Skip to content

Commit 1dd06ec

Browse files
committed
override all configurations
Signed-off-by: ChrsMark <[email protected]>
1 parent a2a3f77 commit 1dd06ec

File tree

3 files changed

+20
-35
lines changed

3 files changed

+20
-35
lines changed

receiver/receivercreator/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ operators:
543543
- id: container-parser
544544
type: container
545545
```
546-
This default can be extended using the respective annotation:
546+
This default can be extended or overridden using the respective annotation:
547547
`io.opentelemetry.discovery.logs/config`
548548

549549
**Example:**
@@ -553,17 +553,14 @@ io.opentelemetry.discovery.logs/config: |
553553
include_file_name: true
554554
max_log_size: "2MiB"
555555
operators:
556+
- type: container
557+
id: container-parser
556558
- type: regex_parser
557559
regex: "^(?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) (?P<sev>[A-Z]*) (?P<msg>.*)$"
558560
```
559561

560-
Note that individual settings are overridden by the configuration provided by the hints while the operators list
561-
is extended keeping first the `container` parser. If `container` parser is explicitly set by the user the default
562-
will be overridden.
563-
564562
`include` cannot be overridden and is fixed to discovered container's log file path.
565563

566-
567564
#### Support multiple target containers
568565

569566
Users can target the annotation to a specific container by suffixing it with the name of that container:
@@ -573,6 +570,8 @@ For example:
573570
io.opentelemetry.discovery.logs.busybox/config: |
574571
max_log_size: "3MiB"
575572
operators:
573+
- type: container
574+
id: container-parser
576575
- id: some
577576
type: add
578577
field: attributes.tag
@@ -691,6 +690,8 @@ spec:
691690
io.opentelemetry.discovery.logs.redis/config: |
692691
max_log_size: "4MiB"
693692
operators:
693+
- type: container
694+
id: container-parser
694695
- id: some
695696
type: add
696697
field: attributes.tag

receiver/receivercreator/discovery.go

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ const (
2828
scraperHint = "scraper"
2929
configHint = "config"
3030

31-
logsReceiver = "filelog"
32-
defaultLogPathPattern = "/var/log/pods/%s_%s_%s/%s/*.log"
33-
filelogOperatorsConfigKey = "operators"
31+
logsReceiver = "filelog"
32+
defaultLogPathPattern = "/var/log/pods/%s_%s_%s/%s/*.log"
3433
)
3534

3635
// k8sHintsBuilder creates configurations from hints provided as Pod's annotations.
@@ -212,10 +211,10 @@ func createLogsConfig(
212211
logPath := fmt.Sprintf(defaultLogPathPattern, namespace, podName, podUID, containerName)
213212
cont := []any{map[string]any{"id": "container-parser", "type": "container"}}
214213
defaultConfMap := userConfigMap{
215-
"include": []string{logPath},
216-
"include_file_path": true,
217-
"include_file_name": false,
218-
filelogOperatorsConfigKey: cont,
214+
"include": []string{logPath},
215+
"include_file_path": true,
216+
"include_file_name": false,
217+
"operators": cont,
219218
}
220219

221220
configStr, found := getHintAnnotation(annotations, otelLogsHints, configHint, scopeSuffix)
@@ -228,29 +227,8 @@ func createLogsConfig(
228227
logger.Debug("could not unmarshal configuration from hint", zap.Error(err))
229228
}
230229

231-
containerOpFound := false
232230
for k, v := range userConf {
233-
if k == filelogOperatorsConfigKey {
234-
vlist, ok := v.([]any)
235-
if !ok {
236-
logger.Debug("could not parse operators configuration from hint", zap.Any("config", userConf))
237-
}
238-
for _, op := range vlist {
239-
operator, ok := op.(map[string]any)
240-
if !ok {
241-
logger.Debug("could not parse operator configuration from hint", zap.Any("operator", op))
242-
}
243-
if operator["type"] == "container" {
244-
containerOpFound = true
245-
}
246-
}
247-
if !containerOpFound {
248-
// if no container operator found then just extend the list
249-
// otherwise we just use the user provided operators as-is
250-
vlist = append(cont, vlist...)
251-
}
252-
defaultConfMap[k] = vlist
253-
} else if k == "include" {
231+
if k == "include" {
254232
// path cannot be other than the one of the target container
255233
continue
256234
} else {

receiver/receivercreator/discovery_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,16 @@ func TestK8sHintsBuilderLogs(t *testing.T) {
230230
include_file_name: true
231231
max_log_size: "2MiB"
232232
operators:
233+
- type: container
234+
id: container-parser
233235
- type: regex_parser
234236
regex: "^(?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) (?P<sev>[A-Z]*) (?P<msg>.*)$"`
235237
configNginx := `
236238
include_file_name: true
237239
max_log_size: "4MiB"
238240
operators:
241+
- type: container
242+
id: container-parser
239243
- type: add
240244
field: attributes.tag
241245
value: beta`
@@ -614,6 +618,8 @@ func TestCreateLogsConfig(t *testing.T) {
614618
include_file_name: true
615619
max_log_size: "2MiB"
616620
operators:
621+
- type: container
622+
id: container-parser
617623
- type: regex_parser
618624
regex: "^(?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) (?P<sev>[A-Z]*) (?P<msg>.*)$"`
619625
tests := map[string]struct {

0 commit comments

Comments
 (0)