mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 22:25:03 +00:00
vendor dependencies
This commit is contained in:
parent
604208ef4f
commit
72abf135d6
1156 changed files with 78178 additions and 105799 deletions
79
vendor/k8s.io/apiserver/pkg/admission/metrics/metrics.go
generated
vendored
79
vendor/k8s.io/apiserver/pkg/admission/metrics/metrics.go
generated
vendored
|
|
@ -75,27 +75,27 @@ type pluginHandlerWithMetrics struct {
|
|||
}
|
||||
|
||||
// Admit performs a mutating admission control check and emit metrics.
|
||||
func (p pluginHandlerWithMetrics) Admit(a admission.Attributes) error {
|
||||
func (p pluginHandlerWithMetrics) Admit(a admission.Attributes, o admission.ObjectInterfaces) error {
|
||||
mutatingHandler, ok := p.Interface.(admission.MutationInterface)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
err := mutatingHandler.Admit(a)
|
||||
err := mutatingHandler.Admit(a, o)
|
||||
p.observer(time.Since(start), err != nil, a, stepAdmit, p.extraLabels...)
|
||||
return err
|
||||
}
|
||||
|
||||
// Validate performs a non-mutating admission control check and emits metrics.
|
||||
func (p pluginHandlerWithMetrics) Validate(a admission.Attributes) error {
|
||||
func (p pluginHandlerWithMetrics) Validate(a admission.Attributes, o admission.ObjectInterfaces) error {
|
||||
validatingHandler, ok := p.Interface.(admission.ValidationInterface)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
err := validatingHandler.Validate(a)
|
||||
err := validatingHandler.Validate(a, o)
|
||||
p.observer(time.Since(start), err != nil, a, stepValidate, p.extraLabels...)
|
||||
return err
|
||||
}
|
||||
|
|
@ -112,17 +112,17 @@ func newAdmissionMetrics() *AdmissionMetrics {
|
|||
// Admission metrics for a step of the admission flow. The entire admission flow is broken down into a series of steps
|
||||
// Each step is identified by a distinct type label value.
|
||||
step := newMetricSet("step",
|
||||
[]string{"type", "operation", "group", "version", "resource", "subresource", "rejected"},
|
||||
[]string{"type", "operation", "rejected"},
|
||||
"Admission sub-step %s, broken out for each operation and API resource and step type (validate or admit).", true)
|
||||
|
||||
// Built-in admission controller metrics. Each admission controller is identified by name.
|
||||
controller := newMetricSet("controller",
|
||||
[]string{"name", "type", "operation", "group", "version", "resource", "subresource", "rejected"},
|
||||
[]string{"name", "type", "operation", "rejected"},
|
||||
"Admission controller %s, identified by name and broken out for each operation and API resource and type (validate or admit).", false)
|
||||
|
||||
// Admission webhook metrics. Each webhook is identified by name.
|
||||
webhook := newMetricSet("webhook",
|
||||
[]string{"name", "type", "operation", "group", "version", "resource", "subresource", "rejected"},
|
||||
[]string{"name", "type", "operation", "rejected"},
|
||||
"Admission webhook %s, identified by name and broken out for each operation and API resource and type (validate or admit).", false)
|
||||
|
||||
step.mustRegister()
|
||||
|
|
@ -139,36 +139,45 @@ func (m *AdmissionMetrics) reset() {
|
|||
|
||||
// ObserveAdmissionStep records admission related metrics for a admission step, identified by step type.
|
||||
func (m *AdmissionMetrics) ObserveAdmissionStep(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
||||
gvr := attr.GetResource()
|
||||
m.step.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected))...)
|
||||
m.step.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), strconv.FormatBool(rejected))...)
|
||||
}
|
||||
|
||||
// ObserveAdmissionController records admission related metrics for a built-in admission controller, identified by it's plugin handler name.
|
||||
func (m *AdmissionMetrics) ObserveAdmissionController(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
||||
gvr := attr.GetResource()
|
||||
m.controller.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected))...)
|
||||
m.controller.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), strconv.FormatBool(rejected))...)
|
||||
}
|
||||
|
||||
// ObserveWebhook records admission related metrics for a admission webhook.
|
||||
func (m *AdmissionMetrics) ObserveWebhook(elapsed time.Duration, rejected bool, attr admission.Attributes, stepType string, extraLabels ...string) {
|
||||
gvr := attr.GetResource()
|
||||
m.webhook.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), gvr.Group, gvr.Version, gvr.Resource, attr.GetSubresource(), strconv.FormatBool(rejected))...)
|
||||
m.webhook.observe(elapsed, append(extraLabels, stepType, string(attr.GetOperation()), strconv.FormatBool(rejected))...)
|
||||
}
|
||||
|
||||
type metricSet struct {
|
||||
latencies *prometheus.HistogramVec
|
||||
latenciesSummary *prometheus.SummaryVec
|
||||
latencies *prometheus.HistogramVec
|
||||
deprecatedLatencies *prometheus.HistogramVec
|
||||
latenciesSummary *prometheus.SummaryVec
|
||||
deprecatedLatenciesSummary *prometheus.SummaryVec
|
||||
}
|
||||
|
||||
func newMetricSet(name string, labels []string, helpTemplate string, hasSummary bool) *metricSet {
|
||||
var summary *prometheus.SummaryVec
|
||||
var summary, deprecatedSummary *prometheus.SummaryVec
|
||||
if hasSummary {
|
||||
summary = prometheus.NewSummaryVec(
|
||||
prometheus.SummaryOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: fmt.Sprintf("%s_admission_latencies_seconds_summary", name),
|
||||
Help: fmt.Sprintf(helpTemplate, "latency summary"),
|
||||
Name: fmt.Sprintf("%s_admission_duration_seconds_summary", name),
|
||||
Help: fmt.Sprintf(helpTemplate, "latency summary in seconds"),
|
||||
MaxAge: latencySummaryMaxAge,
|
||||
},
|
||||
labels,
|
||||
)
|
||||
deprecatedSummary = prometheus.NewSummaryVec(
|
||||
prometheus.SummaryOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: fmt.Sprintf("%s_admission_latencies_milliseconds_summary", name),
|
||||
Help: fmt.Sprintf("(Deprecated) "+helpTemplate, "latency summary in milliseconds"),
|
||||
MaxAge: latencySummaryMaxAge,
|
||||
},
|
||||
labels,
|
||||
|
|
@ -180,38 +189,62 @@ func newMetricSet(name string, labels []string, helpTemplate string, hasSummary
|
|||
prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: fmt.Sprintf("%s_admission_latencies_seconds", name),
|
||||
Help: fmt.Sprintf(helpTemplate, "latency histogram"),
|
||||
Name: fmt.Sprintf("%s_admission_duration_seconds", name),
|
||||
Help: fmt.Sprintf(helpTemplate, "latency histogram in seconds"),
|
||||
Buckets: latencyBuckets,
|
||||
},
|
||||
labels,
|
||||
),
|
||||
deprecatedLatencies: prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: fmt.Sprintf("%s_admission_latencies_milliseconds", name),
|
||||
Help: fmt.Sprintf("(Deprecated) "+helpTemplate, "latency histogram in milliseconds"),
|
||||
Buckets: latencyBuckets,
|
||||
},
|
||||
labels,
|
||||
),
|
||||
|
||||
latenciesSummary: summary,
|
||||
latenciesSummary: summary,
|
||||
deprecatedLatenciesSummary: deprecatedSummary,
|
||||
}
|
||||
}
|
||||
|
||||
// MustRegister registers all the prometheus metrics in the metricSet.
|
||||
func (m *metricSet) mustRegister() {
|
||||
prometheus.MustRegister(m.latencies)
|
||||
prometheus.MustRegister(m.deprecatedLatencies)
|
||||
if m.latenciesSummary != nil {
|
||||
prometheus.MustRegister(m.latenciesSummary)
|
||||
}
|
||||
if m.deprecatedLatenciesSummary != nil {
|
||||
prometheus.MustRegister(m.deprecatedLatenciesSummary)
|
||||
}
|
||||
}
|
||||
|
||||
// Reset resets all the prometheus metrics in the metricSet.
|
||||
func (m *metricSet) reset() {
|
||||
m.latencies.Reset()
|
||||
m.deprecatedLatencies.Reset()
|
||||
if m.latenciesSummary != nil {
|
||||
m.latenciesSummary.Reset()
|
||||
}
|
||||
if m.deprecatedLatenciesSummary != nil {
|
||||
m.deprecatedLatenciesSummary.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
// Observe records an observed admission event to all metrics in the metricSet.
|
||||
func (m *metricSet) observe(elapsed time.Duration, labels ...string) {
|
||||
elapsedSeconds := elapsed.Seconds()
|
||||
elapsedMicroseconds := float64(elapsed / time.Microsecond)
|
||||
m.latencies.WithLabelValues(labels...).Observe(elapsedMicroseconds)
|
||||
m.latencies.WithLabelValues(labels...).Observe(elapsedSeconds)
|
||||
m.deprecatedLatencies.WithLabelValues(labels...).Observe(elapsedMicroseconds)
|
||||
if m.latenciesSummary != nil {
|
||||
m.latenciesSummary.WithLabelValues(labels...).Observe(elapsedMicroseconds)
|
||||
m.latenciesSummary.WithLabelValues(labels...).Observe(elapsedSeconds)
|
||||
}
|
||||
if m.deprecatedLatenciesSummary != nil {
|
||||
m.deprecatedLatenciesSummary.WithLabelValues(labels...).Observe(elapsedMicroseconds)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue