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