Skip to content

Commit

Permalink
Add metric for the count of skaffold configurations in current sessio…
Browse files Browse the repository at this point in the history
…n; 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
  • Loading branch information
gsquared94 authored Feb 23, 2021
1 parent 33537ea commit 7f2eeed
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/skaffold/instrumentation/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/skaffold/instrumentation/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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"},
Expand All @@ -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},
Expand Down
9 changes: 8 additions & 1 deletion pkg/skaffold/instrumentation/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package instrumentation
import (
"net/http"
"runtime"
"strings"
"time"

flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/skaffold/instrumentation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down

0 comments on commit 7f2eeed

Please sign in to comment.