Skip to content

Commit

Permalink
plugins/status: fix bundle_failed_load_counter metric (#4823)
Browse files Browse the repository at this point in the history
...for bundles without a revision.

Fixes #4822.

Signed-off-by: Jakob Schmid <jkbschmid@github.com>
  • Loading branch information
jkbschmid committed Jun 28, 2022
1 parent fc128ac commit 5fa44bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/status/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func updatePrometheusMetrics(u *UpdateRequestV1) {
}
lastSuccessfulActivation.Reset()
for _, bundle := range u.Bundles {
if bundle.Code == "" && bundle.ActiveRevision != "" {
if bundle.Code == "" && !bundle.LastSuccessfulActivation.IsZero() {
loaded.WithLabelValues(bundle.Name).Inc()
} else {
failLoad.WithLabelValues(bundle.Name, bundle.Code, bundle.Message).Inc()
Expand Down
33 changes: 33 additions & 0 deletions plugins/status/plugin_go1.17_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,36 @@ func TestPluginPrometheus(t *testing.T) {
t.Fatalf("Unexpected number of plugins (%v), got %v", 1, pluginsStatus)
}
}

func TestMetricsBundleWithoutRevision(t *testing.T) {
fixture := newTestFixture(t, nil, func(c *Config) {
c.Prometheus = true
})
fixture.server.ch = make(chan UpdateRequestV1)
defer fixture.server.stop()

ctx := context.Background()

err := fixture.plugin.Start(ctx)
if err != nil {
t.Fatal(err)
}
defer fixture.plugin.Stop(ctx)
<-fixture.server.ch

status := testStatus()
status.ActiveRevision = ""

fixture.plugin.BulkUpdateBundleStatus(map[string]*bundle.Status{"bundle": status})
<-fixture.server.ch

bundlesLoaded := testutil.CollectAndCount(loaded)
if bundlesLoaded != 1 {
t.Fatalf("Unexpected number of bundle loads (%v), got %v", 1, bundlesLoaded)
}

bundlesFailedToLoad := testutil.CollectAndCount(failLoad)
if bundlesFailedToLoad != 0 {
t.Fatalf("Unexpected number of bundle fails load (%v), got %v", 0, bundlesFailedToLoad)
}
}

0 comments on commit 5fa44bb

Please sign in to comment.