Skip to content

Commit

Permalink
feat: canary_check_invalid_count metric (#2261)
Browse files Browse the repository at this point in the history
* feat: canary_check_invalid_count metric

* chore: undo some formatting changes
  • Loading branch information
adityathebe authored Oct 25, 2024
1 parent dbc85a6 commit d85f05b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion checks/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *HTTPChecker) Check(ctx *context.Context, extConfig external.Check) pkg.

//nolint:staticcheck
if check.Endpoint != "" && check.URL != "" {
return results.Failf("cannot specify both endpoint and url")
return results.Invalidf("cannot specify both endpoint and url")
}

//nolint:staticcheck
Expand Down
18 changes: 17 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func setupMetrics() {
checkLabels,
)

OpsInvalidCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "canary_check_invalid_count",
Help: "The total number of invalid checks",
},
[]string{"type", "endpoint", "canary_name", "canary_namespace", "owner", "severity", "key", "name"},
)

CanaryCheckInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "canary_check_info",
Expand All @@ -86,7 +94,7 @@ func setupMetrics() {
checkLabels,
)

prometheus.MustRegister(Gauge, CanaryCheckInfo, OpsCount, OpsSuccessCount, OpsFailedCount, RequestLatency)
prometheus.MustRegister(Gauge, CanaryCheckInfo, OpsCount, OpsSuccessCount, OpsInvalidCount, OpsFailedCount, RequestLatency)
}

var (
Expand All @@ -103,6 +111,7 @@ var (
Gauge *prometheus.GaugeVec

// Check specific metrics
OpsInvalidCount *prometheus.CounterVec
OpsCount *prometheus.CounterVec
OpsFailedCount *prometheus.CounterVec
OpsSuccessCount *prometheus.CounterVec
Expand Down Expand Up @@ -259,6 +268,12 @@ func Record(
}
}
} else {
if result.Invalid {
OpsInvalidCount.WithLabelValues(checkMetricLabels...).Inc()
} else {
OpsFailedCount.WithLabelValues(checkMetricLabels...).Inc()
}

fail.Append(1)
Gauge.WithLabelValues(gaugeLabels...).Set(1)

Expand All @@ -272,6 +287,7 @@ func Record(
} else {
_latency = types.Latency{}
}

return _uptime, _latency
}

Expand Down

0 comments on commit d85f05b

Please sign in to comment.