Skip to content

Commit 2ad62f4

Browse files
[filelog/operator/container] Correct docs file path metadata output location (#44474)
#### Description The documentation states the `container` operator for the `filelog` receiver outputs the metadata from the filepath to `resource.attributes{}` while in reality it outputs to `resource{}`. This is confusing when trying to match on these fields in later operators. <!--Describe the documentation added.--> #### Documentation Updated the example JSON snippets so it's clear the output is at `resource{}` --------- Co-authored-by: Christos Markou <[email protected]>
1 parent c8d2f9e commit 2ad62f4

File tree

1 file changed

+88
-48
lines changed

1 file changed

+88
-48
lines changed

pkg/stanza/docs/operators/container.md

Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@ The `container` parser can be configured to embed certain operations such as th
2727
Requires `include_file_path: true` in order for the `log.file.path` field to be available for the operator.
2828
If that's not possible, users can disable the metadata addition with `add_metadata_from_filepath: false`.
2929
A file path like `"/var/log/pods/some-ns_kube-controller-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d6/kube-controller/1.log"`,
30-
will produce the following k8s metadata:
30+
will produce the following k8s metadata as part of the [Entry.resource](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/docs/types/entry.md):
3131

3232
```json
3333
{
3434
"resource": {
35-
"attributes": {
36-
"k8s.pod.name": "kube-controller-kind-control-plane",
37-
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
38-
"k8s.container.name": "kube-controller",
39-
"k8s.container.restart_count": "1",
40-
"k8s.namespace.name": "some-ns"
41-
}
35+
"k8s.pod.name": "kube-controller-kind-control-plane",
36+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
37+
"k8s.container.name": "kube-controller",
38+
"k8s.container.restart_count": "1",
39+
"k8s.namespace.name": "some-ns"
4240
}
4341
}
4442
```
@@ -58,7 +56,7 @@ Note: in this example the `format: docker` is optional since formats can be auto
5856
`add_metadata_from_filepath` is true by default as well.
5957

6058
<table>
61-
<tr><td> Input body </td> <td> Output body</td></tr>
59+
<tr><td> Input entry </td> <td> Output entry</td></tr>
6260
<tr>
6361
<td>
6462

@@ -83,13 +81,11 @@ Note: in this example the `format: docker` is optional since formats can be auto
8381
"log.file.path": "/var/log/pods/some_kube-controller-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d6/kube-controller/1.log"
8482
},
8583
"resource": {
86-
"attributes": {
87-
"k8s.pod.name": "kube-controller-kind-control-plane",
88-
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
89-
"k8s.container.name": "kube-controller",
90-
"k8s.container.restart_count": "1",
91-
"k8s.namespace.name": "some"
92-
}
84+
"k8s.pod.name": "kube-controller-kind-control-plane",
85+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
86+
"k8s.container.name": "kube-controller",
87+
"k8s.container.restart_count": "1",
88+
"k8s.namespace.name": "some"
9389
}
9490
}
9591
```
@@ -106,7 +102,7 @@ Configuration:
106102
```
107103

108104
<table>
109-
<tr><td> Input body </td> <td> Output body</td></tr>
105+
<tr><td> Input entry </td> <td> Output entry</td></tr>
110106
<tr>
111107
<td>
112108

@@ -132,13 +128,11 @@ Configuration:
132128
"log.file.path": "/var/log/pods/some_kube-controller-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d6/kube-controller/1.log"
133129
},
134130
"resource": {
135-
"attributes": {
136-
"k8s.pod.name": "kube-controller-kind-control-plane",
137-
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
138-
"k8s.container.name": "kube-controller",
139-
"k8s.container.restart_count": "1",
140-
"k8s.namespace.name": "some"
141-
}
131+
"k8s.pod.name": "kube-controller-kind-control-plane",
132+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
133+
"k8s.container.name": "kube-controller",
134+
"k8s.container.restart_count": "1",
135+
"k8s.namespace.name": "some"
142136
}
143137
}
144138
```
@@ -155,7 +149,7 @@ Configuration:
155149
```
156150

157151
<table>
158-
<tr><td> Input body </td> <td> Output body</td></tr>
152+
<tr><td> Input entry </td> <td> Output entry</td></tr>
159153
<tr>
160154
<td>
161155

@@ -181,13 +175,11 @@ Configuration:
181175
"log.file.path": "/var/log/pods/some_kube-controller-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d6/kube-controller/1.log"
182176
},
183177
"resource": {
184-
"attributes": {
185-
"k8s.pod.name": "kube-controller-kind-control-plane",
186-
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
187-
"k8s.container.name": "kube-controller",
188-
"k8s.container.restart_count": "1",
189-
"k8s.namespace.name": "some"
190-
}
178+
"k8s.pod.name": "kube-controller-kind-control-plane",
179+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
180+
"k8s.container.name": "kube-controller",
181+
"k8s.container.restart_count": "1",
182+
"k8s.namespace.name": "some"
191183
}
192184
}
193185
```
@@ -207,7 +199,7 @@ Configuration:
207199
```
208200

209201
<table>
210-
<tr><td> Input body </td> <td> Output body</td></tr>
202+
<tr><td> Input entry </td> <td> Output entry</td></tr>
211203
<tr>
212204
<td>
213205

@@ -238,13 +230,11 @@ Configuration:
238230
"log.file.path": "/var/log/pods/some_kube-controller-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d6/kube-controller/1.log"
239231
},
240232
"resource": {
241-
"attributes": {
242-
"k8s.pod.name": "kube-controller-kind-control-plane",
243-
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
244-
"k8s.container.name": "kube-controller",
245-
"k8s.container.restart_count": "1",
246-
"k8s.namespace.name": "some"
247-
}
233+
"k8s.pod.name": "kube-controller-kind-control-plane",
234+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
235+
"k8s.container.name": "kube-controller",
236+
"k8s.container.restart_count": "1",
237+
"k8s.namespace.name": "some"
248238
}
249239
}
250240
```
@@ -276,7 +266,7 @@ receivers:
276266
```
277267

278268
<table>
279-
<tr><td> Input body </td> <td> Output body</td></tr>
269+
<tr><td> Input entry </td> <td> Output entry</td></tr>
280270
<tr>
281271
<td>
282272

@@ -306,13 +296,63 @@ receivers:
306296
"log.file.path": "/var/log/pods/some_kube-controller-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d6/kube-controller/1.log"
307297
},
308298
"resource": {
309-
"attributes": {
310-
"k8s.pod.name": "kube-controller-kind-control-plane",
311-
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
312-
"k8s.container.name": "kube-controller",
313-
"k8s.container.restart_count": "1",
314-
"k8s.namespace.name": "some"
315-
}
299+
"k8s.pod.name": "kube-controller-kind-control-plane",
300+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
301+
"k8s.container.name": "kube-controller",
302+
"k8s.container.restart_count": "1",
303+
"k8s.namespace.name": "some"
304+
}
305+
}
306+
```
307+
308+
</td>
309+
</tr>
310+
</table>
311+
312+
#### Use metadata in operators
313+
To use the metadata in other operators, use the [Entry.resource](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/stanza/docs/types/entry.md):
314+
315+
Configuration:
316+
```yaml
317+
- type: container
318+
format: docker
319+
add_metadata_from_filepath: true
320+
- type: move
321+
from: resource["k8s.namespace.name"]
322+
to: resource.namespace
323+
```
324+
325+
<table>
326+
<tr><td> Input entry </td> <td> Output entry</td></tr>
327+
<tr>
328+
<td>
329+
330+
```json
331+
{
332+
"timestamp": "",
333+
"body": "{\"log\":\"INFO: log line here\",\"stream\":\"stdout\",\"time\":\"2024-03-30T08:31:20.545192187Z\"}",
334+
"log.file.path": "/var/log/pods/some_kube-controller-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d6/kube-controller/1.log"
335+
}
336+
```
337+
338+
</td>
339+
<td>
340+
341+
```json
342+
{
343+
"timestamp": "2024-03-30 08:31:20.545192187 +0000 UTC",
344+
"body": "INFO: log line here",
345+
"attributes": {
346+
"time": "2024-03-30T08:31:20.545192187Z",
347+
"log.iostream": "stdout",
348+
"log.file.path": "/var/log/pods/some_kube-controller-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d6/kube-controller/1.log"
349+
},
350+
"resource": {
351+
"k8s.pod.name": "kube-controller-kind-control-plane",
352+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d6",
353+
"k8s.container.name": "kube-controller",
354+
"k8s.container.restart_count": "1",
355+
"namespace": "some"
316356
}
317357
}
318358
```

0 commit comments

Comments
 (0)