Skip to content
Open
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
5 changes: 5 additions & 0 deletions api/v1alpha1/envoyproxy_metric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ type ProxyOpenTelemetrySink struct {
//
// +optional
ReportHistogramsAsDeltas *bool `json:"reportHistogramsAsDeltas,omitempty"`
// Prefix configures the OpenTelemetry sink to prepend the given prefix to emitted stat names,
// the full stat name will be `<prefix>.<stat_name>`.
//
// +optional
Prefix *string `json:"prefix,omitempty"`
Comment thread
gray-oni marked this conversation as resolved.
// Headers is a list of additional headers to send with OTLP export requests.
// These headers are added as gRPC initial metadata for the OTLP gRPC service.
// +optional
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -17085,6 +17085,11 @@ spec:
maximum: 65535
minimum: 0
type: integer
prefix:
description: |-
Prefix configures the OpenTelemetry sink to prepend the given prefix to emitted stat names,
the full stat name will be `<prefix>.<stat_name>`.
type: string
reportCountersAsDeltas:
description: |-
ReportCountersAsDeltas configures the OpenTelemetry sink to report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17084,6 +17084,11 @@ spec:
maximum: 65535
minimum: 0
type: integer
prefix:
description: |-
Prefix configures the OpenTelemetry sink to prepend the given prefix to emitted stat names,
the full stat name will be `<prefix>.<stat_name>`.
type: string
reportCountersAsDeltas:
description: |-
ReportCountersAsDeltas configures the OpenTelemetry sink to report
Expand Down
1 change: 1 addition & 0 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@ func (t *Translator) processMetrics(gwCtx *GatewayContext, envoyproxy *egv1a1.En
ResourceAttributes: sink.OpenTelemetry.ResourceAttributes,
ReportCountersAsDeltas: ptr.Deref(sink.OpenTelemetry.ReportCountersAsDeltas, false),
ReportHistogramsAsDeltas: ptr.Deref(sink.OpenTelemetry.ReportHistogramsAsDeltas, false),
Prefix: ptr.Deref(sink.OpenTelemetry.Prefix, ""),
})
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/infrastructure/common/proxy_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func ConvertResolvedMetricSinks(irSinks []ir.ResolvedMetricSink) []bootstrap.Met
Authority: sink.Authority,
ReportCountersAsDeltas: sink.ReportCountersAsDeltas,
ReportHistogramsAsDeltas: sink.ReportHistogramsAsDeltas,
Prefix: sink.Prefix,
Headers: sink.Headers,
ResourceAttributes: sink.ResourceAttributes,
}
Expand Down
25 changes: 25 additions & 0 deletions internal/infrastructure/common/proxy_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,31 @@ func TestResolvedMetricSinksConversion(t *testing.T) {
},
},
},
{
name: "sink with prefix",
irSinks: []ir.ResolvedMetricSink{
{
Destination: ir.RouteDestination{
Name: "metrics_otel_0",
Settings: []*ir.DestinationSetting{
{
Endpoints: []*ir.DestinationEndpoint{
{Host: "otel-collector.example.com", Port: 4317},
},
},
},
},
Prefix: "envoy",
},
},
expected: []bootstrap.MetricSink{
{
Address: "otel-collector.example.com",
Port: 4317,
Prefix: "envoy",
},
},
},
{
name: "sink with resources",
irSinks: []ir.ResolvedMetricSink{
Expand Down
4 changes: 3 additions & 1 deletion internal/infrastructure/remote/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func proxyListenerToProto(l *ir.ProxyListener) *remoteinfra.ProxyListener {

// resolvedMetricSinkToProto translates every field of ir.ResolvedMetricSink
// (Authority, Headers, ResourceAttributes, ReportCountersAsDeltas,
// ReportHistogramsAsDeltas). Only its Destination is narrowed to a subset; see
// ReportHistogramsAsDeltas, Prefix). Only its Destination is narrowed to a subset; see
// routeDestinationToProto.
func resolvedMetricSinkToProto(s *ir.ResolvedMetricSink) *remoteinfra.ResolvedMetricSink {
out := &remoteinfra.ResolvedMetricSink{
Expand All @@ -149,6 +149,7 @@ func resolvedMetricSinkToProto(s *ir.ResolvedMetricSink) *remoteinfra.ResolvedMe
ResourceAttributes: s.ResourceAttributes,
ReportCountersAsDeltas: s.ReportCountersAsDeltas,
ReportHistogramsAsDeltas: s.ReportHistogramsAsDeltas,
Prefix: s.Prefix,
}

for _, h := range s.Headers {
Expand Down Expand Up @@ -376,6 +377,7 @@ func protoToResolvedMetricSink(s *remoteinfra.ResolvedMetricSink) ir.ResolvedMet
ResourceAttributes: s.GetResourceAttributes(),
ReportCountersAsDeltas: s.GetReportCountersAsDeltas(),
ReportHistogramsAsDeltas: s.GetReportHistogramsAsDeltas(),
Prefix: s.GetPrefix(),
}

if s.GetDestination() != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/infrastructure/remote/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func fullyPopulatedInfra() *ir.Infra {
ResourceAttributes: map[string]string{"service.name": "eg"},
ReportCountersAsDeltas: true,
ReportHistogramsAsDeltas: true,
Prefix: "envoy",
Headers: []gwapiv1.HTTPHeader{
{Name: "x-header", Value: "header-value"},
},
Expand Down
2 changes: 2 additions & 0 deletions internal/ir/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type ResolvedMetricSink struct {
ReportCountersAsDeltas bool `json:"reportCountersAsDeltas,omitempty" yaml:"reportCountersAsDeltas,omitempty"`
// ReportHistogramsAsDeltas configures histograms to use delta temporality.
ReportHistogramsAsDeltas bool `json:"reportHistogramsAsDeltas,omitempty" yaml:"reportHistogramsAsDeltas,omitempty"`
// Prefix is prepended to emitted stat names, the full stat name will be `<prefix>.<stat_name>`.
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
}

// InfraMetadata defines metadata for the managed proxy infrastructure.
Expand Down
4 changes: 4 additions & 0 deletions internal/xds/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ type MetricSink struct {
ReportCountersAsDeltas bool
// ReportHistogramsAsDeltas configures histograms to use delta temporality.
ReportHistogramsAsDeltas bool
// Prefix is prepended to emitted stat names, the full stat name will be `<prefix>.<stat_name>`.
// If empty, no prefix is added.
Prefix string
// Headers is a list of headers to send with OTLP export requests.
Headers []gwapiv1.HTTPHeader
// ResourceAttributes is a map of resource attributes for the metrics sink.
Expand Down Expand Up @@ -269,6 +272,7 @@ func GetRenderedBootstrapConfig(opts *RenderBootstrapConfigOptions) (string, err
Port: port,
ReportCountersAsDeltas: ptr.Deref(sink.OpenTelemetry.ReportCountersAsDeltas, false),
ReportHistogramsAsDeltas: ptr.Deref(sink.OpenTelemetry.ReportHistogramsAsDeltas, false),
Prefix: ptr.Deref(sink.OpenTelemetry.Prefix, ""),
Headers: sink.OpenTelemetry.Headers,
})
}
Expand Down
3 changes: 3 additions & 0 deletions internal/xds/bootstrap/bootstrap.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ stats_sinks:
{{- if $sink.ReportHistogramsAsDeltas }}
report_histograms_as_deltas: true
{{- end }}
{{- if $sink.Prefix }}
prefix: '{{ $sink.Prefix }}'
Comment thread
gray-oni marked this conversation as resolved.
{{- end}}
{{- if $sink.ResourceAttributes }}
resource_detectors:
- name: envoy.tracers.opentelemetry.resource_detectors.static_config
Expand Down
22 changes: 22 additions & 0 deletions internal/xds/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,28 @@ func TestGetRenderedBootstrapConfig(t *testing.T) {
SdsConfig: sds,
},
},
{
name: "otel-metrics-prefix",
opts: &RenderBootstrapConfigOptions{
ProxyMetrics: &egv1a1.ProxyMetrics{
Prometheus: &egv1a1.ProxyPrometheusProvider{
Disable: true,
},
Sinks: []egv1a1.ProxyMetricSink{
{
Type: egv1a1.MetricSinkTypeOpenTelemetry,
OpenTelemetry: &egv1a1.ProxyOpenTelemetrySink{
Host: new("otel-collector.monitoring.svc"),
Port: 4317,
ReportHistogramsAsDeltas: new(true),
Prefix: new("envoy"),
},
},
},
},
SdsConfig: sds,
},
},
{
name: "otel-metrics-headers",
opts: &RenderBootstrapConfigOptions{
Expand Down
146 changes: 146 additions & 0 deletions internal/xds/bootstrap/testdata/render/otel-metrics-prefix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
admin:
access_log:
- name: envoy.access_loggers.file
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/null
address:
socket_address:
address: 127.0.0.1
port_value: 19000
cluster_manager:
local_cluster_name: local_cluster
node:
locality:
zone: $(ENVOY_SERVICE_ZONE)
deferredStatOptions:
enableDeferredCreationStats: true
stats_config:
use_all_default_tags: true
stats_tags:
- regex: \.zone(\.(([^\.]+)\.))
tag_name: from_zone
- regex: \.zone\.[^\.]+\.(([^\.]+)\.)
tag_name: to_zone
- regex: "^cluster(\\..+\\.(.+))\\.total_match_count$"
tag_name: socket_match_name
- regex: "circuit_breakers\\.((.+?)\\.).+"
tag_name: priority
layered_runtime:
layers:
- name: global_config
static_layer:
envoy.reloadable_features.oauth2_legacy_cbc_decrypt_compat: false
envoy.reloadable_features.oauth2_use_gcm_encryption: true
re2.max_program_size.error_level: 4294967295
re2.max_program_size.warn_level: 1000
dynamic_resources:
ads_config:
api_type: DELTA_GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: true
lds_config:
ads: {}
initial_fetch_timeout: 0s
resource_api_version: V3
cds_config:
ads: {}
initial_fetch_timeout: 0s
resource_api_version: V3
stats_sinks:
- name: "envoy.stat_sinks.open_telemetry"
typed_config:
"@type": type.googleapis.com/envoy.extensions.stat_sinks.open_telemetry.v3.SinkConfig
grpc_service:
envoy_grpc:
cluster_name: otel_metric_sink_0
report_histograms_as_deltas: true
prefix: 'envoy'
static_resources:
clusters:
- name: otel_metric_sink_0
connect_timeout: 0.250s
type: STRICT_DNS
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
"@type": "type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions"
explicit_http_config:
http2_protocol_options: {}
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: otel_metric_sink_0
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: otel-collector.monitoring.svc
port_value: 4317
- connect_timeout: 10s
eds_cluster_config:
eds_config:
ads: {}
resource_api_version: 'V3'
service_name: local_cluster
load_balancing_policy:
policies:
- typed_extension_config:
name: 'envoy.load_balancing_policies.least_request'
typed_config:
'@type': 'type.googleapis.com/envoy.extensions.load_balancing_policies.least_request.v3.LeastRequest'
locality_lb_config:
zone_aware_lb_config:
min_cluster_size: '1'
name: local_cluster
type: EDS
- connect_timeout: 10s
load_assignment:
cluster_name: xds_cluster
endpoints:
- load_balancing_weight: 1
lb_endpoints:
- load_balancing_weight: 1
endpoint:
address:
socket_address:
address: envoy-gateway
port_value: 18000
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
"@type": "type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions"
explicit_http_config:
http2_protocol_options:
connection_keepalive:
interval: 30s
timeout: 5s
name: xds_cluster
type: STRICT_DNS
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
tls_params:
tls_maximum_protocol_version: TLSv1_3
tls_certificate_sds_secret_configs:
- name: xds_certificate
sds_config:
path_config_source:
path: /sds/xds-certificate.json
resource_api_version: V3
validation_context_sds_secret_config:
name: xds_trusted_ca
sds_config:
path_config_source:
path: /sds/xds-trusted-ca.json
resource_api_version: V3
overload_manager:
refresh_interval: 0.25s
resource_monitors:
- name: "envoy.resource_monitors.global_downstream_max_connections"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.downstream_connections.v3.DownstreamConnectionsConfig
max_active_downstream_connections: 50000
Loading