lib/promscrape/discovery/kubernetes: log a warning if role: endpoints discovers more than 1000 targets per a single endpoint

In this case `role: endpointslice` must be used instead.

See the following references:

* https://kubernetes.io/docs/reference/labels-annotations-taints/#endpoints-kubernetes-io-over-capacity
* https://github.com/kubernetes/kubernetes/pull/99975
* https://github.com/prometheus/prometheus/issues/7572#issuecomment-934779398
This commit is contained in:
Aliaksandr Valialkin 2021-10-19 13:19:18 +03:00
parent 0d48b89afe
commit 3408a05d12
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 19 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils"
)
@ -103,6 +104,14 @@ func (eps *Endpoints) getTargetLabels(gw *groupWatcher) []map[string]string {
ms = appendEndpointLabelsForAddresses(ms, gw, podPortsSeen, eps, ess.NotReadyAddresses, epp, svc, "false")
}
}
// See https://kubernetes.io/docs/reference/labels-annotations-taints/#endpoints-kubernetes-io-over-capacity
// and https://github.com/kubernetes/kubernetes/pull/99975
switch eps.Metadata.Annotations.GetByName("endpoints.kubernetes.io/over-capacity") {
case "truncated":
logger.Warnf(`the number of targets for "role: endpoints" %q exceeds 1000 and has been truncated; please use "role: endpointslice" instead`, eps.Metadata.key())
case "warning":
logger.Warnf(`the number of targets for "role: endpoints" %q exceeds 1000 and will be truncated in the next k8s releases; please use "role: endpointslice" instead`, eps.Metadata.key())
}
// Append labels for skipped ports on seen pods.
portSeen := func(port int, ports []int) bool {

View File

@ -33,6 +33,16 @@ func JoinHostPort(host string, port int) string {
// SortedLabels represents sorted labels.
type SortedLabels []prompbmarshal.Label
// GetByName returns the label with the given name from sls.
func (sls *SortedLabels) GetByName(name string) string {
for _, lb := range *sls {
if lb.Name == name {
return lb.Value
}
}
return ""
}
// UnmarshalJSON unmarshals JSON from data.
func (sls *SortedLabels) UnmarshalJSON(data []byte) error {
var m map[string]string