Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
feat(metrics): Add "unknown" for dest labels on local replies
Browse files Browse the repository at this point in the history
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 <johuhn@microsoft.com>
  • Loading branch information
nojnhuh committed Feb 22, 2021
1 parent 1583cf1 commit f9c7dd0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/envoy/lds/connection_manager.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/envoy/lds/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f9c7dd0

Please sign in to comment.