From f9c7dd0665c2ba2995750067840c30b730fdba6b Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Thu, 14 Jan 2021 11:38:51 -0600 Subject: [PATCH] feat(metrics): Add "unknown" for dest labels on local replies Because `destination_*` tags are generated at the request's destination, requests that invoke a local response from Envoy have no `destination_*` values. This change modifies Envoy to add the expected header keys with the value "unknown" to stay consistent with the behavior for requests that don't invoke a local reply. Signed-off-by: Jon Huhn --- pkg/envoy/lds/connection_manager.go | 27 +++++++++++++++++++++++++++ pkg/envoy/lds/listener_test.go | 2 ++ 2 files changed, 29 insertions(+) diff --git a/pkg/envoy/lds/connection_manager.go b/pkg/envoy/lds/connection_manager.go index d09325df02..e018bc9dc0 100644 --- a/pkg/envoy/lds/connection_manager.go +++ b/pkg/envoy/lds/connection_manager.go @@ -1,6 +1,8 @@ package lds import ( + envoy_config_accesslog_v3 "github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3" + envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" xds_route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3" xds_hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3" "github.com/envoyproxy/go-control-plane/pkg/wellknown" @@ -77,6 +79,31 @@ func getHTTPConnectionManager(routeName string, cfg configurator.Configurator, h filters = append(filters, statsFilter) } connManager.HttpFilters = append(filters, connManager.HttpFilters...) + + // When Envoy responds to an outgoing HTTP request with a local reply, + // destination_* tags for WASM metrics are missing. This configures + // Envoy's local replies to add the same headers that are expected from + // HTTP responses with the "unknown" value hardcoded because we don't + // know the intended destination of the request. + var localReplyHeaders []*envoy_config_core_v3.HeaderValueOption + for k := range headers { + localReplyHeaders = append(localReplyHeaders, &envoy_config_core_v3.HeaderValueOption{ + Header: &envoy_config_core_v3.HeaderValue{ + Key: k, + Value: "unknown", + }, + }) + } + connManager.LocalReplyConfig = &xds_hcm.LocalReplyConfig{ + Mappers: []*xds_hcm.ResponseMapper{ + { + Filter: &envoy_config_accesslog_v3.AccessLogFilter{ + FilterSpecifier: &envoy_config_accesslog_v3.AccessLogFilter_NotHealthCheckFilter{}, + }, + HeadersToAdd: localReplyHeaders, + }, + }, + } } return connManager diff --git a/pkg/envoy/lds/listener_test.go b/pkg/envoy/lds/listener_test.go index 5f074473b7..08d22f1438 100644 --- a/pkg/envoy/lds/listener_test.go +++ b/pkg/envoy/lds/listener_test.go @@ -150,6 +150,8 @@ var _ = Describe("Test getHTTPConnectionManager", func() { Expect(connManager.GetHttpFilters()[2].GetName()).To(Equal(wellknown.HTTPRoleBasedAccessControl)) Expect(connManager.GetHttpFilters()[3].GetName()).To(Equal(wellknown.Router)) + Expect(connManager.GetLocalReplyConfig().GetMappers()[0].HeadersToAdd[0].Header.Value).To(Equal("unknown")) + // reset global state statsWASMBytes = oldStatsWASMBytes featureflags.Features.WASMStats = oldWASMflag