Skip to content

add debug/iterations metric #5359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/skaffold/instrumentation/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ func commandMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, ra
}
commandCounter.Record(ctx, 1, labels...)

if meter.Command == "dev" {
iterationCounter := metric.Must(m).NewInt64ValueRecorder("dev/iterations",
metric.WithDescription("Number of iterations in a dev session"))
if meter.Command == "dev" || meter.Command == "debug" {
iterationCounter := metric.Must(m).NewInt64ValueRecorder(fmt.Sprintf("%s/iterations", meter.Command),
metric.WithDescription(fmt.Sprintf("Number of iterations in a %s session", meter.Command)))

counts := make(map[string]map[proto.StatusCode]int)

Expand Down
30 changes: 25 additions & 5 deletions pkg/skaffold/instrumentation/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,22 @@ func TestExportMetrics(t *testing.T) {
StartTime: startTime.Add(time.Hour * 24 * 30),
Duration: time.Minute * 2,
}
devBuildBytes, _ := json.Marshal([]skaffoldMeter{buildMeter, devMeter})
debugMeter := skaffoldMeter{
Command: "debug",
Version: "vTest.2",
Arch: "test arch 1",
OS: "test os 2",
PlatformType: "test platform",
Deployers: []string{"test helm", "test kpt"},
SyncType: map[string]bool{"manual": true, "sync": true},
EnumFlags: map[string]string{"test_run": "test_run_value"},
Builders: map[string]int{"jib": 3, "buildpacks": 2},
DevIterations: []devIteration{{"build", 104}, {"build", 0}, {"sync", 0}, {"deploy", 1014}},
ErrorCode: proto.StatusCode_BUILD_CANCELLED,
StartTime: startTime.Add(time.Hour * 24 * 10),
Duration: time.Minute * 4,
}
metersBytes, _ := json.Marshal([]skaffoldMeter{buildMeter, devMeter, debugMeter})
fs := &testutil.FakeFileSystem{
Files: map[string][]byte{
"/secret/keys.json": []byte(testKey),
Expand All @@ -95,7 +110,7 @@ func TestExportMetrics(t *testing.T) {
{
name: "meter is appended to previously saved metrics",
meter: devMeter,
savedMetrics: devBuildBytes,
savedMetrics: metersBytes,
},
{
name: "meter does not re-save invalid metrics",
Expand All @@ -113,10 +128,15 @@ func TestExportMetrics(t *testing.T) {
meter: devMeter,
isOnline: true,
},
{
name: "test creating debug otel metrics",
meter: debugMeter,
isOnline: true,
},
{
name: "test otel metrics include offline metrics",
meter: devMeter,
savedMetrics: devBuildBytes,
savedMetrics: metersBytes,
isOnline: true,
},
}
Expand Down Expand Up @@ -256,7 +276,7 @@ func checkOutput(t *testutil.T, meters []skaffoldMeter, b []byte) {
buildDeps[k] += v
}
}
if meter.Command == "dev" {
if meter.Command == "dev" || meter.Command == "debug" {
for _, devI := range meter.DevIterations {
devIterations[devI]++
}
Expand Down Expand Up @@ -293,7 +313,7 @@ func checkOutput(t *testutil.T, meters []skaffoldMeter, b []byte) {
builders[l.Labels["builder"]]--
case "deployer":
deployers[l.Labels["deployer"]]--
case "dev/iterations":
case "dev/iterations", "debug/iterations":
e := l.Labels["error"]
devIterations[devIteration{l.Labels["intent"], proto.StatusCode(proto.StatusCode_value[e])}]--
case "errors":
Expand Down