Add admission_latencies_milliseconds metrics for backward compatible
Kubernetes-commit: d9c57e74076ea8bacbba4628eb9c994c165270bf
This commit is contained in:
		
							parent
							
								
									ab09d1ac67
								
							
						
					
					
						commit
						ddce6d2b02
					
				|  | @ -153,19 +153,31 @@ func (m *AdmissionMetrics) ObserveWebhook(elapsed time.Duration, rejected bool, | |||
| } | ||||
| 
 | ||||
| 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"), | ||||
| 				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, | ||||
|  | @ -178,37 +190,61 @@ func newMetricSet(name string, labels []string, helpTemplate string, hasSummary | |||
| 				Namespace: namespace, | ||||
| 				Subsystem: subsystem, | ||||
| 				Name:      fmt.Sprintf("%s_admission_latencies_seconds", name), | ||||
| 				Help:      fmt.Sprintf(helpTemplate, "latency histogram"), | ||||
| 				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(elapsedSeconds) | ||||
| 	m.deprecatedLatencies.WithLabelValues(labels...).Observe(elapsedMicroseconds) | ||||
| 	if m.latenciesSummary != nil { | ||||
| 		m.latenciesSummary.WithLabelValues(labels...).Observe(elapsedSeconds) | ||||
| 	} | ||||
| 	if m.deprecatedLatenciesSummary != nil { | ||||
| 		m.deprecatedLatenciesSummary.WithLabelValues(labels...).Observe(elapsedMicroseconds) | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue