| Jan Schär | a48bd3c | 2024-07-29 17:22:18 +0200 | [diff] [blame^] | 1 | package kubernetes |
| 2 | |
| 3 | // Taken and modified from the Kubernetes plugin of CoreDNS, under Apache 2.0. |
| 4 | |
| 5 | import ( |
| 6 | "time" |
| 7 | |
| 8 | "github.com/prometheus/client_golang/prometheus" |
| 9 | |
| 10 | "source.monogon.dev/osbase/net/dns" |
| 11 | ) |
| 12 | |
| 13 | var ( |
| 14 | // dnsProgrammingLatency is defined as the time it took to program a DNS |
| 15 | // instance - from the time a service or pod has changed to the time the |
| 16 | // change was propagated and was available to be served by a DNS server. |
| 17 | // The definition of this SLI can be found at https://github.com/kubernetes/community/blob/master/sig-scalability/slos/dns_programming_latency.md |
| 18 | // Note that the metrics is partially based on the time exported by the |
| 19 | // endpoints controller on the master machine. The measurement may be |
| 20 | // inaccurate if there is a clock drift between the node and master machine. |
| 21 | // The service_kind label can be one of: |
| 22 | // * cluster_ip |
| 23 | // * headless_with_selector |
| 24 | // * headless_without_selector |
| 25 | dnsProgrammingLatency = dns.MetricsFactory.NewHistogramVec(prometheus.HistogramOpts{ |
| 26 | Namespace: "dnsserver", |
| 27 | Subsystem: "kubernetes", |
| 28 | Name: "dns_programming_duration_seconds", |
| 29 | // From 1 millisecond to ~17 minutes. |
| 30 | Buckets: prometheus.ExponentialBuckets(0.001, 2, 20), |
| 31 | Help: "In Cluster DNS Programming Latency in seconds", |
| 32 | }, []string{"service_kind"}) |
| 33 | ) |
| 34 | |
| 35 | func recordDNSProgrammingLatency(lastChangeTriggerTime time.Time) { |
| 36 | if !lastChangeTriggerTime.IsZero() { |
| 37 | // If we're here it means that the Endpoints object is for a headless service |
| 38 | // and that the Endpoints object was created by the endpoints-controller |
| 39 | // (because the LastChangeTriggerTime annotation is set). It means that the |
| 40 | // corresponding service is a "headless service with selector". |
| 41 | dnsProgrammingLatency.WithLabelValues("headless_with_selector"). |
| 42 | Observe(time.Since(lastChangeTriggerTime).Seconds()) |
| 43 | } |
| 44 | } |