Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable admin route for stats/prometheus #6503

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/6503-clayton-gonsalves-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allow `/stats/prometheus` route on the `admin` listener.
10 changes: 7 additions & 3 deletions internal/envoy/v3/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func StatsListeners(metrics contour_v1alpha1.MetricsConfig, health contour_v1alp
SocketOptions: NewSocketOptions().TCPKeepalive().Build(),
FilterChains: filterChain("stats",
DownstreamTLSTransportSocket(
downstreamTLSContext(metrics.TLS.CAFile != "")), routeForAdminInterface("/stats")),
downstreamTLSContext(metrics.TLS.CAFile != "")), routeForAdminInterface("/stats", "/stats/prometheus")),
}, {
Name: "health",
Address: SocketAddress(health.Address, health.Port),
Expand All @@ -65,7 +65,11 @@ func StatsListeners(metrics contour_v1alpha1.MetricsConfig, health contour_v1alp
Name: "stats-health",
Address: SocketAddress(metrics.Address, metrics.Port),
SocketOptions: NewSocketOptions().TCPKeepalive().Build(),
FilterChains: filterChain("stats", nil, routeForAdminInterface("/ready", "/stats")),
FilterChains: filterChain("stats", nil, routeForAdminInterface(
"/ready",
"/stats",
"/stats/prometheus",
)),
}}

// Create separate HTTP listeners for metrics and health.
Expand All @@ -74,7 +78,7 @@ func StatsListeners(metrics contour_v1alpha1.MetricsConfig, health contour_v1alp
Name: "stats",
Address: SocketAddress(metrics.Address, metrics.Port),
SocketOptions: NewSocketOptions().TCPKeepalive().Build(),
FilterChains: filterChain("stats", nil, routeForAdminInterface("/stats")),
FilterChains: filterChain("stats", nil, routeForAdminInterface("/stats", "/stats/prometheus")),
}, {
Name: "health",
Address: SocketAddress(health.Address, health.Port),
Expand Down
36 changes: 32 additions & 4 deletions internal/envoy/v3/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,34 @@ func TestStatsListeners(t *testing.T) {
},
}

prometheusStatsRoute := &envoy_config_route_v3.Route{
Match: &envoy_config_route_v3.RouteMatch{
PathSpecifier: &envoy_config_route_v3.RouteMatch_Path{
Path: "/stats/prometheus",
},
Headers: []*envoy_config_route_v3.HeaderMatcher{
{
Name: ":method",
HeaderMatchSpecifier: &envoy_config_route_v3.HeaderMatcher_StringMatch{
StringMatch: &envoy_matcher_v3.StringMatcher{
IgnoreCase: true,
MatchPattern: &envoy_matcher_v3.StringMatcher_Exact{
Exact: "GET",
},
},
},
},
},
},
Action: &envoy_config_route_v3.Route_Route{
Route: &envoy_config_route_v3.RouteAction{
ClusterSpecifier: &envoy_config_route_v3.RouteAction_Cluster{
Cluster: "envoy-admin",
},
},
},
}

type testcase struct {
metrics contour_v1alpha1.MetricsConfig
health contour_v1alpha1.HealthConfig
Expand Down Expand Up @@ -119,7 +147,7 @@ func TestStatsListeners(t *testing.T) {
VirtualHosts: []*envoy_config_route_v3.VirtualHost{{
Name: "backend",
Domains: []string{"*"},
Routes: []*envoy_config_route_v3.Route{readyRoute, statsRoute},
Routes: []*envoy_config_route_v3.Route{readyRoute, statsRoute, prometheusStatsRoute},
}},
},
},
Expand Down Expand Up @@ -165,7 +193,7 @@ func TestStatsListeners(t *testing.T) {
VirtualHosts: []*envoy_config_route_v3.VirtualHost{{
Name: "backend",
Domains: []string{"*"},
Routes: []*envoy_config_route_v3.Route{statsRoute},
Routes: []*envoy_config_route_v3.Route{statsRoute, prometheusStatsRoute},
}},
},
},
Expand Down Expand Up @@ -256,7 +284,7 @@ func TestStatsListeners(t *testing.T) {
VirtualHosts: []*envoy_config_route_v3.VirtualHost{{
Name: "backend",
Domains: []string{"*"},
Routes: []*envoy_config_route_v3.Route{statsRoute},
Routes: []*envoy_config_route_v3.Route{statsRoute, prometheusStatsRoute},
}},
},
},
Expand Down Expand Up @@ -349,7 +377,7 @@ func TestStatsListeners(t *testing.T) {
VirtualHosts: []*envoy_config_route_v3.VirtualHost{{
Name: "backend",
Domains: []string{"*"},
Routes: []*envoy_config_route_v3.Route{statsRoute},
Routes: []*envoy_config_route_v3.Route{statsRoute, prometheusStatsRoute},
}},
},
},
Expand Down