This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d8713a  chore: Make phase structured logging key a string
6d8713a is described below

commit 6d8713ab87edc580a40f6d32c5baa1ac6e946cfa
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Mon May 17 16:44:34 2021 +0200

    chore: Make phase structured logging key a string
---
 e2e/common/operator_metrics_test.go | 10 ++--------
 e2e/support/test_support.go         |  2 --
 e2e/support/util/structured_log.go  | 26 ++------------------------
 pkg/builder/builder.go              |  3 ++-
 4 files changed, 6 insertions(+), 35 deletions(-)

diff --git a/e2e/common/operator_metrics_test.go 
b/e2e/common/operator_metrics_test.go
index ebe6dc2..909b7ae 100644
--- a/e2e/common/operator_metrics_test.go
+++ b/e2e/common/operator_metrics_test.go
@@ -81,10 +81,7 @@ func TestMetrics(t *testing.T) {
                                AddStep(MatchFields(IgnoreExtras, Fields{
                                        "LoggerName":  
Equal("camel-k.controller.build"),
                                        "Message":     Equal("Build state 
transition"),
-                                       "Phase":       MatchFields(IgnoreExtras,
-                                               Fields{
-                                                       "Name": 
Equal(string(v1.BuildPhasePending)),
-                                               }),
+                                       "Phase":       
Equal(string(v1.BuildPhasePending)),
                                        "RequestName": Equal(build.Name),
                                }), LogEntryNoop).
                                AddStep(MatchFields(IgnoreExtras, Fields{
@@ -344,10 +341,7 @@ func TestMetrics(t *testing.T) {
                                AddStep(MatchFields(IgnoreExtras, Fields{
                                        "LoggerName":  
Equal("camel-k.controller.build"),
                                        "Message":     Equal("Build state 
transition"),
-                                       "Phase":       MatchFields(IgnoreExtras,
-                                               Fields{
-                                                       "Name": 
Equal(string(v1.BuildPhasePending)),
-                                       }),
+                                       "Phase":       
Equal(string(v1.BuildPhasePending)),
                                        "RequestName": Equal(build.Name),
                                }), func(l *LogEntry) { ts2 = l.Timestamp.Time 
}).
                                Walk()
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 01732cf..39a77c2 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -293,8 +293,6 @@ func StructuredLogs(ns, podName string, options 
corev1.PodLogOptions, ignorePars
                        }
                }
 
-               log.Debug("Parsed: %s with phase '%s'\n", entry.Message, 
entry.Phase.Name)
-
                entries = append(entries, entry)
        }
 
diff --git a/e2e/support/util/structured_log.go 
b/e2e/support/util/structured_log.go
index 7b621dc..ca26628 100644
--- a/e2e/support/util/structured_log.go
+++ b/e2e/support/util/structured_log.go
@@ -20,7 +20,6 @@ limitations under the License.
 package util
 
 import (
-       "encoding/json"
        "math"
        "strconv"
        "time"
@@ -44,27 +43,6 @@ func (t *Time) UnmarshalJSON(s []byte) (err error) {
        return nil
 }
 
-type Phase struct {
-       Name string
-}
-
-func (p *Phase) UnmarshalJSON(b []byte) error {
-       if b[0] != '"' {
-               var tmp int
-
-               json.Unmarshal(b, &tmp)
-               p.Name = strconv.Itoa(tmp)
-
-               return nil
-       }
-
-       if err := json.Unmarshal(b, &p.Name); err != nil {
-               return err
-       }
-
-       return nil
-}
-
 type LogEntry struct {
        // Zap
        Level      zapcore.Level `json:"level,omitempty"`
@@ -79,7 +57,7 @@ type LogEntry struct {
        // Camel K
        Namespace string `json:"ns,omitempty"`
        Name      string `json:"name,omitempty"`
-       Phase     Phase `json:"phase,omitempty"`
+       Phase     string `json:"phase,omitempty"`
        PhaseFrom string `json:"phase-from,omitempty"`
        PhaseTo   string `json:"phase-to,omitempty"`
-}
\ No newline at end of file
+}
diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go
index 9aa0236..1af6c82 100644
--- a/pkg/builder/builder.go
+++ b/pkg/builder/builder.go
@@ -22,6 +22,7 @@ import (
        "os"
        "path"
        "sort"
+       "strconv"
        "time"
 
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -115,7 +116,7 @@ func (t *builderTask) Do(ctx context.Context) 
v1.BuildStatus {
                default:
                        l := t.log.WithValues(
                                "step", step.ID(),
-                               "phase", step.Phase(),
+                               "phase", strconv.FormatInt(int64(step.Phase()), 
10),
                                "task", t.task.Name,
                        )
 

Reply via email to