Skip to content

Commit

Permalink
Export last run duration metric
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Apr 12, 2022
1 parent 1faf28e commit 21bc399
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/pint/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ var (
Help: "Last checks run completion time since unix epoch in seconds",
},
)
lastRunDuration = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "pint_last_run_duration_seconds",
Help: "Last checks run duration in seconds",
},
)
rulesParsedTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "pint_rules_parsed_total",
Expand Down
5 changes: 5 additions & 0 deletions cmd/pint/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func tryDecodingYamlError(e string) (int, string) {
}

func checkRules(ctx context.Context, workers int, cfg config.Config, entries []discovery.Entry) (summary reporter.Summary) {
start := time.Now()
defer func() {
lastRunDuration.Set(time.Since(start).Seconds())
}()

jobs := make(chan scanJob, workers*5)
results := make(chan reporter.Report, workers*5)
wg := sync.WaitGroup{}
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0042_watch_metrics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ pint_check_duration_seconds_count{check="promql/syntax"}
# HELP pint_check_iterations_total Total number of completed check iterations since pint start
# TYPE pint_check_iterations_total counter
pint_check_iterations_total
# HELP pint_last_run_duration_seconds Last checks run duration in seconds
# TYPE pint_last_run_duration_seconds gauge
pint_last_run_duration_seconds
# HELP pint_last_run_time_seconds Last checks run completion time since unix epoch in seconds
# TYPE pint_last_run_time_seconds gauge
pint_last_run_time_seconds
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0054_watch_metrics_prometheus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pint_check_duration_seconds_count{check="promql/vector_matching"}
# HELP pint_check_iterations_total Total number of completed check iterations since pint start
# TYPE pint_check_iterations_total counter
pint_check_iterations_total
# HELP pint_last_run_duration_seconds Last checks run duration in seconds
# TYPE pint_last_run_duration_seconds gauge
pint_last_run_duration_seconds
# HELP pint_last_run_time_seconds Last checks run completion time since unix epoch in seconds
# TYPE pint_last_run_time_seconds gauge
pint_last_run_time_seconds
Expand Down
3 changes: 3 additions & 0 deletions cmd/pint/tests/0057_watch_metrics_prometheus_ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ pint_check_duration_seconds_count{check="promql/vector_matching"}
# HELP pint_check_iterations_total Total number of completed check iterations since pint start
# TYPE pint_check_iterations_total counter
pint_check_iterations_total
# HELP pint_last_run_duration_seconds Last checks run duration in seconds
# TYPE pint_last_run_duration_seconds gauge
pint_last_run_duration_seconds
# HELP pint_last_run_time_seconds Last checks run completion time since unix epoch in seconds
# TYPE pint_last_run_time_seconds gauge
pint_last_run_time_seconds
Expand Down
1 change: 1 addition & 0 deletions cmd/pint/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func actionWatch(c *cli.Context) error {
prometheus.MustRegister(checkIterationsTotal)
prometheus.MustRegister(pintVersion)
prometheus.MustRegister(lastRunTime)
prometheus.MustRegister(lastRunDuration)
prometheus.MustRegister(rulesParsedTotal)
promapi.RegisterMetrics()

Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## v0.17.5

### Added

- Added `pint_last_run_duration_seconds` metric.

### Fixed

- Better handling of YAML unmarshal errors.
Expand Down

0 comments on commit 21bc399

Please sign in to comment.