[ISSUE #12196] FIX prometheus http sd invalid label names (#12239)

* prometheus http sd: fix invalid label names

* Update PrometheusUtils.java
This commit is contained in:
Thomas Lee 2024-07-01 13:53:32 +08:00 committed by GitHub
parent b8d13e0557
commit 92a3d17681
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.groupingBy;
@ -62,6 +63,9 @@ public class PrometheusUtils {
labelNode.put("__meta_clusterName", clusterName);
//export metadata
Map<String, String> metadata = instance.getMetadata();
// auto convert label names contain with "." and "-" to "_"
metadata = metadata.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().replace(".", "_").replace("-", "_"), e -> e.getValue()));
metadata.forEach(labelNode::put);
ObjectNode jsonNode = JacksonUtils.createEmptyJsonNode();
jsonNode.replace("targets", targetsNode);