Skip to content

Commit 935815f

Browse files
Merge pull request #106122 from rezakrimi/issue/105862
making some apiserver metrics stable Kubernetes-commit: ae550b62da15ca5fe4983c79aaa6b2a39e3e711a
2 parents 556349a + 193bf2c commit 935815f

File tree

4 files changed

+64
-51
lines changed

4 files changed

+64
-51
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
gopkg.in/square/go-jose.v2 v2.2.2
4747
k8s.io/api v0.0.0-20211104203923-7979b39b3911
4848
k8s.io/apimachinery v0.0.0-20211105203412-d7e096fd217f
49-
k8s.io/client-go v0.0.0-20211105164225-9b0b23a8ade2
49+
k8s.io/client-go v0.0.0-20211108163918-6d69eb8ad66c
5050
k8s.io/component-base v0.0.0-20211104205040-9025b85fb213
5151
k8s.io/klog/v2 v2.30.0
5252
k8s.io/kube-openapi v0.0.0-20210817084001-7fbd8d59e5b8
@@ -59,6 +59,6 @@ require (
5959
replace (
6060
k8s.io/api => k8s.io/api v0.0.0-20211104203923-7979b39b3911
6161
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20211105203412-d7e096fd217f
62-
k8s.io/client-go => k8s.io/client-go v0.0.0-20211105164225-9b0b23a8ade2
62+
k8s.io/client-go => k8s.io/client-go v0.0.0-20211108163918-6d69eb8ad66c
6363
k8s.io/component-base => k8s.io/component-base v0.0.0-20211104205040-9025b85fb213
6464
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,8 @@ k8s.io/api v0.0.0-20211104203923-7979b39b3911 h1:KKASx2y52X9MofhS6vOnUdLGgz+CH8/
948948
k8s.io/api v0.0.0-20211104203923-7979b39b3911/go.mod h1:Y3aSuR3Z7RwvAGbnpQ1+oBIWgAIxvlHcaUCVUzOgpuo=
949949
k8s.io/apimachinery v0.0.0-20211105203412-d7e096fd217f h1:GhfOaNapo86CszGIgYEv2kO136l13jxtg9Ollcge114=
950950
k8s.io/apimachinery v0.0.0-20211105203412-d7e096fd217f/go.mod h1:NdmIf2dMPBkkSfPmCDRbThro3RAWWypv6x+CttBbMto=
951-
k8s.io/client-go v0.0.0-20211105164225-9b0b23a8ade2 h1:xSziulz0lPNAGwDShPbAl/GDC0WhcT0SXBSgupRuvwA=
952-
k8s.io/client-go v0.0.0-20211105164225-9b0b23a8ade2/go.mod h1:g16LjnowDDsmCFt4UWsyD8NLjDvW3fPe9yrv0R1cGeE=
951+
k8s.io/client-go v0.0.0-20211108163918-6d69eb8ad66c h1:s5vCBULsOhcAM2PYOAkWd80073+znVOFarjt6tBBZZI=
952+
k8s.io/client-go v0.0.0-20211108163918-6d69eb8ad66c/go.mod h1:02q+oqOEJnuqNoUa0/UqLsGM+YH6Wb845RmkUjcgtd0=
953953
k8s.io/component-base v0.0.0-20211104205040-9025b85fb213 h1:lyyB2OygJtIIBbgpRR2dKm5aue0Aqax/LJDvXBst1bI=
954954
k8s.io/component-base v0.0.0-20211104205040-9025b85fb213/go.mod h1:GiuGF3WbM9lKQ32U85f+z0vIRD1J3vAg3My8kBvmbOA=
955955
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=

pkg/admission/metrics/metrics.go

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package metrics
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"strconv"
2322
"time"
2423

@@ -45,8 +44,6 @@ const (
4544
)
4645

4746
var (
48-
// Use buckets ranging from 5 ms to 2.5 seconds (admission webhooks timeout at 30 seconds by default).
49-
latencyBuckets = []float64{0.005, 0.025, 0.1, 0.5, 1.0, 2.5}
5047
latencySummaryMaxAge = 5 * time.Hour
5148

5249
// Metrics provides access to all admission metrics.
@@ -126,19 +123,68 @@ type AdmissionMetrics struct {
126123
func newAdmissionMetrics() *AdmissionMetrics {
127124
// Admission metrics for a step of the admission flow. The entire admission flow is broken down into a series of steps
128125
// Each step is identified by a distinct type label value.
129-
step := newMetricSet("step",
130-
[]string{"type", "operation", "rejected"},
131-
"Admission sub-step %s, broken out for each operation and API resource and step type (validate or admit).", true)
126+
// Use buckets ranging from 5 ms to 2.5 seconds.
127+
step := &metricSet{
128+
latencies: metrics.NewHistogramVec(
129+
&metrics.HistogramOpts{
130+
Namespace: namespace,
131+
Subsystem: subsystem,
132+
Name: "step_admission_duration_seconds",
133+
Help: "Admission sub-step latency histogram in seconds, broken out for each operation and API resource and step type (validate or admit).",
134+
Buckets: []float64{0.005, 0.025, 0.1, 0.5, 1.0, 2.5},
135+
StabilityLevel: metrics.STABLE,
136+
},
137+
[]string{"type", "operation", "rejected"},
138+
),
139+
140+
latenciesSummary: metrics.NewSummaryVec(
141+
&metrics.SummaryOpts{
142+
Namespace: namespace,
143+
Subsystem: subsystem,
144+
Name: "step_admission_duration_seconds_summary",
145+
Help: "Admission sub-step latency summary in seconds, broken out for each operation and API resource and step type (validate or admit).",
146+
MaxAge: latencySummaryMaxAge,
147+
StabilityLevel: metrics.ALPHA,
148+
},
149+
[]string{"type", "operation", "rejected"},
150+
),
151+
}
132152

133153
// Built-in admission controller metrics. Each admission controller is identified by name.
134-
controller := newMetricSet("controller",
135-
[]string{"name", "type", "operation", "rejected"},
136-
"Admission controller %s, identified by name and broken out for each operation and API resource and type (validate or admit).", false)
154+
// Use buckets ranging from 5 ms to 2.5 seconds.
155+
controller := &metricSet{
156+
latencies: metrics.NewHistogramVec(
157+
&metrics.HistogramOpts{
158+
Namespace: namespace,
159+
Subsystem: subsystem,
160+
Name: "controller_admission_duration_seconds",
161+
Help: "Admission controller latency histogram in seconds, identified by name and broken out for each operation and API resource and type (validate or admit).",
162+
Buckets: []float64{0.005, 0.025, 0.1, 0.5, 1.0, 2.5},
163+
StabilityLevel: metrics.STABLE,
164+
},
165+
[]string{"name", "type", "operation", "rejected"},
166+
),
167+
168+
latenciesSummary: nil,
169+
}
137170

138171
// Admission webhook metrics. Each webhook is identified by name.
139-
webhook := newMetricSet("webhook",
140-
[]string{"name", "type", "operation", "rejected"},
141-
"Admission webhook %s, identified by name and broken out for each operation and API resource and type (validate or admit).", false)
172+
// Use buckets ranging from 5 ms to 2.5 seconds (admission webhooks timeout at 30 seconds by default).
173+
webhook := &metricSet{
174+
latencies: metrics.NewHistogramVec(
175+
&metrics.HistogramOpts{
176+
Namespace: namespace,
177+
Subsystem: subsystem,
178+
Name: "webhook_admission_duration_seconds",
179+
Help: "Admission webhook latency histogram in seconds, identified by name and broken out for each operation and API resource and type (validate or admit).",
180+
Buckets: []float64{0.005, 0.025, 0.1, 0.5, 1.0, 2.5},
181+
StabilityLevel: metrics.STABLE,
182+
},
183+
[]string{"name", "type", "operation", "rejected"},
184+
),
185+
186+
latenciesSummary: nil,
187+
}
142188

143189
webhookRejection := metrics.NewCounterVec(
144190
&metrics.CounterOpts{
@@ -209,39 +255,6 @@ type metricSet struct {
209255
latenciesSummary *metrics.SummaryVec
210256
}
211257

212-
func newMetricSet(name string, labels []string, helpTemplate string, hasSummary bool) *metricSet {
213-
var summary *metrics.SummaryVec
214-
if hasSummary {
215-
summary = metrics.NewSummaryVec(
216-
&metrics.SummaryOpts{
217-
Namespace: namespace,
218-
Subsystem: subsystem,
219-
Name: fmt.Sprintf("%s_admission_duration_seconds_summary", name),
220-
Help: fmt.Sprintf(helpTemplate, "latency summary in seconds"),
221-
MaxAge: latencySummaryMaxAge,
222-
StabilityLevel: metrics.ALPHA,
223-
},
224-
labels,
225-
)
226-
}
227-
228-
return &metricSet{
229-
latencies: metrics.NewHistogramVec(
230-
&metrics.HistogramOpts{
231-
Namespace: namespace,
232-
Subsystem: subsystem,
233-
Name: fmt.Sprintf("%s_admission_duration_seconds", name),
234-
Help: fmt.Sprintf(helpTemplate, "latency histogram in seconds"),
235-
Buckets: latencyBuckets,
236-
StabilityLevel: metrics.ALPHA,
237-
},
238-
labels,
239-
),
240-
241-
latenciesSummary: summary,
242-
}
243-
}
244-
245258
// MustRegister registers all the prometheus metrics in the metricSet.
246259
func (m *metricSet) mustRegister() {
247260
legacyregistry.MustRegister(m.latencies)

pkg/endpoints/metrics/metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ var (
115115
Help: "Response size distribution in bytes for each group, version, verb, resource, subresource, scope and component.",
116116
// Use buckets ranging from 1000 bytes (1KB) to 10^9 bytes (1GB).
117117
Buckets: compbasemetrics.ExponentialBuckets(1000, 10.0, 7),
118-
StabilityLevel: compbasemetrics.ALPHA,
118+
StabilityLevel: compbasemetrics.STABLE,
119119
},
120120
[]string{"verb", "group", "version", "resource", "subresource", "scope", "component"},
121121
)
@@ -169,7 +169,7 @@ var (
169169
&compbasemetrics.GaugeOpts{
170170
Name: "apiserver_current_inflight_requests",
171171
Help: "Maximal number of currently used inflight request limit of this apiserver per request kind in last second.",
172-
StabilityLevel: compbasemetrics.ALPHA,
172+
StabilityLevel: compbasemetrics.STABLE,
173173
},
174174
[]string{"request_kind"},
175175
)

0 commit comments

Comments
 (0)