mirror of https://github.com/linkerd/linkerd2.git
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.
This commit is contained in:
parent
7c87fd4498
commit
de635d3fcf
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
pb "github.com/linkerd/linkerd2/controller/gen/public"
|
pb "github.com/linkerd/linkerd2/controller/gen/public"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
@ -96,14 +97,22 @@ func processEdgeMetrics(inbound, outbound model.Vector, resourceType, selectedNa
|
||||||
for _, sample := range inbound {
|
for _, sample := range inbound {
|
||||||
// skip inbound results without a clientID because we cannot construct edge
|
// skip inbound results without a clientID because we cannot construct edge
|
||||||
// information
|
// information
|
||||||
if _, ok := sample.Metric[model.LabelName("client_id")]; ok {
|
if clientID, ok := sample.Metric[model.LabelName("client_id")]; ok {
|
||||||
key := sample.Metric[model.LabelName(resourceReplacementInbound)]
|
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
|
dstIndex[key] = sample.Metric
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sample := range outbound {
|
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 {
|
if _, ok := srcIndex[key]; !ok {
|
||||||
srcIndex[key] = []model.Metric{}
|
srcIndex[key] = []model.Metric{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue