Skip to content

Commit

Permalink
design/impl: control plane metrics monitoring
Browse files Browse the repository at this point in the history
Signed-off-by: bitliu <[email protected]>
  • Loading branch information
Xunzhuo committed Oct 16, 2023
1 parent 8e8b072 commit e7a15d1
Show file tree
Hide file tree
Showing 49 changed files with 2,626 additions and 176 deletions.
59 changes: 54 additions & 5 deletions api/v1alpha1/envoygateway_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ func DefaultEnvoyGateway() *EnvoyGateway {
APIVersion: GroupVersion.String(),
},
EnvoyGatewaySpec{
Gateway: DefaultGateway(),
Provider: DefaultEnvoyGatewayProvider(),
Logging: DefaultEnvoyGatewayLogging(),
Admin: DefaultEnvoyGatewayAdmin(),
Debug: DefaultEnvoyGatewayDebug(),
Gateway: DefaultGateway(),
Provider: DefaultEnvoyGatewayProvider(),
Logging: DefaultEnvoyGatewayLogging(),
Admin: DefaultEnvoyGatewayAdmin(),
Debug: DefaultEnvoyGatewayDebug(),
Telemetry: DefaultEnvoyGatewayTelemetry(),
},
}
}
Expand Down Expand Up @@ -51,6 +52,9 @@ func (e *EnvoyGateway) SetEnvoyGatewayDefaults() {
if e.Debug == nil {
e.Debug = DefaultEnvoyGatewayDebug()
}
if e.Telemetry == nil {
e.Telemetry = DefaultEnvoyGatewayTelemetry()
}
}

// GetEnvoyGatewayAdmin returns the EnvoyGatewayAdmin of EnvoyGateway or a default EnvoyGatewayAdmin if unspecified.
Expand Down Expand Up @@ -112,6 +116,51 @@ func DefaultEnvoyGatewayLogging() *EnvoyGatewayLogging {
}
}

// GetEnvoyGatewayAdmin returns the EnvoyGatewayAdmin of EnvoyGateway or a default EnvoyGatewayAdmin if unspecified.
func (e *EnvoyGateway) GetEnvoyGatewayTelemetry() *EnvoyGatewayTelemetry {
if e.Telemetry != nil {
if e.Telemetry.Metrics.Prometheus == nil {
e.Telemetry.Metrics.Prometheus = DefaultEnvoyGatewayPrometheus()
}
if e.Telemetry.Metrics == nil {
e.Telemetry.Metrics = DefaultEnvoyGatewayMetrics()
}
return e.Telemetry
}
e.Telemetry = DefaultEnvoyGatewayTelemetry()

return e.Telemetry
}

func (e *EnvoyGateway) IfEnablePrometheus() bool {
return e.GetEnvoyGatewayTelemetry().Metrics.Prometheus.Enable
}

// DefaultEnvoyGatewayTelemetry returns a new EnvoyGatewayTelemetry with default configuration parameters.
func DefaultEnvoyGatewayTelemetry() *EnvoyGatewayTelemetry {
return &EnvoyGatewayTelemetry{
Metrics: DefaultEnvoyGatewayMetrics(),
}
}

// DefaultEnvoyGatewayMetrics returns a new EnvoyGatewayMetrics with default configuration parameters.
func DefaultEnvoyGatewayMetrics() *EnvoyGatewayMetrics {
return &EnvoyGatewayMetrics{
// Enable prometheus pull by default.
Prometheus: &EnvoyGatewayPrometheusProvider{
Enable: true,
},
}
}

// DefaultEnvoyGatewayPrometheus returns a new EnvoyGatewayMetrics with default configuration parameters.
func DefaultEnvoyGatewayPrometheus() *EnvoyGatewayPrometheusProvider {
return &EnvoyGatewayPrometheusProvider{
// Enable prometheus pull by default.
Enable: true,
}
}

// DefaultEnvoyGatewayProvider returns a new EnvoyGatewayProvider with default configuration parameters.
func DefaultEnvoyGatewayProvider() *EnvoyGatewayProvider {
return &EnvoyGatewayProvider{
Expand Down
44 changes: 44 additions & 0 deletions api/v1alpha1/envoygateway_metric_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package v1alpha1

// EnvoyGatewayMetrics defines control plane push/pull metrics configurations.
type EnvoyGatewayMetrics struct {
// Sinks defines the metric sinks where metrics are sent to.
Sinks []EnvoyGatewayMetricSink `json:"sinks,omitempty"`
// Prometheus defines the configuration for prometheus endpoint.
Prometheus *EnvoyGatewayPrometheusProvider `json:"prometheus,omitempty"`
}

// EnvoyGatewayMetricSink defines control plane
// metric sinks where metrics are sent to.
type EnvoyGatewayMetricSink struct {
// Type defines the metric sink type.
// EG control plane currently supports OpenTelemetry.
// +kubebuilder:validation:Enum=OpenTelemetry
// +kubebuilder:default=OpenTelemetry
Type MetricSinkType `json:"type"`
// Host define the sink service hostname.
Host string `json:"host"`
// Protocol define the sink service protocol.
// +kubebuilder:validation:Enum=grpc;http
Protocol string `json:"protocol"`
// Port defines the port the sink service is exposed on.
//
// +optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=4317
Port int32 `json:"port,omitempty"`
}

// EnvoyGatewayPrometheusProvider will expose prometheus endpoint in pull mode.
type EnvoyGatewayPrometheusProvider struct {
// Enable defines if enables the prometheus metrics in pull mode. Default is true.
//
// +optional
// +kubebuilder:default=true
Enable bool `json:"enable,omitempty"`
}
13 changes: 13 additions & 0 deletions api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ type EnvoyGatewaySpec struct {
// +optional
Debug *EnvoyGatewayDebug `json:"debug,omitempty"`

// Telemetry defines the desired control plane telemetry related abilities.
// If unspecified, the telemetry is used with default configuration.
//
// +optional
Telemetry *EnvoyGatewayTelemetry `json:"telemetry,omitempty"`

// RateLimit defines the configuration associated with the Rate Limit service
// deployed by Envoy Gateway required to implement the Global Rate limiting
// functionality. The specific rate limit service used here is the reference
Expand All @@ -90,6 +96,13 @@ type EnvoyGatewaySpec struct {
ExtensionAPIs *ExtensionAPISettings `json:"extensionApis,omitempty"`
}

// EnvoyGatewayTelemetry defines telemetry configurations for envoy gateway control plane.
// Control plane will focus on metrics observability telemetry and tracing telemetry later.
type EnvoyGatewayTelemetry struct {
// Metrics defines metrics configuration for envoy gateway.
Metrics *EnvoyGatewayMetrics `json:"metrics,omitempty"`
}

// EnvoyGatewayLogging defines logging for Envoy Gateway.
type EnvoyGatewayLogging struct {
// Level is the logging level. If unspecified, defaults to "info".
Expand Down
16 changes: 8 additions & 8 deletions api/v1alpha1/metric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

package v1alpha1

type MetricSinkType string

const (
MetricSinkTypeOpenTelemetry MetricSinkType = "OpenTelemetry"
)

type ProxyMetrics struct {
// Prometheus defines the configuration for Admin endpoint `/stats/prometheus`.
Prometheus *PrometheusProvider `json:"prometheus,omitempty"`
Prometheus *ProxyPrometheusProvider `json:"prometheus,omitempty"`
// Sinks defines the metric sinks where metrics are sent to.
Sinks []MetricSink `json:"sinks,omitempty"`
// Matches defines configuration for selecting specific metrics instead of generating all metrics stats
Expand All @@ -23,12 +29,6 @@ type ProxyMetrics struct {
EnableVirtualHostStats bool `json:"enableVirtualHostStats,omitempty"`
}

type MetricSinkType string

const (
MetricSinkTypeOpenTelemetry MetricSinkType = "OpenTelemetry"
)

type MetricSink struct {
// Type defines the metric sink type.
// EG currently only supports OpenTelemetry.
Expand Down Expand Up @@ -71,5 +71,5 @@ type OpenTelemetrySink struct {
// TODO: add support for customizing OpenTelemetry sink in https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/stat_sinks/open_telemetry/v3/open_telemetry.proto#envoy-v3-api-msg-extensions-stat-sinks-open-telemetry-v3-sinkconfig
}

type PrometheusProvider struct {
type ProxyPrometheusProvider struct {
}
3 changes: 1 addition & 2 deletions api/v1alpha1/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ func validateBootstrap(boostrapConfig *egv1a1.ProxyBootstrap) error {
}
}

// nolint // Circumvents this error "Error: copylocks: call of reflect.DeepEqual copies lock value:"
if userXdsCluster == nil || !reflect.DeepEqual(*userXdsCluster.LoadAssignment, *defaultXdsCluster.LoadAssignment) {
if userXdsCluster == nil || !reflect.DeepEqual(userXdsCluster.LoadAssignment, defaultXdsCluster.LoadAssignment) {
return fmt.Errorf("xds_cluster's loadAssigntment cannot be modified")
}

Expand Down
48 changes: 48 additions & 0 deletions api/v1alpha1/validation/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,54 @@ func TestEnvoyGatewayDebug(t *testing.T) {
assert.True(t, eg.Debug.Address != nil)
}

func TestEnvoyGatewayTelemetry(t *testing.T) {
// default envoygateway config telemetry should not be nil
eg := egv1a1.DefaultEnvoyGateway()
assert.True(t, eg.Telemetry != nil)

// get default telemetry config from envoygateway
// values should be set in default
egTelemetry := eg.GetEnvoyGatewayTelemetry()
assert.True(t, egTelemetry != nil)
assert.True(t, egTelemetry.Metrics != nil)
assert.True(t, egTelemetry.Metrics.Prometheus.Enable == true)
assert.True(t, egTelemetry.Metrics.Sinks == nil)

// override the telemetry config
// values should be updated
eg.Telemetry.Metrics = &egv1a1.EnvoyGatewayMetrics{
Prometheus: &egv1a1.EnvoyGatewayPrometheusProvider{
Enable: false,
},
Sinks: []egv1a1.EnvoyGatewayMetricSink{
{
Type: egv1a1.MetricSinkTypeOpenTelemetry,
Host: "otel-collector.monitoring.svc.cluster.local",
Protocol: "grpc",
Port: 4317,
}, {
Type: egv1a1.MetricSinkTypeOpenTelemetry,
Host: "otel-collector.monitoring.svc.cluster.local",
Protocol: "http",
Port: 4318,
},
},
}

assert.True(t, eg.GetEnvoyGatewayTelemetry().Metrics.Prometheus.Enable == false)
assert.True(t, len(eg.GetEnvoyGatewayTelemetry().Metrics.Sinks) == 2)
assert.True(t, eg.GetEnvoyGatewayTelemetry().Metrics.Sinks[0].Type == egv1a1.MetricSinkTypeOpenTelemetry)

// set eg defaults when telemetry is nil
// the telemetry should not be nil
eg.Telemetry = nil
eg.SetEnvoyGatewayDefaults()
assert.True(t, eg.Telemetry != nil)
assert.True(t, eg.Telemetry.Metrics != nil)
assert.True(t, eg.Telemetry.Metrics.Prometheus.Enable == true)
assert.True(t, eg.Telemetry.Metrics.Sinks == nil)
}

func TestGetEnvoyProxyDefaultComponentLevel(t *testing.T) {
cases := []struct {
logging egv1a1.ProxyLogging
Expand Down
Loading

0 comments on commit e7a15d1

Please sign in to comment.