From 0018b846473c03be7d60e07ef3ee9ff53496af5b Mon Sep 17 00:00:00 2001 From: Bence Csati Date: Wed, 11 Dec 2024 11:42:56 +0100 Subject: [PATCH] chore: follow-up on ffe changes Signed-off-by: Bence Csati --- api/telemetry/v1alpha1/output_types.go | 54 +++++++++++-------- .../v1alpha1/zz_generated.deepcopy.go | 24 ++++++++- .../telemetry.kube-logging.dev_outputs.yaml | 20 ++++++- .../telemetry.kube-logging.dev_outputs.yaml | 20 ++++++- .../otel_conf_gen/otel_conf_gen_test.go | 4 +- .../exporter/fluent_forward_exporter_test.go | 18 +++++-- 6 files changed, 108 insertions(+), 32 deletions(-) diff --git a/api/telemetry/v1alpha1/output_types.go b/api/telemetry/v1alpha1/output_types.go index 4f8a610..ccbf052 100644 --- a/api/telemetry/v1alpha1/output_types.go +++ b/api/telemetry/v1alpha1/output_types.go @@ -99,25 +99,13 @@ type OTLPHTTP struct { HTTPClientConfig `json:",inline"` } -// Configuration for the fluentforward exporter. -type Fluentforward struct { - TCPClientSettings `json:",inline"` - - // RequireAck enables the acknowledgement feature. - RequireAck *bool `json:"require_ack,omitempty"` - - // The Fluent tag parameter used for routing - Tag *string `json:"tag,omitempty"` - - // CompressGzip enables gzip compression for the payload. - CompressGzip *bool `json:"compress_gzip,omitempty"` - - // DefaultLabelsEnabled is a map of default attributes to be added to each log record. - DefaultLabelsEnabled *map[string]bool `json:"default_labels_enabled,omitempty"` - - QueueConfig *QueueSettings `json:"sending_queue,omitempty"` - RetryConfig *BackOffConfig `json:"retry_on_failure,omitempty"` - Kubernetes *KubernetesMetadata `json:"kubernetes_metadata,omitempty"` +type Endpoint struct { + // TCPAddr is the address of the server to connect to. + TCPAddr *string `json:"tcp_addr"` + // Controls whether to validate the tcp address. + // Turning this ON may result in the collector failing to start if it came up faster then the endpoint. + // default is false. + ValidateTCPResolution bool `json:"validate_tcp_resolution"` } type KubernetesMetadata struct { @@ -125,9 +113,12 @@ type KubernetesMetadata struct { IncludePodLabels bool `json:"include_pod_labels"` } +// TCPClientSettings defines common settings for a TCP client. type TCPClientSettings struct { - // The target endpoint URI to send data to (e.g.: some.url:24224). - Endpoint *string `json:"endpoint,omitempty"` + // +kubebuilder:validation:Required + + // Endpoint to send logs to. + *Endpoint `json:"endpoint"` // +kubebuilder:validation:Format=duration @@ -141,6 +132,27 @@ type TCPClientSettings struct { SharedKey *string `json:"shared_key,omitempty"` } +// Configuration for the fluentforward exporter. +type Fluentforward struct { + TCPClientSettings `json:",inline"` + + // RequireAck enables the acknowledgement feature. + RequireAck *bool `json:"require_ack,omitempty"` + + // The Fluent tag parameter used for routing + Tag *string `json:"tag,omitempty"` + + // CompressGzip enables gzip compression for the payload. + CompressGzip *bool `json:"compress_gzip,omitempty"` + + // DefaultLabelsEnabled is a map of default attributes to be added to each log record. + DefaultLabelsEnabled *map[string]bool `json:"default_labels_enabled,omitempty"` + + QueueConfig *QueueSettings `json:"sending_queue,omitempty"` + RetryConfig *BackOffConfig `json:"retry_on_failure,omitempty"` + Kubernetes *KubernetesMetadata `json:"kubernetes_metadata,omitempty"` +} + // OutputStatus defines the observed state of Output type OutputStatus struct { } diff --git a/api/telemetry/v1alpha1/zz_generated.deepcopy.go b/api/telemetry/v1alpha1/zz_generated.deepcopy.go index d6658ee..08626d4 100644 --- a/api/telemetry/v1alpha1/zz_generated.deepcopy.go +++ b/api/telemetry/v1alpha1/zz_generated.deepcopy.go @@ -342,6 +342,26 @@ func (in *CollectorStatus) DeepCopy() *CollectorStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Endpoint) DeepCopyInto(out *Endpoint) { + *out = *in + if in.TCPAddr != nil { + in, out := &in.TCPAddr, &out.TCPAddr + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Endpoint. +func (in *Endpoint) DeepCopy() *Endpoint { + if in == nil { + return nil + } + out := new(Endpoint) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Fluentforward) DeepCopyInto(out *Fluentforward) { *out = *in @@ -992,8 +1012,8 @@ func (in *TCPClientSettings) DeepCopyInto(out *TCPClientSettings) { *out = *in if in.Endpoint != nil { in, out := &in.Endpoint, &out.Endpoint - *out = new(string) - **out = **in + *out = new(Endpoint) + (*in).DeepCopyInto(*out) } if in.ConnectionTimeout != nil { in, out := &in.ConnectionTimeout, &out.ConnectionTimeout diff --git a/charts/telemetry-controller/crds/telemetry.kube-logging.dev_outputs.yaml b/charts/telemetry-controller/crds/telemetry.kube-logging.dev_outputs.yaml index d8da1d2..bf3c85e 100644 --- a/charts/telemetry-controller/crds/telemetry.kube-logging.dev_outputs.yaml +++ b/charts/telemetry-controller/crds/telemetry.kube-logging.dev_outputs.yaml @@ -150,8 +150,22 @@ spec: to be added to each log record. type: object endpoint: - description: 'The target endpoint URI to send data to (e.g.: some.url:24224).' - type: string + description: Endpoint to send logs to. + properties: + tcp_addr: + description: TCPAddr is the address of the server to connect + to. + type: string + validate_tcp_resolution: + description: |- + Controls whether to validate the tcp address. + Turning this ON may result in the collector failing to start if it came up faster then the endpoint. + default is false. + type: boolean + required: + - tcp_addr + - validate_tcp_resolution + type: object kubernetes_metadata: properties: include_pod_labels: @@ -283,6 +297,8 @@ spec: https://godoc.org/crypto/tls#Config for more information. (optional) type: string type: object + required: + - endpoint type: object otlp: description: |- diff --git a/config/crd/bases/telemetry.kube-logging.dev_outputs.yaml b/config/crd/bases/telemetry.kube-logging.dev_outputs.yaml index d8da1d2..bf3c85e 100644 --- a/config/crd/bases/telemetry.kube-logging.dev_outputs.yaml +++ b/config/crd/bases/telemetry.kube-logging.dev_outputs.yaml @@ -150,8 +150,22 @@ spec: to be added to each log record. type: object endpoint: - description: 'The target endpoint URI to send data to (e.g.: some.url:24224).' - type: string + description: Endpoint to send logs to. + properties: + tcp_addr: + description: TCPAddr is the address of the server to connect + to. + type: string + validate_tcp_resolution: + description: |- + Controls whether to validate the tcp address. + Turning this ON may result in the collector failing to start if it came up faster then the endpoint. + default is false. + type: boolean + required: + - tcp_addr + - validate_tcp_resolution + type: object kubernetes_metadata: properties: include_pod_labels: @@ -283,6 +297,8 @@ spec: https://godoc.org/crypto/tls#Config for more information. (optional) type: string type: object + required: + - endpoint type: object otlp: description: |- diff --git a/internal/controller/telemetry/otel_conf_gen/otel_conf_gen_test.go b/internal/controller/telemetry/otel_conf_gen/otel_conf_gen_test.go index 2ad7046..82693f7 100644 --- a/internal/controller/telemetry/otel_conf_gen/otel_conf_gen_test.go +++ b/internal/controller/telemetry/otel_conf_gen/otel_conf_gen_test.go @@ -271,7 +271,9 @@ func TestOtelColConfComplex(t *testing.T) { Spec: v1alpha1.OutputSpec{ Fluentforward: &v1alpha1.Fluentforward{ TCPClientSettings: v1alpha1.TCPClientSettings{ - Endpoint: utils.ToPtr("fluentd.example-tenant-b-ns.svc.cluster.local:24224"), + Endpoint: &v1alpha1.Endpoint{ + TCPAddr: utils.ToPtr("fluentd.example-tenant-b-ns.svc.cluster.local:24224"), + }, TLSSetting: &v1alpha1.TLSClientSetting{ Insecure: true, }, diff --git a/internal/controller/telemetry/pipeline/components/exporter/fluent_forward_exporter_test.go b/internal/controller/telemetry/pipeline/components/exporter/fluent_forward_exporter_test.go index 24d354d..d1a385f 100644 --- a/internal/controller/telemetry/pipeline/components/exporter/fluent_forward_exporter_test.go +++ b/internal/controller/telemetry/pipeline/components/exporter/fluent_forward_exporter_test.go @@ -79,7 +79,9 @@ func TestGenerateFluentforwardExporters(t *testing.T) { Spec: v1alpha1.OutputSpec{ Fluentforward: &v1alpha1.Fluentforward{ TCPClientSettings: v1alpha1.TCPClientSettings{ - Endpoint: utils.ToPtr("http://example.com"), + Endpoint: &v1alpha1.Endpoint{ + TCPAddr: utils.ToPtr("http://example.com"), + }, }, }, }, @@ -108,7 +110,10 @@ func TestGenerateFluentforwardExporters(t *testing.T) { }, expectedResult: map[string]any{ "fluentforwardexporter/default_output1": map[string]any{ - "endpoint": "http://example.com", + "endpoint": map[string]any{ + "tcp_addr": "http://example.com", + "validate_tcp_resolution": false, + }, "sending_queue": map[string]any{ "enabled": true, "queue_size": float64(100), @@ -165,7 +170,9 @@ func TestGenerateFluentforwardExporters(t *testing.T) { Spec: v1alpha1.OutputSpec{ Fluentforward: &v1alpha1.Fluentforward{ TCPClientSettings: v1alpha1.TCPClientSettings{ - Endpoint: utils.ToPtr("http://example.com"), + Endpoint: &v1alpha1.Endpoint{ + TCPAddr: utils.ToPtr("http://example.com"), + }, ConnectionTimeout: utils.ToPtr("30s"), SharedKey: utils.ToPtr("shared-key"), }, @@ -203,7 +210,10 @@ func TestGenerateFluentforwardExporters(t *testing.T) { }, expectedResult: map[string]any{ "fluentforwardexporter/default_output2": map[string]any{ - "endpoint": "http://example.com", + "endpoint": map[string]any{ + "tcp_addr": "http://example.com", + "validate_tcp_resolution": false, + }, "connection_timeout": "30s", "shared_key": "shared-key", "require_ack": true,