From da54f2b843f8367644e2a8b6c6af3fa3fe6b294d Mon Sep 17 00:00:00 2001 From: gsquared94 Date: Mon, 22 Feb 2021 12:47:58 -0800 Subject: [PATCH 1/2] Add metric for the count of skaffold configurations in current session; fix the build platform type metric to save list of all platforms --- 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..30003e2f779 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.Uint32("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..8b866763518 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 = uint32(len(configs)) } func SetCommand(cmd string) { diff --git a/pkg/skaffold/instrumentation/types.go b/pkg/skaffold/instrumentation/types.go index 48e1cb279e1..2f490f76ffa 100644 --- a/pkg/skaffold/instrumentation/types.go +++ b/pkg/skaffold/instrumentation/types.go @@ -45,7 +45,10 @@ 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). + // ConfigCount is the number of parsed skaffold configurations in the current session. + ConfigCount uint32 + + // 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. From 1c84d3c3a86c4f523502a945cd346cb43f6d5bc2 Mon Sep 17 00:00:00 2001 From: gsquared94 Date: Mon, 22 Feb 2021 13:40:52 -0800 Subject: [PATCH 2/2] change `uint32` to `int`; appease linters --- pkg/skaffold/instrumentation/export.go | 2 +- pkg/skaffold/instrumentation/meter.go | 2 +- pkg/skaffold/instrumentation/types.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/skaffold/instrumentation/export.go b/pkg/skaffold/instrumentation/export.go index 30003e2f779..8268d4803d3 100644 --- a/pkg/skaffold/instrumentation/export.go +++ b/pkg/skaffold/instrumentation/export.go @@ -146,7 +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.Uint32("config_count", meter.ConfigCount), + label.Int("config_count", meter.ConfigCount), randLabel, } diff --git a/pkg/skaffold/instrumentation/meter.go b/pkg/skaffold/instrumentation/meter.go index 8b866763518..f4d75fdba9e 100644 --- a/pkg/skaffold/instrumentation/meter.go +++ b/pkg/skaffold/instrumentation/meter.go @@ -94,7 +94,7 @@ func InitMeterFromConfig(configs []*latest.SkaffoldConfig) { meter.BuildArtifacts += len(config.Pipeline.Build.Artifacts) } meter.PlatformType = strings.Join(platforms, ":") - meter.ConfigCount = uint32(len(configs)) + meter.ConfigCount = len(configs) } func SetCommand(cmd string) { diff --git a/pkg/skaffold/instrumentation/types.go b/pkg/skaffold/instrumentation/types.go index 2f490f76ffa..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,9 +48,6 @@ type skaffoldMeter struct { // Arch Architecture running Skaffold e.g. amd64, arm64, etc. Arch string - // ConfigCount is the number of parsed skaffold configurations in the current session. - ConfigCount uint32 - // PlatformType Where Skaffold is building artifacts (local, cluster, Google Cloud Build, or a combination of them). PlatformType string