Skip to content

Commit 3724fd9

Browse files
committed
[Misc] Operator: minor fixes
Correct minor typos
1 parent 93aa3cd commit 3724fd9

File tree

2 files changed

+56
-56
lines changed

2 files changed

+56
-56
lines changed

internal/controller/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ var (
122122
}, []string{"name"})
123123
)
124124

125-
// Create a varaible to hold all the collectors
125+
// Create a variable to hold all the collectors
126126
var collectors = []prometheus.Collector{ReconcileErrors, Panics, TenantOperations, depth, adds, latency, workDuration, unfinished, longestRunningProcessor, retries}
127127

128128
// #region capOperatorMetricsProvider

internal/util/metrics-server.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
/*
2-
SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and cap-operator contributors
3-
SPDX-License-Identifier: Apache-2.0
4-
*/
5-
6-
package util
7-
8-
import (
9-
"net/http"
10-
"os"
11-
12-
"github.com/prometheus/client_golang/prometheus"
13-
"github.com/prometheus/client_golang/prometheus/promauto"
14-
"github.com/prometheus/client_golang/prometheus/promhttp"
15-
"k8s.io/klog/v2"
16-
)
17-
18-
// Initalizes the metrics server with default port 9090 and path /metrics based on default prometheus client
19-
func InitMetricsServer() {
20-
// Expose /metrics HTTP endpoint
21-
go func() {
22-
// Default port
23-
metricsPort := "9090"
24-
25-
// Get Port from env
26-
portEnv := os.Getenv("METRICS_PORT")
27-
if portEnv != "" {
28-
metricsPort = portEnv
29-
}
30-
http.Handle("/metrics", promhttp.Handler())
31-
klog.Fatal(http.ListenAndServe(":"+metricsPort, nil))
32-
}()
33-
}
34-
35-
// Instruments the given HTTP handler with counter (total requests) and gauge (in flight requests) metrics
36-
func InstrumentHttpHandler(handler func(http.ResponseWriter, *http.Request), metricNamePrefix string, helpTextSuffix string) http.HandlerFunc {
37-
klog.InfoS("Instrumenting HTTP handler", "metricPrefix", metricNamePrefix, "helpSuffix", helpTextSuffix)
38-
return promhttp.InstrumentHandlerCounter(
39-
promauto.NewCounterVec(
40-
prometheus.CounterOpts{
41-
Name: metricNamePrefix + "_total",
42-
Help: "Total " + helpTextSuffix,
43-
},
44-
[]string{"code", "method"},
45-
),
46-
promhttp.InstrumentHandlerInFlight(promauto.NewGauge(
47-
prometheus.GaugeOpts{
48-
Name: metricNamePrefix + "_in_flight",
49-
Help: "Current " + helpTextSuffix,
50-
},
51-
),
52-
http.HandlerFunc(handler),
53-
),
54-
)
55-
}
1+
/*
2+
SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and cap-operator contributors
3+
SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package util
7+
8+
import (
9+
"net/http"
10+
"os"
11+
12+
"github.com/prometheus/client_golang/prometheus"
13+
"github.com/prometheus/client_golang/prometheus/promauto"
14+
"github.com/prometheus/client_golang/prometheus/promhttp"
15+
"k8s.io/klog/v2"
16+
)
17+
18+
// Initializes the metrics server with default port 9090 and path /metrics based on default prometheus client
19+
func InitMetricsServer() {
20+
// Expose /metrics HTTP endpoint
21+
go func() {
22+
// Default port
23+
metricsPort := "9090"
24+
25+
// Get Port from env
26+
portEnv := os.Getenv("METRICS_PORT")
27+
if portEnv != "" {
28+
metricsPort = portEnv
29+
}
30+
http.Handle("/metrics", promhttp.Handler())
31+
klog.Fatal(http.ListenAndServe(":"+metricsPort, nil))
32+
}()
33+
}
34+
35+
// Instruments the given HTTP handler with counter (total requests) and gauge (in flight requests) metrics
36+
func InstrumentHttpHandler(handler func(http.ResponseWriter, *http.Request), metricNamePrefix string, helpTextSuffix string) http.HandlerFunc {
37+
klog.InfoS("Instrumenting HTTP handler", "metricPrefix", metricNamePrefix, "helpSuffix", helpTextSuffix)
38+
return promhttp.InstrumentHandlerCounter(
39+
promauto.NewCounterVec(
40+
prometheus.CounterOpts{
41+
Name: metricNamePrefix + "_total",
42+
Help: "Total " + helpTextSuffix,
43+
},
44+
[]string{"code", "method"},
45+
),
46+
promhttp.InstrumentHandlerInFlight(promauto.NewGauge(
47+
prometheus.GaugeOpts{
48+
Name: metricNamePrefix + "_in_flight",
49+
Help: "Current " + helpTextSuffix,
50+
},
51+
),
52+
http.HandlerFunc(handler),
53+
),
54+
)
55+
}

0 commit comments

Comments
 (0)