Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] [exporter/coralogix] Document and test attributes ordering #26027

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions exporter/coralogixexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Learn more about [AWS PrivateLink in the documentation page](https://coralogix.c
### Application and SubSystem attributes

v0.62.0 release of OpenTelemetry Collector allows you to map Application name and Subsystem name to Resource attributes.
You need to set `application_name_attributes` and `subsystem_name_attributes` fields with a list of potential Resource attributes for the AppName and Subsystem values. The first not-empty Resource attribute is going to be used.
You need to set `application_name_attributes` and `subsystem_name_attributes` fields with a list of potential Resource attributes for the AppName and Subsystem values. The first not-empty Resource attribute is going to be used. If multiple resource attributes are available, **the order of the attributes in the list determines their priority.**

### Kubernetes attributes

Expand All @@ -114,16 +114,17 @@ exporters:
coralogix:
domain: "coralogix.com"
application_name_attributes:
- "service.namespace"
- "k8s.namespace.name"
- "service.namespace"
subsystem_name_attributes:
- "service.name"
- "k8s.job.name"
- "k8s.deployment.name"
- "k8s.statefulset.name"
- "k8s.daemonset.name"
- "k8s.cronjob.name"
- "k8s.job.name"
- "k8s.container.name"
- "k8s.pod.name"
- "k8s.node.name"
- "service.name"
```
### Host Attributes

Expand Down
30 changes: 28 additions & 2 deletions exporter/coralogixexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/pdata/pcommon"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/coralogixexporter/internal/metadata"
)
Expand Down Expand Up @@ -124,8 +125,8 @@ func TestLoadConfig(t *testing.T) {
WaitForReady: false,
BalancerName: "",
},
AppNameAttributes: []string{"service.namespace"},
SubSystemAttributes: []string{"service.name"},
AppNameAttributes: []string{"service.namespace", "k8s.namespace.name"},
SubSystemAttributes: []string{"service.name", "k8s.deployment.name", "k8s.statefulset.name", "k8s.daemonset.name", "k8s.cronjob.name", "k8s.job.name", "k8s.container.name"},
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: "https://",
TLSSetting: configtls.TLSClientSetting{
Expand Down Expand Up @@ -270,3 +271,28 @@ func TestEndpoindsAndDomainWithAllExporters(t *testing.T) {
require.NotNil(t, le, "failed to create logs exporter")
require.NoError(t, le.start(context.Background(), componenttest.NewNopHost()))
}

func TestGetMetadataFromResource(t *testing.T) {
r1 := pcommon.NewResource()
r1.Attributes().PutStr("k8s.node.name", "node-test")
r1.Attributes().PutStr("k8s.container.name", "container-test")
r1.Attributes().PutStr("k8s.deployment.name", "deployment-test")
r1.Attributes().PutStr("k8s.namespace.name", "namespace-test")

r2 := pcommon.NewResource()
r2.Attributes().PutStr("k8s.node.name", "node-test")
r2.Attributes().PutStr("k8s.namespace.name", "namespace-test")

c := &Config{
AppNameAttributes: []string{"k8s.container.name", "k8s.deployment.name", "k8s.node.name"},
SubSystemAttributes: []string{"k8s.namespace.name", "k8s.node.name"},
}

appName, subSystemName := c.getMetadataFromResource(r1)
assert.Equal(t, "container-test", appName)
assert.Equal(t, "namespace-test", subSystemName)

appName, subSystemName = c.getMetadataFromResource(r2)
assert.Equal(t, "node-test", appName)
assert.Equal(t, "namespace-test", subSystemName)
}
7 changes: 7 additions & 0 deletions exporter/coralogixexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ coralogix/all:
endpoint: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
application_name_attributes:
- "service.namespace"
- "k8s.namespace.name"
subsystem_name_attributes:
- "service.name"
- "k8s.deployment.name"
- "k8s.statefulset.name"
- "k8s.daemonset.name"
- "k8s.cronjob.name"
- "k8s.job.name"
- "k8s.container.name"
private_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
application_name: "APP_NAME"
subsystem_name: "SUBSYSTEM_NAME"
Expand Down