From 68424b318ab71ba1ce2b34680e0d832a95ba324c Mon Sep 17 00:00:00 2001 From: freddygv Date: Tue, 14 Dec 2021 08:39:24 -0700 Subject: [PATCH] Get partition label from upstream metrics --- command/connect/envoy/bootstrap_config.go | 20 +++++++------ .../connect/envoy/bootstrap_config_test.go | 28 +++++++++++-------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/command/connect/envoy/bootstrap_config.go b/command/connect/envoy/bootstrap_config.go index 4f16e79b03..777a02451e 100644 --- a/command/connect/envoy/bootstrap_config.go +++ b/command/connect/envoy/bootstrap_config.go @@ -403,22 +403,26 @@ func resourceTagSpecifiers(omitDeprecatedTags bool) ([]string, error) { // Upstream listener metrics are prefixed by consul.upstream // // Listener metric name format: - // .upstream... + // .upstream.... // // Examples: // - tcp.upstream.db.dc1.downstream_cx_total: 0 - // - http.upstream.web.default.dc1.downstream_cx_total: 0 + // - http.upstream.web.frontend.west.dc1.downstream_cx_total: 0 {"consul.upstream.service", - fmt.Sprintf(`^(?:tcp|http)\.upstream\.((%s)(?:\.%s)?\.%s\.)`, - reSegment, reSegment, reSegment)}, + fmt.Sprintf(`^(?:tcp|http)\.upstream\.((%s)(?:\.%s)?(?:\.%s)?\.%s\.)`, + reSegment, reSegment, reSegment, reSegment)}, {"consul.upstream.datacenter", - fmt.Sprintf(`^(?:tcp|http)\.upstream\.(%s(?:\.%s)?\.(%s)\.)`, - reSegment, reSegment, reSegment)}, + fmt.Sprintf(`^(?:tcp|http)\.upstream\.(%s(?:\.%s)?(?:\.%s)?\.(%s)\.)`, + reSegment, reSegment, reSegment, reSegment)}, {"consul.upstream.namespace", - fmt.Sprintf(`^(?:tcp|http)\.upstream\.(%s(?:\.(%s))?\.%s\.)`, - reSegment, reSegment, reSegment)}, + fmt.Sprintf(`^(?:tcp|http)\.upstream\.(%s(?:\.(%s))?(?:\.%s)?\.%s\.)`, + reSegment, reSegment, reSegment, reSegment)}, + + {"consul.upstream.partition", + fmt.Sprintf(`^(?:tcp|http)\.upstream\.(%s(?:\.%s)?(?:\.(%s))?\.%s\.)`, + reSegment, reSegment, reSegment, reSegment)}, } // These tags were deprecated in Consul 1.9.0 diff --git a/command/connect/envoy/bootstrap_config_test.go b/command/connect/envoy/bootstrap_config_test.go index 5cfb06e515..5a5e0d3dc0 100644 --- a/command/connect/envoy/bootstrap_config_test.go +++ b/command/connect/envoy/bootstrap_config_test.go @@ -1202,39 +1202,43 @@ func TestConsulTagSpecifiers(t *testing.T) { }, }, { - name: "tcp listener no namespace", + name: "tcp listener no namespace or partition (OSS)", stat: "tcp.upstream.db.dc1.downstream_cx_total", expect: map[string][]string{ "consul.upstream.datacenter": {"db.dc1.", "dc1"}, "consul.upstream.namespace": {"db.dc1.", ""}, + "consul.upstream.partition": {"db.dc1.", ""}, "consul.upstream.service": {"db.dc1.", "db"}, }, }, { - name: "tcp listener with namespace", - stat: "tcp.upstream.db.default.dc1.downstream_cx_total", + name: "tcp listener with namespace and partition", + stat: "tcp.upstream.db.frontend.west.dc1.downstream_cx_total", expect: map[string][]string{ - "consul.upstream.datacenter": {"db.default.dc1.", "dc1"}, - "consul.upstream.namespace": {"db.default.dc1.", "default"}, - "consul.upstream.service": {"db.default.dc1.", "db"}, + "consul.upstream.datacenter": {"db.frontend.west.dc1.", "dc1"}, + "consul.upstream.namespace": {"db.frontend.west.dc1.", "frontend"}, + "consul.upstream.partition": {"db.frontend.west.dc1.", "west"}, + "consul.upstream.service": {"db.frontend.west.dc1.", "db"}, }, }, { - name: "http listener no namespace", + name: "http listener no namespace or partition (OSS)", stat: "http.upstream.web.dc1.downstream_cx_total", expect: map[string][]string{ "consul.upstream.datacenter": {"web.dc1.", "dc1"}, "consul.upstream.namespace": {"web.dc1.", ""}, + "consul.upstream.partition": {"web.dc1.", ""}, "consul.upstream.service": {"web.dc1.", "web"}, }, }, { - name: "http listener with namespace", - stat: "http.upstream.web.default.dc1.downstream_cx_total", + name: "http listener with namespace and partition", + stat: "http.upstream.web.frontend.west.dc1.downstream_cx_total", expect: map[string][]string{ - "consul.upstream.datacenter": {"web.default.dc1.", "dc1"}, - "consul.upstream.namespace": {"web.default.dc1.", "default"}, - "consul.upstream.service": {"web.default.dc1.", "web"}, + "consul.upstream.datacenter": {"web.frontend.west.dc1.", "dc1"}, + "consul.upstream.namespace": {"web.frontend.west.dc1.", "frontend"}, + "consul.upstream.partition": {"web.frontend.west.dc1.", "west"}, + "consul.upstream.service": {"web.frontend.west.dc1.", "web"}, }, }, }