From f75a35f37e0c86d49dfc6c839c39e1d53c2a151a Mon Sep 17 00:00:00 2001 From: Paulin Todev Date: Tue, 14 Nov 2023 17:03:06 +0000 Subject: [PATCH] Fix defaults, add tests --- .../exporter/loadbalancing/loadbalancing.go | 8 +- .../loadbalancing/loadbalancing_test.go | 1 + .../otelcol.exporter.loadbalancing.md | 2 +- pkg/traces/config.go | 2 +- pkg/traces/config_test.go | 90 ++++++++++++++++++- 5 files changed, 96 insertions(+), 7 deletions(-) diff --git a/component/otelcol/exporter/loadbalancing/loadbalancing.go b/component/otelcol/exporter/loadbalancing/loadbalancing.go index 475fabe60a00..e6b7dc836a06 100644 --- a/component/otelcol/exporter/loadbalancing/loadbalancing.go +++ b/component/otelcol/exporter/loadbalancing/loadbalancing.go @@ -213,12 +213,12 @@ type KubernetesResolver struct { var _ river.Defaulter = &KubernetesResolver{} -// DefaultDNSResolver holds default values for K8sSvcResolver. -var DefaultK8sSvcResolver = KubernetesResolver{} - // SetToDefault implements river.Defaulter. func (args *KubernetesResolver) SetToDefault() { - *args = DefaultK8sSvcResolver + if args == nil { + args = &KubernetesResolver{} + } + args.Ports = []int32{4317} } func (k8sSvcResolver *KubernetesResolver) Convert() loadbalancingexporter.K8sSvcResolver { diff --git a/component/otelcol/exporter/loadbalancing/loadbalancing_test.go b/component/otelcol/exporter/loadbalancing/loadbalancing_test.go index b96b6ab2c48f..5e528dd373a3 100644 --- a/component/otelcol/exporter/loadbalancing/loadbalancing_test.go +++ b/component/otelcol/exporter/loadbalancing/loadbalancing_test.go @@ -222,6 +222,7 @@ func TestConfigConversion(t *testing.T) { Static: nil, K8sSvc: &loadbalancingexporter.K8sSvcResolver{ Service: "lb-svc.lb-ns", + Ports: []int32{4317}, }, }, RoutingKey: "traceID", diff --git a/docs/sources/flow/reference/components/otelcol.exporter.loadbalancing.md b/docs/sources/flow/reference/components/otelcol.exporter.loadbalancing.md index 08c55155cbe4..f6951d828cf8 100644 --- a/docs/sources/flow/reference/components/otelcol.exporter.loadbalancing.md +++ b/docs/sources/flow/reference/components/otelcol.exporter.loadbalancing.md @@ -149,7 +149,7 @@ The following arguments are supported: Name | Type | Description | Default | Required ---- | ---- | ----------- | ------- | -------- `service` | `string` | Kubernetes service to resolve. | | yes -`ports` | `list(number)` | Ports to use with the IP addresses resolved from `service`. | `["4317"]` | no +`ports` | `list(number)` | Ports to use with the IP addresses resolved from `service`. | `[4317]` | no If no namespace is specified inside `service`, an attempt will be made to infer the namespace for this Agent. If this fails, the `default` namespace will be used. diff --git a/pkg/traces/config.go b/pkg/traces/config.go index 0134fafd4f05..69d7792a599f 100644 --- a/pkg/traces/config.go +++ b/pkg/traces/config.go @@ -589,7 +589,7 @@ func resolver(config map[string]interface{}) (map[string]interface{}, error) { case dnsTagName, staticTagName: resolverCfg[typ] = cfg case kubernetesTagName: - resolverCfg[typ] = "k8s" + resolverCfg["k8s"] = cfg default: return nil, fmt.Errorf("unsupported resolver config type: %s", typ) } diff --git a/pkg/traces/config_test.go b/pkg/traces/config_test.go index 80edb01b82f5..9ee9e0b32abf 100644 --- a/pkg/traces/config_test.go +++ b/pkg/traces/config_test.go @@ -754,7 +754,7 @@ service: `, }, { - name: "tail sampling config with load balancing", + name: "tail sampling config with DNS load balancing", cfg: ` receivers: jaeger: @@ -829,6 +829,94 @@ processors: - value1 - value2 extensions: {} +service: + pipelines: + traces/0: + exporters: ["loadbalancing"] + processors: [] + receivers: ["jaeger", "push_receiver"] + traces/1: + exporters: ["otlp/0"] + processors: ["tail_sampling"] + receivers: ["otlp/lb"] +`, + }, + { + name: "tail sampling config with Kubernetes load balancing", + cfg: ` +receivers: + jaeger: + protocols: + grpc: +remote_write: + - endpoint: example.com:12345 +tail_sampling: + policies: + - type: always_sample + - type: string_attribute + string_attribute: + key: key + values: + - value1 + - value2 +load_balancing: + receiver_port: 8181 + routing_key: service + exporter: + insecure: true + resolver: + kubernetes: + service: lb-svc.lb-ns + ports: + - 55690 + - 55691 +`, + expectedConfig: ` +receivers: + jaeger: + protocols: + grpc: + push_receiver: {} + otlp/lb: + protocols: + grpc: + endpoint: "0.0.0.0:8181" +exporters: + otlp/0: + endpoint: example.com:12345 + compression: gzip + retry_on_failure: + max_elapsed_time: 60s + loadbalancing: + routing_key: service + protocol: + otlp: + tls: + insecure: true + endpoint: noop + retry_on_failure: + max_elapsed_time: 60s + compression: none + resolver: + k8s: + service: lb-svc.lb-ns + ports: + - 55690 + - 55691 +processors: + tail_sampling: + decision_wait: 5s + policies: + - name: always_sample/0 + type: always_sample + - name: string_attribute/1 + type: string_attribute + string_attribute: + key: key + values: + - value1 + - value2 +extensions: {} service: pipelines: traces/0: