Skip to content

Commit d201b41

Browse files
committed
[exporter/loadbalancingexporter] support k8s service resolver
Signed-off-by: Yuan Fang <[email protected]>
1 parent 788af04 commit d201b41

16 files changed

+768
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use this changelog template to create an entry for release notes.
2+
# If your change doesn't affect end users, such as a test fix or a tooling change,
3+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
4+
5+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
6+
change_type: 'enhancement'
7+
8+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
9+
component: loadbalancingexporter
10+
11+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
12+
note: Added kubernetes service resolver to loadbalancingexporter.
13+
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [22776]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:

cmd/configschema/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ require (
679679
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
680680
k8s.io/kubelet v0.27.3 // indirect
681681
k8s.io/utils v0.0.0-20230308161112-d77c459e9343 // indirect
682+
sigs.k8s.io/controller-runtime v0.15.0 // indirect
682683
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
683684
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
684685
sigs.k8s.io/yaml v1.3.0 // indirect

cmd/configschema/go.sum

+7-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/otelcontribcol/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ require (
688688
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
689689
k8s.io/kubelet v0.27.3 // indirect
690690
k8s.io/utils v0.0.0-20230308161112-d77c459e9343 // indirect
691+
sigs.k8s.io/controller-runtime v0.15.0 // indirect
691692
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
692693
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
693694
sigs.k8s.io/yaml v1.3.0 // indirect

cmd/otelcontribcol/go.sum

+7-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/loadbalancingexporter/README.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ This also supports service name based exporting for traces. If you have two or m
3737
Refer to [config.yaml](./testdata/config.yaml) for detailed examples on using the processor.
3838

3939
* The `otlp` property configures the template used for building the OTLP exporter. Refer to the OTLP Exporter documentation for information on which options are available. Note that the `endpoint` property should not be set and will be overridden by this exporter with the backend endpoint.
40-
* The `resolver` accepts either a `static` node, or a `dns`. If both are specified, `dns` takes precedence.
40+
* The `resolver` accepts a `static` node, a `dns` or a `k8s` service. If all three are specified, `k8s` takes precedence.
4141
* The `hostname` property inside a `dns` node specifies the hostname to query in order to obtain the list of IP addresses.
4242
* The `dns` node also accepts the following optional properties:
4343
* `hostname` DNS hostname to resolve.
4444
* `port` port to be used for exporting the traces to the IP addresses resolved from `hostname`. If `port` is not specified, the default port 4317 is used.
4545
* `interval` resolver interval in go-Duration format, e.g. `5s`, `1d`, `30m`. If not specified, `5s` will be used.
4646
* `timeout` resolver timeout in go-Duration format, e.g. `5s`, `1d`, `30m`. If not specified, `1s` will be used.
47+
* The `k8s` node accepts the following optional properties:
48+
* `service` Kubernetes service to resolve, e.g. `lb-svc.lb-ns`. If no namespace is specified, an attempt will be made to infer the namespace for this collector, and if this fails it will fall back to the `default` namespace.
49+
* `ports` port to be used for exporting the traces to the addresses resolved from `service`. If `ports` is not specified, the default port 4317 is used. When multiple ports are specified, two backends are added to the load balancer as if they were at different pods.
4750
* The `routing_key` property is used to route spans to exporters based on different parameters. This functionality is currently enabled only for `trace` pipeline types. It supports one of the following values:
4851
* `service`: exports spans based on their service name. This is useful when using processors like the span metrics, so all spans for each service are sent to consistent collector instances for metric collection. Otherwise, metrics for the same services are sent to different collectors, making aggregations inaccurate.
4952
* `traceID` (default): exports spans based on their `traceID`.
@@ -92,6 +95,49 @@ service:
9295
- loadbalancing
9396
```
9497
98+
Kubernetes resolver example
99+
```yaml
100+
receivers:
101+
otlp:
102+
protocols:
103+
grpc:
104+
endpoint: localhost:4317
105+
106+
processors:
107+
108+
exporters:
109+
logging:
110+
loadbalancing:
111+
routing_key: "service"
112+
protocol:
113+
otlp:
114+
# all options from the OTLP exporter are supported
115+
# except the endpoint
116+
timeout: 1s
117+
resolver:
118+
# use k8s service resolver, if collector runs in kubernetes environment
119+
k8s:
120+
service: lb-svc.kube-public
121+
ports:
122+
- 15317
123+
- 16317
124+
125+
service:
126+
pipelines:
127+
traces:
128+
receivers:
129+
- otlp
130+
processors: []
131+
exporters:
132+
- loadbalancing
133+
logs:
134+
receivers:
135+
- otlp
136+
processors: []
137+
exporters:
138+
- loadbalancing
139+
```
140+
95141
For testing purposes, the following configuration can be used, where both the load balancer and all backends are running locally:
96142
```yaml
97143
receivers:

exporter/loadbalancingexporter/config.go

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Protocol struct {
3232
type ResolverSettings struct {
3333
Static *StaticResolver `mapstructure:"static"`
3434
DNS *DNSResolver `mapstructure:"dns"`
35+
K8sSvc *K8sSvcResolver `mapstructure:"k8s"`
3536
}
3637

3738
// StaticResolver defines the configuration for the resolver providing a fixed list of backends
@@ -46,3 +47,9 @@ type DNSResolver struct {
4647
Interval time.Duration `mapstructure:"interval"`
4748
Timeout time.Duration `mapstructure:"timeout"`
4849
}
50+
51+
// K8sSvcResolver defines the configuration for the DNS resolver
52+
type K8sSvcResolver struct {
53+
Service string `mapstructure:"service"`
54+
Ports []int32 `mapstructure:"ports"`
55+
}

0 commit comments

Comments
 (0)