Skip to content

Commit 7f2eeed

Browse files
authored
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
1 parent 33537ea commit 7f2eeed

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

pkg/skaffold/instrumentation/export.go

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func createMetrics(ctx context.Context, meter skaffoldMeter) {
146146
label.String("command", meter.Command),
147147
label.String("error", meter.ErrorCode.String()),
148148
label.String("platform_type", meter.PlatformType),
149+
label.Int("config_count", meter.ConfigCount),
149150
randLabel,
150151
}
151152

pkg/skaffold/instrumentation/export_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestExportMetrics(t *testing.T) {
5151
Version: "vTest.0",
5252
Arch: "test arch",
5353
OS: "test os",
54+
ConfigCount: 1,
5455
Deployers: []string{"test kubectl"},
5556
Builders: map[string]int{"docker": 1, "buildpacks": 1},
5657
BuildDependencies: map[string]int{"docker": 1},
@@ -63,7 +64,8 @@ func TestExportMetrics(t *testing.T) {
6364
Version: "vTest.1",
6465
Arch: "test arch 2",
6566
OS: "test os 2",
66-
PlatformType: "test platform",
67+
ConfigCount: 2,
68+
PlatformType: "test platform 1:test platform 2",
6769
Deployers: []string{"test helm", "test kpt"},
6870
SyncType: map[string]bool{"manual": true},
6971
EnumFlags: map[string]string{"test_run": "test_run_value"},
@@ -79,6 +81,7 @@ func TestExportMetrics(t *testing.T) {
7981
Version: "vTest.2",
8082
Arch: "test arch 1",
8183
OS: "test os 2",
84+
ConfigCount: 2,
8285
PlatformType: "test platform",
8386
Deployers: []string{"test helm", "test kpt"},
8487
SyncType: map[string]bool{"manual": true, "sync": true},

pkg/skaffold/instrumentation/meter.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package instrumentation
1919
import (
2020
"net/http"
2121
"runtime"
22+
"strings"
2223
"time"
2324

2425
flag "github.com/spf13/pflag"
@@ -74,8 +75,12 @@ func SetOnlineStatus() {
7475
}
7576

7677
func InitMeterFromConfig(configs []*latest.SkaffoldConfig) {
77-
meter.PlatformType = yamltags.GetYamlTag(configs[0].Build.BuildType) // TODO: support multiple build types in events.
78+
var platforms []string
7879
for _, config := range configs {
80+
pl := yamltags.GetYamlTag(config.Build.BuildType)
81+
if !util.StrSliceContains(platforms, pl) {
82+
platforms = append(platforms, pl)
83+
}
7984
for _, artifact := range config.Pipeline.Build.Artifacts {
8085
meter.Builders[yamltags.GetYamlTag(artifact.ArtifactType)]++
8186
if len(artifact.Dependencies) > 0 {
@@ -88,6 +93,8 @@ func InitMeterFromConfig(configs []*latest.SkaffoldConfig) {
8893
meter.Deployers = append(meter.Deployers, yamltags.GetYamlTags(config.Deploy.DeployType)...)
8994
meter.BuildArtifacts += len(config.Pipeline.Build.Artifacts)
9095
}
96+
meter.PlatformType = strings.Join(platforms, ":")
97+
meter.ConfigCount = len(configs)
9198
}
9299

93100
func SetCommand(cmd string) {

pkg/skaffold/instrumentation/types.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import (
2626

2727
// skaffoldMeter describes the data used to determine operational metrics.
2828
type skaffoldMeter struct {
29+
// ConfigCount is the number of parsed skaffold configurations in the current session.
30+
ConfigCount int
31+
2932
// ExitCode Exit code returned by Skaffold at the end of execution.
3033
ExitCode int
3134

@@ -45,7 +48,7 @@ type skaffoldMeter struct {
4548
// Arch Architecture running Skaffold e.g. amd64, arm64, etc.
4649
Arch string
4750

48-
// PlatformType Where Skaffold is deploying to (local, cluster, or Google Cloud Build).
51+
// PlatformType Where Skaffold is building artifacts (local, cluster, Google Cloud Build, or a combination of them).
4952
PlatformType string
5053

5154
// Deployers All the deployers used in the Skaffold execution.

0 commit comments

Comments
 (0)