Skip to content

Commit

Permalink
Export zone locality in outbound destination metrics (#13129)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sfleen authored Oct 15, 2024
1 parent 682db51 commit 958cfca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions controller/api/destination/endpoint_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func (et *endpointTranslator) sendClientAdd(set watcher.AddressSet) {
Addr: addr,
Weight: defaultWeight,
AuthorityOverride: authOverride,
MetricLabels: map[string]string{},
}

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

if et.extEndpointZoneWeights {
// EXPERIMENTAL: Use the endpoint weight field to indicate zonal
// preference so that local endoints are more heavily weighted.
if et.nodeTopologyZone != "" && address.Zone != nil && *address.Zone == et.nodeTopologyZone {
wa.Weight *= 10
if et.nodeTopologyZone != "" && address.Zone != nil {
if *address.Zone == et.nodeTopologyZone {
wa.MetricLabels["zone_locality"] = "local"

if et.extEndpointZoneWeights {
// EXPERIMENTAL: Use the endpoint weight field to indicate zonal
// preference so that local endoints are more heavily weighted.
wa.Weight *= 10
}
} else {
wa.MetricLabels["zone_locality"] = "remote"
}
} else {
wa.MetricLabels["zone_locality"] = "unknown"
}

addrs = append(addrs, wa)
Expand Down
2 changes: 2 additions & 0 deletions controller/api/destination/endpoint_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ func TestEndpointTranslatorForPods(t *testing.T) {
"serviceaccount": "serviceaccount-name",
"control_plane_ns": "linkerd",
"zone": "",
"zone_locality": "unknown",
}
if diff := deep.Equal(actualAddedAddress1MetricLabels, expectedAddedAddress1MetricLabels); diff != nil {
t.Fatalf("Expected global metric labels sent to be [%v] but was [%v]", expectedAddedAddress1MetricLabels, actualAddedAddress1MetricLabels)
Expand Down Expand Up @@ -658,6 +659,7 @@ func TestEndpointTranslatorExternalWorkloads(t *testing.T) {
expectedAddedAddress1MetricLabels := map[string]string{
"external_workload": "ew-1",
"zone": "",
"zone_locality": "unknown",
"workloadgroup": "wg-name",
}
if diff := deep.Equal(actualAddedAddress1MetricLabels, expectedAddedAddress1MetricLabels); diff != nil {
Expand Down

0 comments on commit 958cfca

Please sign in to comment.