Skip to content

Commit

Permalink
fix cel
Browse files Browse the repository at this point in the history
Signed-off-by: zirain <zirain2009@gmail.com>
  • Loading branch information
zirain committed Apr 2, 2024
1 parent cc9a69c commit 0fa26c5
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 52 deletions.
7 changes: 4 additions & 3 deletions api/v1alpha1/accesslogging_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ type FileEnvoyProxyAccessLog struct {

// OpenTelemetryEnvoyProxyAccessLog defines the OpenTelemetry access log sink.
//
// +kubebuilder:validation:XValidation:message="BackendRef only support Service Kind.",rule="!has(self.backendRef) || !has(self.backendRef.kind) || self.backendRef.kind == 'Service'"
// +kubebuilder:validation:XValidation:message="host or backendRef needs to be set",rule="has(self.host) || has(self.backendRef)"
// +kubebuilder:validation:XValidation:message="backendRef only support Service Kind.",rule="!has(self.backendRef) || self.backendRef.kind == 'Service'"
type OpenTelemetryEnvoyProxyAccessLog struct {
// Host define the extension service hostname.
// Deprecated: Use BackendRef instead.
//
// +kubebuilder:validation:MinLength=0
Host string `json:"host"`
// +optional
Host *string `json:"host"`
// Port defines the port the extension service is exposed on.
// Deprecated: Use BackendRef instead.
//
Expand Down
7 changes: 4 additions & 3 deletions api/v1alpha1/envoyproxy_metric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ type ProxyMetricSink struct {

// ProxyOpenTelemetrySink defines the configuration for OpenTelemetry sink.
//
// +kubebuilder:validation:XValidation:message="BackendRef only support Service Kind.",rule="!has(self.backendRef) || !has(self.backendRef.kind) || self.backendRef.kind == 'Service'"
// +kubebuilder:validation:XValidation:message="host or backendRef needs to be set",rule="has(self.host) || has(self.backendRef)"
// +kubebuilder:validation:XValidation:message="backendRef only support Service Kind.",rule="!has(self.backendRef) || self.backendRef.kind == 'Service'"
type ProxyOpenTelemetrySink struct {
// Host define the service hostname.
// Deprecated: Use BackendRef instead.
//
// +kubebuilder:validation:MinLength=0
Host string `json:"host"`
// +optional
Host *string `json:"host"`
// Port defines the port the service is exposed on.
// Deprecated: Use BackendRef instead.
//
Expand Down
7 changes: 4 additions & 3 deletions api/v1alpha1/tracing_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (

// TracingProvider defines the tracing provider configuration.
//
// +kubebuilder:validation:XValidation:message="BackendRef only support Service Kind.",rule="!has(self.backendRef) || !has(self.backendRef.kind) || self.backendRef.kind == 'Service'"
// +kubebuilder:validation:XValidation:message="host or backendRef needs to be set",rule="has(self.host) || has(self.backendRef)"
// +kubebuilder:validation:XValidation:message="backendRef only support Service Kind.",rule="!has(self.backendRef) || self.backendRef.kind == 'Service'"
type TracingProvider struct {
// Type defines the tracing provider type.
// EG currently only supports OpenTelemetry.
Expand All @@ -42,8 +43,8 @@ type TracingProvider struct {
// Host define the provider service hostname.
// Deprecated: Use BackendRef instead.
//
// +kubebuilder:validation:MinLength=0
Host string `json:"host"`
// +optional
Host *string `json:"host"`
// Port defines the port the provider service is exposed on.
// Deprecated: Use BackendRef instead.
//
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/validation/envoyproxy_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func TestValidateEnvoyProxy(t *testing.T) {
{
Type: egv1a1.MetricSinkTypeOpenTelemetry,
OpenTelemetry: &egv1a1.ProxyOpenTelemetrySink{
Host: "0.0.0.0",
Host: ptr.To("0.0.0.0"),
Port: 3217,
},
},
Expand Down
15 changes: 15 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 @@ -5982,7 +5982,6 @@ spec:
description: |-
Host define the extension service hostname.
Deprecated: Use BackendRef instead.
minLength: 0
type: string
port:
default: 4317
Expand All @@ -5999,13 +5998,13 @@ spec:
Resources is a set of labels that describe the source of a log entry, including envoy node info.
It's recommended to follow [semantic conventions](https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/).
type: object
required:
- host
type: object
x-kubernetes-validations:
- message: BackendRef only support Service Kind.
rule: '!has(self.backendRef) || !has(self.backendRef.kind)
|| self.backendRef.kind == ''Service'''
- message: host or backendRef needs to be set
rule: has(self.host) || has(self.backendRef)
- message: backendRef only support Service Kind.
rule: '!has(self.backendRef) || self.backendRef.kind
== ''Service'''
type:
description: Type defines the type of accesslog
sink.
Expand Down Expand Up @@ -6176,7 +6175,6 @@ spec:
description: |-
Host define the service hostname.
Deprecated: Use BackendRef instead.
minLength: 0
type: string
port:
default: 4317
Expand All @@ -6187,13 +6185,13 @@ spec:
maximum: 65535
minimum: 0
type: integer
required:
- host
type: object
x-kubernetes-validations:
- message: BackendRef only support Service Kind.
rule: '!has(self.backendRef) || !has(self.backendRef.kind)
|| self.backendRef.kind == ''Service'''
- message: host or backendRef needs to be set
rule: has(self.host) || has(self.backendRef)
- message: backendRef only support Service Kind.
rule: '!has(self.backendRef) || self.backendRef.kind
== ''Service'''
type:
default: OpenTelemetry
description: |-
Expand Down Expand Up @@ -6367,7 +6365,6 @@ spec:
description: |-
Host define the provider service hostname.
Deprecated: Use BackendRef instead.
minLength: 0
type: string
port:
default: 4317
Expand All @@ -6386,13 +6383,14 @@ spec:
- OpenTelemetry
type: string
required:
- host
- type
type: object
x-kubernetes-validations:
- message: BackendRef only support Service Kind.
rule: '!has(self.backendRef) || !has(self.backendRef.kind)
|| self.backendRef.kind == ''Service'''
- message: host or backendRef needs to be set
rule: has(self.host) || has(self.backendRef)
- message: backendRef only support Service Kind.
rule: '!has(self.backendRef) || self.backendRef.kind ==
''Service'''
samplingRate:
default: 100
description: |-
Expand Down
11 changes: 9 additions & 2 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,13 @@ func processAccessLog(envoyproxy *egv1a1.EnvoyProxy) *ir.AccessLog {
// TODO: remove support for Host/Port in v1.2
al := &ir.OpenTelemetryAccessLog{
Port: uint32(sink.OpenTelemetry.Port),
Host: sink.OpenTelemetry.Host,
Resources: sink.OpenTelemetry.Resources,
}

if sink.OpenTelemetry.Host != nil {
al.Host = *sink.OpenTelemetry.Host
}

if sink.OpenTelemetry.BackendRef != nil {
al.Host, al.Port = net.BackendHostAndPort(*sink.OpenTelemetry.BackendRef, envoyproxy.Namespace)
}
Expand Down Expand Up @@ -249,7 +252,11 @@ func processTracing(gw *gwapiv1.Gateway, envoyproxy *egv1a1.EnvoyProxy) *ir.Trac
tracing := envoyproxy.Spec.Telemetry.Tracing

// TODO: remove support for Host/Port in v1.2
host, port := tracing.Provider.Host, uint32(tracing.Provider.Port)
var host string
var port uint32
if tracing.Provider.Host != nil {
host, port = *tracing.Provider.Host, uint32(tracing.Provider.Port)
}
if tracing.Provider.BackendRef != nil {
host, port = net.BackendHostAndPort(*tracing.Provider.BackendRef, gw.Namespace)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/gatewayapi/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package gatewayapi

import (
"k8s.io/utils/ptr"

Check failure on line 9 in internal/gatewayapi/listener_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/envoyproxy/gateway/ (goimports)
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestProcessTracing(t *testing.T) {
Telemetry: &egcfgv1a1.ProxyTelemetry{
Tracing: &egcfgv1a1.ProxyTracing{
Provider: egcfgv1a1.TracingProvider{
Host: "fake-host",
Host: ptr.To("fake-host"),
Port: 4317,
},
},
Expand Down Expand Up @@ -85,7 +86,7 @@ func TestProcessTracing(t *testing.T) {
Telemetry: &egcfgv1a1.ProxyTelemetry{
Tracing: &egcfgv1a1.ProxyTracing{
Provider: egcfgv1a1.TracingProvider{
Host: "fake-host",
Host: ptr.To("fake-host"),
Port: 4317,
BackendRef: &gwapiv1.BackendObjectReference{
Name: "fake-name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ infraIR:
name: otel-collector
namespace: monitoring
port: 4317
host: ""
host: null
resources:
k8s.cluster.name: cluster-1
type: OpenTelemetry
Expand Down
12 changes: 8 additions & 4 deletions internal/xds/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type metricSink struct {
// Address is the address of the XDS Server that Envoy is managed by.
Address string
// Port is the port of the XDS Server that Envoy is managed by.
Port int32
Port uint32
}

type adminServerParameters struct {
Expand Down Expand Up @@ -142,7 +142,11 @@ func GetRenderedBootstrapConfig(proxyMetrics *egv1a1.ProxyMetrics) (string, erro
}

// skip duplicate sinks
host, port := sink.OpenTelemetry.Host, uint32(sink.OpenTelemetry.Port)
var host string
var port uint32
if sink.OpenTelemetry.Host == nil {
host, port = *sink.OpenTelemetry.Host, uint32(sink.OpenTelemetry.Port)
}

Check warning on line 149 in internal/xds/bootstrap/bootstrap.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/bootstrap/bootstrap.go#L148-L149

Added lines #L148 - L149 were not covered by tests
if sink.OpenTelemetry.BackendRef != nil {
host, port = net.BackendHostAndPort(*sink.OpenTelemetry.BackendRef, "")
}
Expand All @@ -153,8 +157,8 @@ func GetRenderedBootstrapConfig(proxyMetrics *egv1a1.ProxyMetrics) (string, erro
addresses.Insert(addr)

metricSinks = append(metricSinks, metricSink{
Address: sink.OpenTelemetry.Host,
Port: sink.OpenTelemetry.Port,
Address: host,
Port: port,
})
}

Expand Down
4 changes: 2 additions & 2 deletions internal/xds/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestGetRenderedBootstrapConfig(t *testing.T) {
{
Type: egv1a1.MetricSinkTypeOpenTelemetry,
OpenTelemetry: &egv1a1.ProxyOpenTelemetrySink{
Host: "otel-collector.monitoring.svc",
Host: ptr.To("otel-collector.monitoring.svc"),
Port: 4317,
},
},
Expand All @@ -65,7 +65,7 @@ func TestGetRenderedBootstrapConfig(t *testing.T) {
{
Type: egv1a1.MetricSinkTypeOpenTelemetry,
OpenTelemetry: &egv1a1.ProxyOpenTelemetrySink{
Host: "otel-collector.monitoring.svc",
Host: ptr.To("otel-collector.monitoring.svc"),
Port: 4317,
BackendRef: &gwapiv1.BackendObjectReference{
Name: "otel-collector",
Expand Down
4 changes: 2 additions & 2 deletions internal/xds/bootstrap/testdata/render/otel-metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ static_resources:
- endpoint:
address:
socket_address:
address: otel-collector.monitoring.svc
port_value: 4317
address:

Check failure on line 84 in internal/xds/bootstrap/testdata/render/otel-metrics.yaml

View workflow job for this annotation

GitHub Actions / lint

84:25 [trailing-spaces] trailing spaces

Check failure on line 84 in internal/xds/bootstrap/testdata/render/otel-metrics.yaml

View workflow job for this annotation

GitHub Actions / lint

84:25 [trailing-spaces] trailing spaces
port_value: 0
- connect_timeout: 10s
load_assignment:
cluster_name: xds_cluster
Expand Down
Loading

0 comments on commit 0fa26c5

Please sign in to comment.