Skip to content

Commit

Permalink
Merge pull request #5 from PDOK/pdok-16462-add-last-run-storage-accou…
Browse files Browse the repository at this point in the history
…nt-label

add storage_account label to last_run metric
  • Loading branch information
roelarents authored May 24, 2024
2 parents 69a383b + 80e74f3 commit 9924877
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions internal/agg/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (a *Aggregator) GetLabelNames() []string {
return keys
}

func (a *Aggregator) GetStorageAccountName() string {
return a.labelsWithDefaults[StorageAccount]
}

func (a *Aggregator) Aggregate(previousRunDate time.Time) (aggregationResults []AggregationResult, runDate time.Time, err error) {
log.Print("starting aggregation")
runDate, rowsCh, errCh, err := a.duReader.Read(previousRunDate)
Expand Down
34 changes: 21 additions & 13 deletions internal/metrics/metrics_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,28 @@ func (c *Config) UnmarshalYAML(unmarshal func(any) error) error {
}

func NewUpdater(aggregator *agg.Aggregator, config Config) *Updater {
// promauto automatically registers with prometheus.DefaultRegisterer
storageUsageGauge := promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: config.MetricNamespace,
Subsystem: config.MetricSubsystem,
Name: "usage",
}, aggregator.GetLabelNames())
lastRunDateMetricLabels := prometheus.Labels{}
storageAccountName := aggregator.GetStorageAccountName()
if storageAccountName != "" {
lastRunDateMetricLabels[agg.StorageAccount] = storageAccountName
}
lastRunDateMetric := promauto.NewGauge(prometheus.GaugeOpts{
Namespace: config.MetricNamespace,
Subsystem: config.MetricSubsystem,
Name: "last_run_date",
ConstLabels: lastRunDateMetricLabels,
})
return &Updater{
config: config,
aggregator: aggregator,
// promauto automatically registers with prometheus.DefaultRegisterer
storageUsageGauge: promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: config.MetricNamespace,
Subsystem: config.MetricSubsystem,
Name: "usage",
}, aggregator.GetLabelNames()),
lastRunDateMetric: promauto.NewGauge(prometheus.GaugeOpts{
Namespace: config.MetricNamespace,
Subsystem: config.MetricSubsystem,
Name: "last_run_date",
}),
config: config,
aggregator: aggregator,
storageUsageGauge: storageUsageGauge,
lastRunDateMetric: lastRunDateMetric,
}
}

Expand Down

0 comments on commit 9924877

Please sign in to comment.