From 7f2eeedbae02a300270c0ba0837c70c23e48ef62 Mon Sep 17 00:00:00 2001 From: Gaurav <39389231+gsquared94@users.noreply.github.com> Date: Tue, 23 Feb 2021 13:05:57 -0800 Subject: [PATCH] Add metric for the count of skaffold configurations in current session; fix the build platform type metric to save list of all platforms (#5437) * Add metric for the count of skaffold configurations in current session; fix the build platform type metric to save list of all platforms * change `uint32` to `int`; appease linters --- pkg/skaffold/instrumentation/export.go | 1 + pkg/skaffold/instrumentation/export_test.go | 5 ++++- pkg/skaffold/instrumentation/meter.go | 9 ++++++++- pkg/skaffold/instrumentation/types.go | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/skaffold/instrumentation/export.go b/pkg/skaffold/instrumentation/export.go index 3e4ae3251b8..8268d4803d3 100644 --- a/pkg/skaffold/instrumentation/export.go +++ b/pkg/skaffold/instrumentation/export.go @@ -146,6 +146,7 @@ func createMetrics(ctx context.Context, meter skaffoldMeter) { label.String("command", meter.Command), label.String("error", meter.ErrorCode.String()), label.String("platform_type", meter.PlatformType), + label.Int("config_count", meter.ConfigCount), randLabel, } diff --git a/pkg/skaffold/instrumentation/export_test.go b/pkg/skaffold/instrumentation/export_test.go index 318fdd68c69..a7cdf41db3c 100644 --- a/pkg/skaffold/instrumentation/export_test.go +++ b/pkg/skaffold/instrumentation/export_test.go @@ -51,6 +51,7 @@ func TestExportMetrics(t *testing.T) { Version: "vTest.0", Arch: "test arch", OS: "test os", + ConfigCount: 1, Deployers: []string{"test kubectl"}, Builders: map[string]int{"docker": 1, "buildpacks": 1}, BuildDependencies: map[string]int{"docker": 1}, @@ -63,7 +64,8 @@ func TestExportMetrics(t *testing.T) { Version: "vTest.1", Arch: "test arch 2", OS: "test os 2", - PlatformType: "test platform", + ConfigCount: 2, + PlatformType: "test platform 1:test platform 2", Deployers: []string{"test helm", "test kpt"}, SyncType: map[string]bool{"manual": true}, EnumFlags: map[string]string{"test_run": "test_run_value"}, @@ -79,6 +81,7 @@ func TestExportMetrics(t *testing.T) { Version: "vTest.2", Arch: "test arch 1", OS: "test os 2", + ConfigCount: 2, PlatformType: "test platform", Deployers: []string{"test helm", "test kpt"}, SyncType: map[string]bool{"manual": true, "sync": true}, diff --git a/pkg/skaffold/instrumentation/meter.go b/pkg/skaffold/instrumentation/meter.go index ce78143efd4..f4d75fdba9e 100644 --- a/pkg/skaffold/instrumentation/meter.go +++ b/pkg/skaffold/instrumentation/meter.go @@ -19,6 +19,7 @@ package instrumentation import ( "net/http" "runtime" + "strings" "time" flag "github.com/spf13/pflag" @@ -74,8 +75,12 @@ func SetOnlineStatus() { } func InitMeterFromConfig(configs []*latest.SkaffoldConfig) { - meter.PlatformType = yamltags.GetYamlTag(configs[0].Build.BuildType) // TODO: support multiple build types in events. + var platforms []string for _, config := range configs { + pl := yamltags.GetYamlTag(config.Build.BuildType) + if !util.StrSliceContains(platforms, pl) { + platforms = append(platforms, pl) + } for _, artifact := range config.Pipeline.Build.Artifacts { meter.Builders[yamltags.GetYamlTag(artifact.ArtifactType)]++ if len(artifact.Dependencies) > 0 { @@ -88,6 +93,8 @@ func InitMeterFromConfig(configs []*latest.SkaffoldConfig) { meter.Deployers = append(meter.Deployers, yamltags.GetYamlTags(config.Deploy.DeployType)...) meter.BuildArtifacts += len(config.Pipeline.Build.Artifacts) } + meter.PlatformType = strings.Join(platforms, ":") + meter.ConfigCount = len(configs) } func SetCommand(cmd string) { diff --git a/pkg/skaffold/instrumentation/types.go b/pkg/skaffold/instrumentation/types.go index 48e1cb279e1..f63edc04768 100644 --- a/pkg/skaffold/instrumentation/types.go +++ b/pkg/skaffold/instrumentation/types.go @@ -26,6 +26,9 @@ import ( // skaffoldMeter describes the data used to determine operational metrics. type skaffoldMeter struct { + // ConfigCount is the number of parsed skaffold configurations in the current session. + ConfigCount int + // ExitCode Exit code returned by Skaffold at the end of execution. ExitCode int @@ -45,7 +48,7 @@ type skaffoldMeter struct { // Arch Architecture running Skaffold e.g. amd64, arm64, etc. Arch string - // PlatformType Where Skaffold is deploying to (local, cluster, or Google Cloud Build). + // PlatformType Where Skaffold is building artifacts (local, cluster, Google Cloud Build, or a combination of them). PlatformType string // Deployers All the deployers used in the Skaffold execution.