Skip to content

Commit

Permalink
lib/promscrape/discovery/kubernetes: reduce memory usage for labels w…
Browse files Browse the repository at this point in the history
…hen discovering big number of scrape targets by using string concatenation instead of fmt.Sprintf

Updates #825
  • Loading branch information
valyala committed Nov 7, 2020
1 parent 535fea3 commit 92bc1af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/promscrape/discovery/kubernetes/common_types.go
@@ -1,7 +1,6 @@
package kubernetes

import (
"fmt"
"net/url"
"strings"

Expand All @@ -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"
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/promscrape/discovery/kubernetes/node.go
Expand Up @@ -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
Expand Down

0 comments on commit 92bc1af

Please sign in to comment.