mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 08:23:34 +01:00
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:
parent
535fea3d11
commit
92bc1afcee
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user