From de635d3fcf7c9cd960cce9b5732c6452d2a7f003 Mon Sep 17 00:00:00 2001 From: "Carol A. Scott" Date: Tue, 2 Jul 2019 12:31:15 -0700 Subject: [PATCH] Allow `edges` to handle requests from multiple namespaces to one resource (#3025) This PR fixes a bug in the edges command where if src_resources from two different namespaces sent requests to the same dst_resource, the original src_identity was overwritten. --- controller/api/public/edges.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/controller/api/public/edges.go b/controller/api/public/edges.go index 5249a7df7..a30a8bfa3 100644 --- a/controller/api/public/edges.go +++ b/controller/api/public/edges.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" pb "github.com/linkerd/linkerd2/controller/gen/public" "github.com/prometheus/common/model" @@ -96,14 +97,22 @@ func processEdgeMetrics(inbound, outbound model.Vector, resourceType, selectedNa for _, sample := range inbound { // skip inbound results without a clientID because we cannot construct edge // information - if _, ok := sample.Metric[model.LabelName("client_id")]; ok { - key := sample.Metric[model.LabelName(resourceReplacementInbound)] + if clientID, ok := sample.Metric[model.LabelName("client_id")]; ok { + dstResource := string(sample.Metric[model.LabelName(resourceReplacementInbound)]) + + // format of clientId is id.namespace.serviceaccount.cluster.local + clientIDSlice := strings.Split(string(clientID), ".") + srcNs := clientIDSlice[1] + key := model.LabelValue(fmt.Sprintf("%s.%s", dstResource, srcNs)) dstIndex[key] = sample.Metric } } for _, sample := range outbound { - key := sample.Metric[model.LabelName(resourceReplacementOutbound)] + dstResource := sample.Metric[model.LabelName(resourceReplacementOutbound)] + srcNs := sample.Metric[model.LabelName("namespace")] + + key := model.LabelValue(fmt.Sprintf("%s.%s", dstResource, srcNs)) if _, ok := srcIndex[key]; !ok { srcIndex[key] = []model.Metric{} }