prometheus/discovery/kubernetes
Giedrius Statkevičius e452308e37 discovery/kubernetes: optimize resolvePodRef
resolvePodRef is in a hot path:

```
ROUTINE ======================== github.com/prometheus/prometheus/discovery/kubernetes.(*Endpoints).resolvePodRef in discovery/kubernetes/endpoints.go
    2.50TB     2.66TB (flat, cum) 22.28% of Total
         .          .    447:func (e *Endpoints) resolvePodRef(ref *apiv1.ObjectReference) *apiv1.Pod {
         .          .    448:   if ref == nil || ref.Kind != "Pod" {
         .          .    449:           return nil
         .          .    450:   }
    2.50TB     2.50TB    451:   p := &apiv1.Pod{}
         .          .    452:   p.Namespace = ref.Namespace
         .          .    453:   p.Name = ref.Name
         .          .    454:
         .   156.31GB    455:   obj, exists, err := e.podStore.Get(p)
         .          .    456:   if err != nil {
         .          .    457:           level.Error(e.logger).Log("msg", "resolving pod ref failed", "err", err)
         .          .    458:           return nil
         .          .    459:   }
         .          .    460:   if !exists {
```

This is some low hanging fruit that we can easily optimize. The key of
an object has format "namespace/name" so generate that inside of
Prometheus itself and use pooling.

```
goos: linux
goarch: amd64
pkg: github.com/prometheus/prometheus/discovery/kubernetes
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
                 │   olddisc    │               newdisc               │
                 │    sec/op    │   sec/op     vs base                │
ResolvePodRef-16   516.3n ± 17%   289.5n ± 7%  -43.92% (p=0.000 n=10)

                 │   olddisc    │              newdisc               │
                 │     B/op     │    B/op     vs base                │
ResolvePodRef-16   1168.00 ± 0%   24.00 ± 0%  -97.95% (p=0.000 n=10)

                 │  olddisc   │            newdisc             │
                 │ allocs/op  │ allocs/op   vs base            │
ResolvePodRef-16   2.000 ± 0%   2.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal
```

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
2024-10-28 12:12:40 +02:00
..
endpoints.go discovery/kubernetes: optimize resolvePodRef 2024-10-28 12:12:40 +02:00
endpoints_test.go discovery/kubernetes: optimize resolvePodRef 2024-10-28 12:12:40 +02:00
endpointslice.go fix(discovery): Handle cache.DeletedFinalStateUnknown in node informers' DeleteFunc 2024-10-16 10:20:37 +02:00
endpointslice_adaptor.go discovery(k8s): remove support for API versions no longer served 2024-07-04 14:54:27 +02:00
endpointslice_adaptor_test.go discovery(k8s): remove support for API versions no longer served 2024-07-04 14:54:27 +02:00
endpointslice_test.go tests: update discovery tests with new labael 2024-10-01 10:26:58 +02:00
ingress.go chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04:00
ingress_adaptor.go discovery(k8s): remove support for API versions no longer served 2024-07-04 14:54:27 +02:00
ingress_test.go discovery(k8s): remove support for API versions no longer served 2024-07-04 14:54:27 +02:00
kubernetes.go fix(discovery): Handle cache.DeletedFinalStateUnknown in node informers' DeleteFunc 2024-10-16 10:20:37 +02:00
kubernetes_test.go fix(discovery): Handle cache.DeletedFinalStateUnknown in node informers' DeleteFunc 2024-10-16 10:20:37 +02:00
metrics.go discovery(k8s): add a metric to track failed requests, failures will still be logged. 2024-02-28 19:55:46 +01:00
node.go fix(discovery): Handle cache.DeletedFinalStateUnknown in node informers' DeleteFunc 2024-10-16 10:20:37 +02:00
node_test.go Kubernetes service discovery: add provider ID label (#9603) 2021-12-06 22:27:11 +01:00
pod.go fix(discovery): Handle cache.DeletedFinalStateUnknown in node informers' DeleteFunc 2024-10-16 10:20:37 +02:00
pod_test.go Add container ID as a meta label for pod targets 2023-01-11 11:44:36 -05:00
service.go chore!: adopt log/slog, remove go-kit/log 2024-10-07 15:58:50 -04:00
service_test.go add loadbalancerip to service labels 2022-08-10 12:40:11 +02:00