diff --git a/pkg/skaffold/instrumentation/export.go b/pkg/skaffold/instrumentation/export.go index 94531e509bb..823b673c591 100644 --- a/pkg/skaffold/instrumentation/export.go +++ b/pkg/skaffold/instrumentation/export.go @@ -149,7 +149,7 @@ func createMetrics(ctx context.Context, meter skaffoldMeter) { label.String("os", meter.OS), label.String("arch", meter.Arch), label.String("command", meter.Command), - label.String("error", strconv.Itoa(int(meter.ErrorCode))), + label.String("error", meter.ErrorCode.String()), label.String("platform_type", meter.PlatformType), randLabel, } @@ -183,7 +183,7 @@ func flagMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, randL labels := []label.KeyValue{ label.String("command", meter.Command), label.String("value", v), - label.String("error", strconv.Itoa(int(meter.ErrorCode))), + label.String("error", meter.ErrorCode.String()), randLabel, } flagCounter.Record(ctx, 1, labels...) @@ -194,7 +194,7 @@ func commandMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, ra commandCounter := metric.Must(m).NewInt64ValueRecorder(meter.Command, metric.WithDescription(fmt.Sprintf("Number of times %s is used", meter.Command))) labels := []label.KeyValue{ - label.String("error", strconv.Itoa(int(meter.ErrorCode))), + label.String("error", meter.ErrorCode.String()), randLabel, } commandCounter.Record(ctx, 1, labels...) @@ -216,7 +216,7 @@ func commandMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, ra for errorCode, count := range errorCounts { iterationCounter.Record(ctx, int64(count), label.String("intent", intention), - label.String("error", strconv.Itoa(int(errorCode))), + label.String("error", errorCode.String()), randLabel) } } @@ -244,7 +244,7 @@ func builderMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, ra func errorMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, randLabel label.KeyValue) { errCounter := metric.Must(m).NewInt64ValueRecorder("errors", metric.WithDescription("Skaffold errors")) - errCounter.Record(ctx, 1, label.String("error", strconv.Itoa(int(meter.ErrorCode))), randLabel) + errCounter.Record(ctx, 1, label.String("error", meter.ErrorCode.String()), randLabel) commandLabel := label.String("command", meter.Command) diff --git a/pkg/skaffold/instrumentation/export_test.go b/pkg/skaffold/instrumentation/export_test.go index 84168b79070..62c8df74b6f 100644 --- a/pkg/skaffold/instrumentation/export_test.go +++ b/pkg/skaffold/instrumentation/export_test.go @@ -23,7 +23,6 @@ import ( "io/ioutil" "net/http" "os" - "strconv" "strings" "testing" "time" @@ -241,7 +240,7 @@ func checkOutput(t *testutil.T, meters []skaffoldMeter, b []byte) { durationCount[fmt.Sprintf("%s:%f", meter.Command, meter.Duration.Seconds())]++ archCount[meter.Arch]++ commandCount[meter.Command]++ - errorCount[meter.ErrorCode]++ + errorCount[meter.ErrorCode.String()]++ platform[meter.PlatformType]++ for k, v := range meter.EnumFlags { @@ -280,9 +279,9 @@ func checkOutput(t *testutil.T, meters []skaffoldMeter, b []byte) { osCount[l.Labels["os"]]-- versionCount[l.Labels["version"]]-- platform[l.Labels["platform_type"]]-- - e, _ := strconv.Atoi(l.Labels["error"]) - if e == int(proto.StatusCode_OK) { - errorCount[proto.StatusCode(e)]-- + e := l.Labels["error"] + if e == proto.StatusCode_OK.String() { + errorCount[e]-- } case "launch/duration": durationCount[fmt.Sprintf("%s:%f", l.Labels["command"], l.value().(float64))]-- @@ -295,11 +294,11 @@ func checkOutput(t *testutil.T, meters []skaffoldMeter, b []byte) { case "deployer": deployers[l.Labels["deployer"]]-- case "dev/iterations": - e, _ := strconv.Atoi(l.Labels["error"]) - devIterations[devIteration{l.Labels["intent"], proto.StatusCode(e)}]-- + e := l.Labels["error"] + devIterations[devIteration{l.Labels["intent"], proto.StatusCode(proto.StatusCode_value[e])}]-- case "errors": - e, _ := strconv.Atoi(l.Labels["error"]) - errorCount[proto.StatusCode(e)]-- + e := l.Labels["error"] + errorCount[e]-- default: switch { case meteredCommands.Contains(l.Name):