Skip to content

Commit

Permalink
Fix defaults, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev committed Nov 14, 2023
1 parent fd9a1ed commit f75a35f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 7 deletions.
8 changes: 4 additions & 4 deletions component/otelcol/exporter/loadbalancing/loadbalancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func TestConfigConversion(t *testing.T) {
Static: nil,
K8sSvc: &loadbalancingexporter.K8sSvcResolver{
Service: "lb-svc.lb-ns",
Ports: []int32{4317},
},
},
RoutingKey: "traceID",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/traces/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
90 changes: 89 additions & 1 deletion pkg/traces/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ service:
`,
},
{
name: "tail sampling config with load balancing",
name: "tail sampling config with DNS load balancing",
cfg: `
receivers:
jaeger:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f75a35f

Please sign in to comment.