diff --git a/plugins/bundle/status.go b/plugins/bundle/status.go index 432946531a..b8fc856c7c 100644 --- a/plugins/bundle/status.go +++ b/plugins/bundle/status.go @@ -41,17 +41,16 @@ type Status struct { // activation. func (s *Status) SetActivateSuccess(revision string) { s.LastSuccessfulActivation = time.Now().UTC() - s.ActiveRevision = revision + if s.ActiveRevision != revision { + s.FirstSuccessfulActivation = s.LastSuccessfulActivation + s.ActiveRevision = revision + } } // SetDownloadSuccess updates the status object to reflect a successful // download. func (s *Status) SetDownloadSuccess() { s.LastSuccessfulDownload = time.Now().UTC() - - if s.FirstSuccessfulActivation.IsZero() { - s.FirstSuccessfulActivation = s.LastSuccessfulDownload - } } // SetRequest updates the status object to reflect a download attempt. diff --git a/plugins/status/plugin.go b/plugins/status/plugin.go index ded3346044..108adc098e 100644 --- a/plugins/status/plugin.go +++ b/plugins/status/plugin.go @@ -236,7 +236,7 @@ func (p *Plugin) Start(ctx context.Context) error { if p.config.Prometheus && p.manager.PrometheusRegister() != nil { p.register(p.manager.PrometheusRegister(), pluginStatus, loaded, failLoad, lastRequest, lastSuccessfulActivation, lastSuccessfulDownload, - lastSuccessfulRequest, bundleLoadDuration) + lastSuccessfulRequest, bundleLoadDuration, activeRevision) } // Set the status plugin's status to OK now that everything is registered and diff --git a/plugins/status/plugin_go1.17_test.go b/plugins/status/plugin_go1.17_test.go index ce714d4290..90742b15a9 100644 --- a/plugins/status/plugin_go1.17_test.go +++ b/plugins/status/plugin_go1.17_test.go @@ -45,6 +45,9 @@ func TestPluginPrometheus(t *testing.T) { if registerMock.Collectors[pluginStatus] != true { t.Fatalf("Plugin status metric was not registered on prometheus") } + if registerMock.Collectors[activeRevision] != true { + t.Fatalf("activeRevision metric was not registered on prometheus") + } if registerMock.Collectors[loaded] != true { t.Fatalf("Loaded metric was not registered on prometheus") } @@ -90,6 +93,11 @@ func TestPluginPrometheus(t *testing.T) { t.Fatalf("Last request expected (%v), got %v", status.LastSuccessfulActivation.UTC(), lastSuccessfulActivationMetricResult.UTC()) } + activeRevisionMetricResult := time.UnixMilli(int64(testutil.ToFloat64(activeRevision) / 1e6)) + if !activeRevisionMetricResult.Equal(status.FirstSuccessfulActivation) { + t.Fatalf("Active revision expected (%v), got %v", status.FirstSuccessfulActivation.UTC(), activeRevisionMetricResult.UTC()) + } + bundlesLoaded := testutil.CollectAndCount(loaded) if bundlesLoaded != 1 { t.Fatalf("Unexpected number of bundle loads (%v), got %v", 1, bundlesLoaded) diff --git a/plugins/status/plugin_test.go b/plugins/status/plugin_test.go index d5014de995..680c7355de 100644 --- a/plugins/status/plugin_test.go +++ b/plugins/status/plugin_test.go @@ -749,17 +749,19 @@ func (t *testServer) stop() { func testStatus() *bundle.Status { tDownload, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:00.0000000Z") - tActivate, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:01.0000000Z") - tSuccessfulRequest, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:02.0000000Z") - tRequest, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:03.0000000Z") + tFirstActivation, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:01.0000000Z") + tActivate, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:02.0000000Z") + tSuccessfulRequest, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:03.0000000Z") + tRequest, _ := time.Parse(time.RFC3339Nano, "2018-01-01T00:00:04.0000000Z") status := bundle.Status{ - Name: "example/authz", - ActiveRevision: "quickbrawnfaux", - LastSuccessfulDownload: tDownload, - LastSuccessfulActivation: tActivate, - LastRequest: tRequest, - LastSuccessfulRequest: tSuccessfulRequest, + Name: "example/authz", + ActiveRevision: "quickbrawnfaux", + FirstSuccessfulActivation: tFirstActivation, + LastSuccessfulDownload: tDownload, + LastSuccessfulActivation: tActivate, + LastRequest: tRequest, + LastSuccessfulRequest: tSuccessfulRequest, } return &status