lib/promscrape/discovery/kubernetes: reduce memory usage for labels when discovering big number of scrape targets by using string concatenation instead of fmt.Sprintf

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/825
This commit is contained in:
Aliaksandr Valialkin 2020-11-07 13:02:12 +02:00
parent 535fea3d11
commit 92bc1afcee
2 changed files with 5 additions and 6 deletions

View file

@ -1,7 +1,6 @@
package kubernetes
import (
"fmt"
"net/url"
"strings"
@ -23,13 +22,13 @@ type ObjectMeta struct {
func (om *ObjectMeta) registerLabelsAndAnnotations(prefix string, m map[string]string) {
for _, lb := range om.Labels {
ln := discoveryutils.SanitizeLabelName(lb.Name)
m[fmt.Sprintf("%s_label_%s", prefix, ln)] = lb.Value
m[fmt.Sprintf("%s_labelpresent_%s", prefix, ln)] = "true"
m[prefix + "_label_" + ln] = lb.Value
m[prefix + "_labelpresent_" + ln] = "true"
}
for _, a := range om.Annotations {
an := discoveryutils.SanitizeLabelName(a.Name)
m[fmt.Sprintf("%s_annotation_%s", prefix, an)] = a.Value
m[fmt.Sprintf("%s_annotationpresent_%s", prefix, an)] = "true"
m[prefix + "_annotation_" + an] = a.Value
m[prefix + "_annotationpresent_" + an] = "true"
}
}

View file

@ -95,7 +95,7 @@ func (n *Node) appendTargetLabels(ms []map[string]string) []map[string]string {
}
addrTypesUsed[a.Type] = true
ln := discoveryutils.SanitizeLabelName(a.Type)
m[fmt.Sprintf("__meta_kubernetes_node_address_%s", ln)] = a.Address
m["__meta_kubernetes_node_address_" + ln] = a.Address
}
ms = append(ms, m)
return ms