Skip to content

Commit cbce404

Browse files
committed
Add http status code to lease list latency
1 parent 3e9dee9 commit cbce404

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pkg/agent/lease_counter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ func NewLeaseInformerWithMetrics(client kubernetes.Interface, namespace string,
9595
&cache.ListWatch{
9696
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
9797
start := time.Now()
98+
httpCode := 200
9899
defer func() {
99100
latency := time.Now().Sub(start)
100-
metrics.Metrics.ObserveLeaseListLatency(latency)
101+
metrics.Metrics.ObserveLeaseListLatency(latency, httpCode)
101102
}()
102103
obj, err := client.CoordinationV1().Leases(namespace).List(context.TODO(), options)
103104
if err != nil {
@@ -106,6 +107,7 @@ func NewLeaseInformerWithMetrics(client kubernetes.Interface, namespace string,
106107
var apiStatus apierrors.APIStatus
107108
if errors.As(err, &apiStatus) {
108109
status := apiStatus.Status()
110+
httpCode = int(status.Code)
109111
metrics.Metrics.ObserveLeaseList(int(status.Code), string(status.Reason))
110112
} else {
111113
klog.Errorf("Lease list error could not be logged to metrics as it is not an APIStatus: %v", err)

pkg/agent/metrics/metrics.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type AgentMetrics struct {
6060
streamErrors *prometheus.CounterVec
6161
leaseLists *prometheus.CounterVec
6262
leaseWatches *prometheus.CounterVec
63-
leaseListLatencies prometheus.Histogram
63+
leaseListLatencies *prometheus.HistogramVec
6464
}
6565

6666
// newAgentMetrics create a new AgentMetrics, configured with default metric names.
@@ -137,14 +137,15 @@ func newAgentMetrics() *AgentMetrics {
137137
},
138138
[]string{"http_response_code", "reason"},
139139
)
140-
leaseListLatencies := prometheus.NewHistogram(
140+
leaseListLatencies := prometheus.NewHistogramVec(
141141
prometheus.HistogramOpts{
142142
Namespace: Namespace,
143143
Subsystem: Subsystem,
144144
Name: "lease_list_latency_seconds",
145145
Help: "Latency of server lease listing in seconds",
146146
Buckets: latencyBuckets,
147147
},
148+
[]string{"http_response_code"},
148149
)
149150
streamPackets := commonmetrics.MakeStreamPacketsTotalMetric(Namespace, Subsystem)
150151
streamErrors := commonmetrics.MakeStreamErrorsTotalMetric(Namespace, Subsystem)
@@ -226,8 +227,8 @@ func (a *AgentMetrics) ObserveLeaseWatch(httpCode int, reason string) {
226227
a.leaseLists.WithLabelValues(strconv.Itoa(httpCode), reason).Inc()
227228
}
228229

229-
func (a *AgentMetrics) ObserveLeaseListLatency(latency time.Duration) {
230-
a.leaseListLatencies.Observe(latency.Seconds())
230+
func (a *AgentMetrics) ObserveLeaseListLatency(latency time.Duration, httpCode int) {
231+
a.leaseListLatencies.WithLabelValues(strconv.Itoa(httpCode)).Observe(latency.Seconds())
231232
}
232233

233234
// EndpointConnectionInc increments a new endpoint connection.

0 commit comments

Comments
 (0)