Skip to content

Commit 1c3ce48

Browse files
committed
Export zone locality in outbound destination metrics
Currently, we don't have a simple way of checking if the endpoint a proxy is discovering is in the same zone or not. This adds a "zone_locality" metric label to the outbound destination address metrics. Note that this does not increase the cardinality of the related metrics, as this label doesn't vary within an endpoint. Validated by checking the prometheus metrics on a local cluster and verifying this label appears in the outbound transport metrics. Signed-off-by: Scott Fleener <[email protected]>
1 parent f73fb11 commit 1c3ce48

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

controller/api/destination/endpoint_translator.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ func (et *endpointTranslator) sendClientAdd(set watcher.AddressSet) {
444444
Addr: addr,
445445
Weight: defaultWeight,
446446
AuthorityOverride: authOverride,
447+
MetricLabels: map[string]string{},
447448
}
448449

449450
if address.Identity != "" {
@@ -465,12 +466,20 @@ func (et *endpointTranslator) sendClientAdd(set watcher.AddressSet) {
465466
}
466467
}
467468

468-
if et.extEndpointZoneWeights {
469-
// EXPERIMENTAL: Use the endpoint weight field to indicate zonal
470-
// preference so that local endoints are more heavily weighted.
471-
if et.nodeTopologyZone != "" && address.Zone != nil && *address.Zone == et.nodeTopologyZone {
472-
wa.Weight *= 10
469+
if et.nodeTopologyZone != "" && address.Zone != nil {
470+
if *address.Zone == et.nodeTopologyZone {
471+
wa.MetricLabels["zone_locality"] = "local"
472+
473+
if et.extEndpointZoneWeights {
474+
// EXPERIMENTAL: Use the endpoint weight field to indicate zonal
475+
// preference so that local endoints are more heavily weighted.
476+
wa.Weight *= 10
477+
}
478+
} else {
479+
wa.MetricLabels["zone_locality"] = "remote"
473480
}
481+
} else {
482+
wa.MetricLabels["zone_locality"] = "unknown"
474483
}
475484

476485
addrs = append(addrs, wa)

controller/api/destination/endpoint_translator_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ func TestEndpointTranslatorForPods(t *testing.T) {
485485
"serviceaccount": "serviceaccount-name",
486486
"control_plane_ns": "linkerd",
487487
"zone": "",
488+
"zone_locality": "unknown",
488489
}
489490
if diff := deep.Equal(actualAddedAddress1MetricLabels, expectedAddedAddress1MetricLabels); diff != nil {
490491
t.Fatalf("Expected global metric labels sent to be [%v] but was [%v]", expectedAddedAddress1MetricLabels, actualAddedAddress1MetricLabels)
@@ -658,6 +659,7 @@ func TestEndpointTranslatorExternalWorkloads(t *testing.T) {
658659
expectedAddedAddress1MetricLabels := map[string]string{
659660
"external_workload": "ew-1",
660661
"zone": "",
662+
"zone_locality": "unknown",
661663
"workloadgroup": "wg-name",
662664
}
663665
if diff := deep.Equal(actualAddedAddress1MetricLabels, expectedAddedAddress1MetricLabels); diff != nil {

0 commit comments

Comments
 (0)