Răsfoiți Sursa

Added Instance field to metric, but only use if node is empty

Matt Bolt 1 an în urmă
părinte
comite
323b465d6d
1 a modificat fișierele cu 9 adăugiri și 5 ștergeri
  1. 9 5
      core/pkg/source/decoders.go

+ 9 - 5
core/pkg/source/decoders.go

@@ -423,6 +423,7 @@ func DecodePodsResult(result *QueryResult) *PodsResult {
 type ContainerMetricResult struct {
 	Cluster   string
 	Node      string
+	Instance  string
 	Namespace string
 	Pod       string
 	Container string
@@ -433,11 +434,13 @@ type ContainerMetricResult struct {
 func DecodeContainerMetricResult(result *QueryResult) *ContainerMetricResult {
 	cluster, _ := result.GetCluster()
 
-	// Note: This emulates the relabel behavior from older queries - we just do this by default
-	// Note: if node is empty
-	node, err := result.GetNode()
-	if err != nil || node == "" {
-		node, _ = result.GetInstance()
+	node, _ := result.GetNode()
+	instance, _ := result.GetInstance()
+
+	// NOTE: this addresses cases where the node isn't set, but the instance is,
+	// NOTE: we just inherit the instance as the node
+	if node == "" {
+		node = instance
 	}
 
 	namespace, _ := result.GetNamespace()
@@ -447,6 +450,7 @@ func DecodeContainerMetricResult(result *QueryResult) *ContainerMetricResult {
 	return &ContainerMetricResult{
 		Cluster:   cluster,
 		Node:      node,
+		Instance:  instance,
 		Namespace: namespace,
 		Pod:       pod,
 		Container: container,