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

Add envoy stat_prefix support for httpproxy #5535

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 4 additions & 0 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ type EnvoyConfig struct {
// Network holds various configurable Envoy network values.
// +optional
Network *NetworkParameters `json:"network,omitempty"`

// Set StatPrefix on envoy routes
// +optional
EnableStatPrefix *bool `json:"enableStatPrefix"`
}

// DebugConfig contains Contour specific troubleshooting options.
Expand Down
5 changes: 5 additions & 0 deletions apis/projectcontour/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions changelogs/unreleased/5535-therealak12-small.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds `stat_prefix` support. if `envoy.enableStatPrefix` configuration is true, contour will automatically set `stat_prefix` on each route.
6 changes: 6 additions & 0 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -565,6 +566,7 @@
MaximumProtocolVersion: annotation.TLSVersion(contourConfiguration.Envoy.Cluster.UpstreamTLS.MaximumProtocolVersion, "1.3"),
CipherSuites: contourConfiguration.Envoy.Cluster.UpstreamTLS.SanitizedCipherSuites(),
},
enableStatPrefix: *contourConfiguration.Envoy.EnableStatPrefix,

Check warning on line 569 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L569

Added line #L569 was not covered by tests
})

// Build the core Kubernetes event handler.
Expand Down Expand Up @@ -1123,6 +1125,7 @@
perConnectionBufferLimitBytes *uint32
globalRateLimitService *contour_api_v1alpha1.RateLimitServiceConfig
upstreamTLS *dag.UpstreamTLS
enableStatPrefix bool
}

func (s *Server) getDAGBuilder(dbc dagBuilderConfig) *dag.Builder {
Expand Down Expand Up @@ -1194,6 +1197,7 @@
PerConnectionBufferLimitBytes: dbc.perConnectionBufferLimitBytes,
SetSourceMetadataOnRoutes: true,
UpstreamTLS: dbc.upstreamTLS,
EnableStatPrefix: dbc.enableStatPrefix,
},
&dag.ExtensionServiceProcessor{
// Note that ExtensionService does not support ExternalName, if it does get added,
Expand All @@ -1218,6 +1222,7 @@
PerConnectionBufferLimitBytes: dbc.perConnectionBufferLimitBytes,
SetSourceMetadataOnRoutes: true,
UpstreamTLS: dbc.upstreamTLS,
EnableStatPrefix: dbc.enableStatPrefix,
},
}

Expand All @@ -1229,6 +1234,7 @@
MaxRequestsPerConnection: dbc.maxRequestsPerConnection,
PerConnectionBufferLimitBytes: dbc.perConnectionBufferLimitBytes,
SetSourceMetadataOnRoutes: true,
EnableStatPrefix: dbc.enableStatPrefix,

Check warning on line 1237 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L1237

Added line #L1237 was not covered by tests
})
}

Expand Down
1 change: 1 addition & 0 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_api_v1alpha
Port: ctx.healthPort,
},
Envoy: &contour_api_v1alpha1.EnvoyConfig{
EnableStatPrefix: &ctx.Config.EnvoyEnableStatPrefix,
Listener: &contour_api_v1alpha1.EnvoyListenerConfig{
UseProxyProto: &ctx.useProxyProto,
DisableAllowChunkedLength: &ctx.Config.DisableAllowChunkedLength,
Expand Down
1 change: 1 addition & 0 deletions cmd/contour/servecontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ func TestConvertServeContext(t *testing.T) {
Name: "envoy",
Namespace: "projectcontour",
},
EnableStatPrefix: ref.To(false),
Listener: &contour_api_v1alpha1.EnvoyListenerConfig{
UseProxyProto: ref.To(false),
DisableAllowChunkedLength: ref.To(false),
Expand Down
6 changes: 6 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ spec:
version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down Expand Up @@ -3778,6 +3781,9 @@ spec:
HTTP version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down
6 changes: 6 additions & 0 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ spec:
version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down Expand Up @@ -3997,6 +4000,9 @@ spec:
HTTP version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down
6 changes: 6 additions & 0 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ spec:
version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down Expand Up @@ -3789,6 +3792,9 @@ spec:
HTTP version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down
6 changes: 6 additions & 0 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ spec:
version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down Expand Up @@ -4000,6 +4003,9 @@ spec:
HTTP version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down
6 changes: 6 additions & 0 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ spec:
version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down Expand Up @@ -3997,6 +4000,9 @@ spec:
HTTP version.
type: string
type: array
enableStatPrefix:
description: Set StatPrefix on envoy routes
type: boolean
health:
description: "Health defines the endpoint Envoy uses to serve
health checks. \n Contour's default is { address: \"0.0.0.0\",
Expand Down
2 changes: 2 additions & 0 deletions internal/contourconfig/contourconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"dario.cat/mergo"

contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/ref"
"github.com/projectcontour/contour/internal/timeout"
Expand Down Expand Up @@ -130,6 +131,7 @@ func Defaults() contour_api_v1alpha1.ContourConfigurationSpec {
XffNumTrustedHops: ref.To(uint32(0)),
EnvoyAdminPort: ref.To(9001),
},
EnableStatPrefix: ref.To(false),
},
Gateway: nil,
HTTPProxy: &contour_api_v1alpha1.HTTPProxyConfig{
Expand Down
6 changes: 4 additions & 2 deletions internal/contourconfig/contourconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/contourconfig"
"github.com/projectcontour/contour/internal/ref"
"github.com/projectcontour/contour/internal/timeout"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestOverlayOnDefaults(t *testing.T) {
Expand Down Expand Up @@ -133,6 +134,7 @@ func TestOverlayOnDefaults(t *testing.T) {
XffNumTrustedHops: ref.To(uint32(77)),
EnvoyAdminPort: ref.To(9997),
},
EnableStatPrefix: ref.To(false),
},
Gateway: &contour_api_v1alpha1.GatewayConfig{
ControllerName: "gatewaycontroller",
Expand Down
8 changes: 6 additions & 2 deletions internal/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
"strings"
"time"

"github.com/projectcontour/contour/internal/status"
"github.com/projectcontour/contour/internal/timeout"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/projectcontour/contour/internal/status"
"github.com/projectcontour/contour/internal/timeout"
)

// Observer is an interface for receiving notification of DAG updates.
Expand Down Expand Up @@ -373,6 +374,9 @@ type Route struct {
Kind string
Namespace string
Name string

// The stat_prefix to set on envoy route
StatPrefix *string
}

// HasPathPrefix returns whether this route has a PrefixPathCondition.
Expand Down
11 changes: 11 additions & 0 deletions internal/dag/gatewayapi_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
// configurable and off by default in order to support the feature
// without requiring all existing test cases to change.
SetSourceMetadataOnRoutes bool

// Whether to set StatPrefix on envoy routes or not
EnableStatPrefix bool
}

// matchConditions holds match rules.
Expand Down Expand Up @@ -2175,6 +2178,10 @@
route.Name = name
}

if p.EnableStatPrefix {
route.StatPrefix = ref.To(fmt.Sprintf("%s_%s", namespace, name))
}

Check warning on line 2183 in internal/dag/gatewayapi_processor.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/gatewayapi_processor.go#L2182-L2183

Added lines #L2182 - L2183 were not covered by tests

routes = append(routes, route)
}

Expand Down Expand Up @@ -2243,6 +2250,10 @@
route.Name = name
}

if p.EnableStatPrefix {
route.StatPrefix = ref.To(fmt.Sprintf("%s_%s", namespace, name))
}

Check warning on line 2255 in internal/dag/gatewayapi_processor.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/gatewayapi_processor.go#L2254-L2255

Added lines #L2254 - L2255 were not covered by tests

routes = append(routes, route)
}

Expand Down
17 changes: 15 additions & 2 deletions internal/dag/httpproxy_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
"strings"
"time"

"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"

contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/annotation"
"github.com/projectcontour/contour/internal/k8s"
"github.com/projectcontour/contour/internal/ref"
"github.com/projectcontour/contour/internal/status"
"github.com/projectcontour/contour/internal/timeout"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
)

// defaultMaxRequestBytes specifies default value maxRequestBytes for AuthorizationServer
Expand Down Expand Up @@ -116,6 +118,9 @@
// UpstreamTLS defines the TLS settings like min/max version
// and cipher suites for upstream connections.
UpstreamTLS *UpstreamTLS

// Whether to set StatPrefix on envoy routes or not
EnableStatPrefix bool
}

// Run translates HTTPProxies into DAG objects and
Expand Down Expand Up @@ -638,6 +643,10 @@
route.Name = proxy.Name
}

if p.EnableStatPrefix {
route.StatPrefix = ref.To(fmt.Sprintf("%s_%s", proxy.Namespace, proxy.Name))
}

Check warning on line 648 in internal/dag/httpproxy_processor.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/httpproxy_processor.go#L647-L648

Added lines #L647 - L648 were not covered by tests

routes = append(routes, route)
}
return routes
Expand Down Expand Up @@ -843,6 +852,10 @@
r.Name = proxy.Name
}

if p.EnableStatPrefix {
r.StatPrefix = ref.To(fmt.Sprintf("%s_%s", proxy.Namespace, proxy.Name))
}

Check warning on line 857 in internal/dag/httpproxy_processor.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/httpproxy_processor.go#L856-L857

Added lines #L856 - L857 were not covered by tests

// If the enclosing root proxy enabled authorization,
// enable it on the route and propagate defaults
// downwards.
Expand Down
15 changes: 12 additions & 3 deletions internal/dag/ingress_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
package dag

import (
"fmt"
"strconv"
"strings"
"time"

"k8s.io/apimachinery/pkg/util/intstr"

"github.com/projectcontour/contour/internal/annotation"
"github.com/projectcontour/contour/internal/k8s"
"github.com/projectcontour/contour/internal/ref"
"github.com/sirupsen/logrus"
networking_v1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/projectcontour/contour/internal/annotation"
"github.com/projectcontour/contour/internal/k8s"
"github.com/projectcontour/contour/internal/ref"
)

// IngressProcessor translates Ingresses into DAG
Expand Down Expand Up @@ -69,6 +71,9 @@
// UpstreamTLS defines the TLS settings like min/max version
// and cipher suites for upstream connections.
UpstreamTLS *UpstreamTLS

// Whether to set StatPrefix on envoy routes or not
EnableStatPrefix bool
}

// Run translates Ingresses into DAG objects and
Expand Down Expand Up @@ -308,6 +313,10 @@
r.Name = ingress.Name
}

if p.EnableStatPrefix {
r.StatPrefix = ref.To(fmt.Sprintf("%s_%s", ingress.Namespace, ingress.Name))
}

Check warning on line 318 in internal/dag/ingress_processor.go

View check run for this annotation

Codecov / codecov/patch

internal/dag/ingress_processor.go#L317-L318

Added lines #L317 - L318 were not covered by tests

switch pathType {
case networking_v1.PathTypePrefix:
prefixMatchType := PrefixMatchSegment
Expand Down
Loading
Loading