Skip to content

Commit

Permalink
Keep active_revision label just on last_success_bundle_activation
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 b6d8180 commit 93703d0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 37 deletions.
1 change: 0 additions & 1 deletion docs/content/monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ When Prometheus is enabled in the status plugin (see [Configuration](../configur
| last_success_bundle_download | gauge | Last successful bundle download in UNIX nanoseconds. | EXPERIMENTAL |
| last_success_bundle_request | gauge | Last successful bundle request in UNIX nanoseconds. | EXPERIMENTAL |
| bundle_loading_duration_ns | histogram | A histogram of duration for bundle loading. | EXPERIMENTAL |
| bundle_active_revision | gauge | First successful bundle activation in UNIX nanoseconds. Contains the activeRevision label. | EXPERIMENTAL |


## Health Checks
Expand Down
2 changes: 1 addition & 1 deletion plugins/bundle/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (p *Plugin) checkPluginReadiness() {
}

func (p *Plugin) activate(ctx context.Context, name string, b *bundle.Bundle) error {
p.log(name).Debug("Bundle activation in progress. Opening storage transaction.")
p.log(name).Debug("Bundle activation in progress (%v). Opening storage transaction.", b.Manifest.Revision)

params := storage.WriteParams
params.Context = storage.NewContext().WithMetrics(p.status[name].Metrics)
Expand Down
28 changes: 12 additions & 16 deletions plugins/bundle/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,24 @@ const (

// Status represents the status of processing a bundle.
type Status struct {
Name string `json:"name"`
ActiveRevision string `json:"active_revision,omitempty"`
FirstSuccessfulActivation time.Time `json:"first_successful_activation,omitempty"`
LastSuccessfulActivation time.Time `json:"last_successful_activation,omitempty"`
LastSuccessfulDownload time.Time `json:"last_successful_download,omitempty"`
LastSuccessfulRequest time.Time `json:"last_successful_request,omitempty"`
LastRequest time.Time `json:"last_request,omitempty"`
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Errors []error `json:"errors,omitempty"`
Metrics metrics.Metrics `json:"metrics,omitempty"`
HTTPCode json.Number `json:"http_code,omitempty"`
Name string `json:"name"`
ActiveRevision string `json:"active_revision,omitempty"`
LastSuccessfulActivation time.Time `json:"last_successful_activation,omitempty"`
LastSuccessfulDownload time.Time `json:"last_successful_download,omitempty"`
LastSuccessfulRequest time.Time `json:"last_successful_request,omitempty"`
LastRequest time.Time `json:"last_request,omitempty"`
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Errors []error `json:"errors,omitempty"`
Metrics metrics.Metrics `json:"metrics,omitempty"`
HTTPCode json.Number `json:"http_code,omitempty"`
}

// SetActivateSuccess updates the status object to reflect a successful
// activation.
func (s *Status) SetActivateSuccess(revision string) {
s.LastSuccessfulActivation = time.Now().UTC()
if s.ActiveRevision != revision {
s.FirstSuccessfulActivation = s.LastSuccessfulActivation
s.ActiveRevision = revision
}
s.ActiveRevision = revision
}

// SetDownloadSuccess updates the status object to reflect a successful
Expand Down
8 changes: 1 addition & 7 deletions plugins/status/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ var (
Help: "Gauge for the plugin by status."},
[]string{"name", "status"},
)
activeRevision = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "bundle_active_revision",
Help: "Gauge for the active revision."},
[]string{"name", "active_revision"},
)
loaded = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "bundle_loaded_counter",
Expand All @@ -39,7 +33,7 @@ var (
prometheus.GaugeOpts{
Name: "last_success_bundle_activation",
Help: "Gauge for the last success bundle activation."},
[]string{"name"},
[]string{"name", "active_revision"},
)
lastSuccessfulDownload = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down
7 changes: 3 additions & 4 deletions 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, activeRevision)
lastSuccessfulRequest, bundleLoadDuration)
}

// Set the status plugin's status to OK now that everything is registered and
Expand Down Expand Up @@ -480,15 +480,14 @@ func updatePrometheusMetrics(u *UpdateRequestV1) {
for name, plugin := range u.Plugins {
pluginStatus.WithLabelValues(name, string(plugin.State)).Set(1)
}
activeRevision.Reset()
lastSuccessfulActivation.Reset()
for _, bundle := range u.Bundles {
if bundle.Code == "" && bundle.ActiveRevision != "" {
loaded.WithLabelValues(bundle.Name).Inc()
} else {
failLoad.WithLabelValues(bundle.Name, bundle.Code, bundle.Message).Inc()
}
activeRevision.WithLabelValues(bundle.Name, bundle.ActiveRevision).Set(float64(bundle.FirstSuccessfulActivation.UnixNano()))
lastSuccessfulActivation.WithLabelValues(bundle.Name).Set(float64(bundle.LastSuccessfulActivation.UnixNano()))
lastSuccessfulActivation.WithLabelValues(bundle.Name, bundle.ActiveRevision).Set(float64(bundle.LastSuccessfulActivation.UnixNano()))
lastSuccessfulDownload.WithLabelValues(bundle.Name).Set(float64(bundle.LastSuccessfulDownload.UnixNano()))
lastSuccessfulRequest.WithLabelValues(bundle.Name).Set(float64(bundle.LastSuccessfulRequest.UnixNano()))
lastRequest.WithLabelValues(bundle.Name).Set(float64(bundle.LastRequest.UnixNano()))
Expand Down
8 changes: 0 additions & 8 deletions plugins/status/plugin_go1.17_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ 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 @@ -93,11 +90,6 @@ 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

0 comments on commit 93703d0

Please sign in to comment.