Skip to content

Commit 286a94f

Browse files
committed
Add k8s attributes to patroni logs. Add CompactingProcessor to patroni logs pipeline.
1 parent f2a80ac commit 286a94f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

internal/collector/patroni.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ func EnablePatroniLogging(ctx context.Context,
4040
},
4141
}
4242

43+
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/processor/resourceprocessor#readme
44+
outConfig.Processors["resource/patroni"] = map[string]any{
45+
"attributes": []map[string]any{
46+
// Container and Namespace names need no escaping because they are DNS labels.
47+
// Pod names need no escaping because they are DNS subdomains.
48+
//
49+
// https://kubernetes.io/docs/concepts/overview/working-with-objects/names
50+
// https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/resource/k8s.md
51+
{"action": "insert", "key": "k8s.container.name", "value": naming.ContainerDatabase},
52+
{"action": "insert", "key": "k8s.namespace.name", "value": "${env:K8S_POD_NAMESPACE}"},
53+
{"action": "insert", "key": "k8s.pod.name", "value": "${env:K8S_POD_NAME}"},
54+
},
55+
}
56+
4357
// https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/processor/transformprocessor#readme
4458
outConfig.Processors["transform/patroni_logs"] = map[string]any{
4559
"log_statements": []map[string]any{{
@@ -90,8 +104,10 @@ func EnablePatroniLogging(ctx context.Context,
90104
Extensions: []ComponentID{"file_storage/patroni_logs"},
91105
Receivers: []ComponentID{"filelog/patroni_jsonlog"},
92106
Processors: []ComponentID{
107+
"resource/patroni",
93108
"transform/patroni_logs",
94109
SubSecondBatchProcessor,
110+
CompactingProcessor,
95111
},
96112
Exporters: []ComponentID{DebugExporter},
97113
}

internal/collector/patroni_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ processors:
4444
batch/200ms:
4545
timeout: 200ms
4646
groupbyattrs/compact: {}
47+
resource/patroni:
48+
attributes:
49+
- action: insert
50+
key: k8s.container.name
51+
value: database
52+
- action: insert
53+
key: k8s.namespace.name
54+
value: ${env:K8S_POD_NAMESPACE}
55+
- action: insert
56+
key: k8s.pod.name
57+
value: ${env:K8S_POD_NAME}
4758
transform/patroni_logs:
4859
log_statements:
4960
- context: log
@@ -76,8 +87,10 @@ service:
7687
exporters:
7788
- debug
7889
processors:
90+
- resource/patroni
7991
- transform/patroni_logs
8092
- batch/200ms
93+
- groupbyattrs/compact
8194
receivers:
8295
- filelog/patroni_jsonlog
8396
`)

0 commit comments

Comments
 (0)