This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 9de098b5ddfdc6ce52e3cc379d512deba66a9daa Author: Pasquale Congiusti <pasquale.congiu...@gmail.com> AuthorDate: Thu Aug 31 09:34:17 2023 +0200 fix(e2e): structured log --- .../operator_metrics_test.go | 10 +++---- e2e/support/util/structured_log.go | 23 +-------------- e2e/support/util/structured_log_test.go | 34 ++++++++++++++++++++++ script/Makefile | 1 + 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/e2e/commonwithcustominstall/operator_metrics_test.go b/e2e/commonwithcustominstall/operator_metrics_test.go index 89516bcc2..831c39b92 100644 --- a/e2e/commonwithcustominstall/operator_metrics_test.go +++ b/e2e/commonwithcustominstall/operator_metrics_test.go @@ -108,7 +108,7 @@ func TestMetrics(t *testing.T) { "PhaseFrom": Equal(string(v1.BuildPhaseScheduling)), "PhaseTo": Equal(string(v1.BuildPhasePending)), "RequestName": Equal(build.Name), - }), func(l *LogEntry) { ts1 = l.Timestamp.Time }). + }), func(l *LogEntry) { ts1 = l.Timestamp }). AddStep(MatchFields(IgnoreExtras, Fields{ "LoggerName": Equal("camel-k.controller.build"), "Message": HavePrefix("Build duration"), @@ -119,7 +119,7 @@ func TestMetrics(t *testing.T) { "PhaseFrom": Equal(string(v1.BuildPhaseRunning)), "PhaseTo": Equal(string(v1.BuildPhaseSucceeded)), "RequestName": Equal(build.Name), - }), func(l *LogEntry) { ts2 = l.Timestamp.Time }). + }), func(l *LogEntry) { ts2 = l.Timestamp }). Walk() Expect(err).To(BeNil()) Expect(ts1).NotTo(BeZero()) @@ -426,7 +426,7 @@ func TestMetrics(t *testing.T) { "PhaseFrom": Equal(string(v1.BuildPhaseScheduling)), "PhaseTo": Equal(string(v1.BuildPhasePending)), "RequestName": Equal(build.Name), - }), func(l *LogEntry) { ts2 = l.Timestamp.Time }). + }), func(l *LogEntry) { ts2 = l.Timestamp }). Walk() Expect(err).To(BeNil()) Expect(ts1).NotTo(BeZero()) @@ -489,12 +489,12 @@ func TestMetrics(t *testing.T) { "RequestName": Equal(it.Name), "PhaseFrom": Equal(string(v1.IntegrationPhaseInitialization)), "PhaseTo": Equal(string(v1.IntegrationPhaseBuildingKit)), - }), func(l *LogEntry) { ts1 = l.Timestamp.Time }). + }), func(l *LogEntry) { ts1 = l.Timestamp }). AddStep(MatchFields(IgnoreExtras, Fields{ "LoggerName": Equal("camel-k.controller.integration"), "Message": HavePrefix("First readiness"), "RequestName": Equal(it.Name), - }), func(l *LogEntry) { ts2 = l.Timestamp.Time }). + }), func(l *LogEntry) { ts2 = l.Timestamp }). Walk() Expect(err).To(BeNil()) Expect(ts1).NotTo(BeZero()) diff --git a/e2e/support/util/structured_log.go b/e2e/support/util/structured_log.go index f740cabd5..cd1334c9d 100644 --- a/e2e/support/util/structured_log.go +++ b/e2e/support/util/structured_log.go @@ -1,6 +1,3 @@ -//go:build integration -// +build integration - /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -21,33 +18,15 @@ limitations under the License. package util import ( - "math" - "strconv" "time" "go.uber.org/zap/zapcore" ) -type Time struct { - time.Time -} - -func (t *Time) UnmarshalJSON(s []byte) (err error) { - f, err := strconv.ParseFloat(string(s), 10) - if err != nil { - return err - } - ns := (f - math.Floor(f)) * 1000000000 - *t = Time{ - time.Unix(int64(f), int64(ns)), - } - return nil -} - type LogEntry struct { // Zap Level zapcore.Level `json:"level,omitempty"` - Timestamp Time `json:"ts,omitempty"` + Timestamp time.Time `json:"ts,omitempty"` LoggerName string `json:"logger,omitempty"` Message string `json:"msg,omitempty"` // Controller runtime diff --git a/e2e/support/util/structured_log_test.go b/e2e/support/util/structured_log_test.go new file mode 100644 index 000000000..067cb7774 --- /dev/null +++ b/e2e/support/util/structured_log_test.go @@ -0,0 +1,34 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestJSONFormat(t *testing.T) { + logLine := `{"level":"info","ts":"2023-08-30T08:07:19Z","logger":"camel-k.cmd","msg":"maxprocs: Leaving GOMAXPROCS=[2]: CPU quota undefined"}` + entry := LogEntry{} + err := json.Unmarshal([]byte(logLine), &entry) + assert.Nil(t, err) + assert.Equal(t, "2023-08-30 08:07:19 +0000 UTC", entry.Timestamp.String()) + assert.Equal(t, "maxprocs: Leaving GOMAXPROCS=[2]: CPU quota undefined", entry.Message) +} diff --git a/script/Makefile b/script/Makefile index 6970b1af7..8195c22c1 100644 --- a/script/Makefile +++ b/script/Makefile @@ -379,6 +379,7 @@ endif ./script/bundle_kamelets.sh $(KAMELET_CATALOG_REPO) $(KAMELET_CATALOG_REPO_TAG) build-compile-integration-tests: + @echo "####### Compiling integration tests..." go test -run nope -tags="integration" ./e2e/... clean: