Skip to content

Commit

Permalink
Implement review
Browse files Browse the repository at this point in the history
Signed-off-by: cmuraru <cmuraru@adobe.com>
  • Loading branch information
cmuraru committed Apr 20, 2022
1 parent 6fa9093 commit b6d8180
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
9 changes: 4 additions & 5 deletions plugins/bundle/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion plugins/status/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions plugins/status/plugin_go1.17_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions plugins/status/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b6d8180

Please sign in to comment.