From f7e5c6e75b2c46d961d0c715b7b1398a9a17cc31 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Mon, 21 Oct 2024 19:18:45 +0545 Subject: [PATCH] chore: undo some formatting changes --- checks/http.go | 4 ++-- pkg/metrics/metrics.go | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/checks/http.go b/checks/http.go index 1aff0eda7..312b4d933 100644 --- a/checks/http.go +++ b/checks/http.go @@ -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 @@ -174,7 +174,7 @@ func (c *HTTPChecker) Check(ctx *context.Context, extConfig external.Check) pkg. connection, connectionData, err := ctx.GetConnectionTemplate(check.Connection) if err != nil { - return results.Invalidf("error getting connection %v", err) + return results.Failf("error getting connection %v", err) } if connection.URL == "" { diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 05e3bdf85..e4af6c4d3 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -94,7 +94,7 @@ func setupMetrics() { checkLabels, ) - prometheus.MustRegister(Gauge, CanaryCheckInfo, OpsCount, OpsSuccessCount, OpsFailedCount, RequestLatency) + prometheus.MustRegister(Gauge, CanaryCheckInfo, OpsCount, OpsSuccessCount, OpsInvalidCount, OpsFailedCount, RequestLatency) } var ( @@ -125,18 +125,18 @@ var ( ) func init() { - prometheus.MustRegister( - CanaryCheckInfo, - Gauge, - OpsCount, - OpsFailedCount, - OpsInvalidCount, - OpsSuccessCount, - RequestLatency, - ) CustomCounters = make(map[string]*prometheus.CounterVec) CustomGauges = make(map[string]*prometheus.GaugeVec) CustomHistograms = make(map[string]*prometheus.HistogramVec) + + // Register the metrics with a delay because + // v1.AdditionalCheckMetricLabels is nil during init. + go func() { + time.Sleep(time.Second) + + slices.Sort(v1.AdditionalCheckMetricLabels) + setupMetrics() + }() } func RemoveCheck(checks v1.Canary) { @@ -172,11 +172,7 @@ func GetMetrics(key string) (uptime types.Uptime, latency types.Latency) { return } -func Record( - ctx context.Context, - canary v1.Canary, - result *pkg.CheckResult, -) (_uptime types.Uptime, _latency types.Latency) { +func Record(ctx context.Context, canary v1.Canary, result *pkg.CheckResult) (_uptime types.Uptime, _latency types.Latency) { defer func() { e := recover() if e != nil {