Skip to content

Commit

Permalink
override all configurations
Browse files Browse the repository at this point in the history
Signed-off-by: ChrsMark <[email protected]>
  • Loading branch information
ChrsMark committed Dec 18, 2024
1 parent a2a3f77 commit 1dd06ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
13 changes: 7 additions & 6 deletions receiver/receivercreator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ operators:
- id: container-parser
type: container
```
This default can be extended using the respective annotation:
This default can be extended or overridden using the respective annotation:
`io.opentelemetry.discovery.logs/config`

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

Note that individual settings are overridden by the configuration provided by the hints while the operators list
is extended keeping first the `container` parser. If `container` parser is explicitly set by the user the default
will be overridden.

`include` cannot be overridden and is fixed to discovered container's log file path.


#### Support multiple target containers

Users can target the annotation to a specific container by suffixing it with the name of that container:
Expand All @@ -573,6 +570,8 @@ For example:
io.opentelemetry.discovery.logs.busybox/config: |
max_log_size: "3MiB"
operators:
- type: container
id: container-parser
- id: some
type: add
field: attributes.tag
Expand Down Expand Up @@ -691,6 +690,8 @@ spec:
io.opentelemetry.discovery.logs.redis/config: |
max_log_size: "4MiB"
operators:
- type: container
id: container-parser
- id: some
type: add
field: attributes.tag
Expand Down
36 changes: 7 additions & 29 deletions receiver/receivercreator/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ const (
scraperHint = "scraper"
configHint = "config"

logsReceiver = "filelog"
defaultLogPathPattern = "/var/log/pods/%s_%s_%s/%s/*.log"
filelogOperatorsConfigKey = "operators"
logsReceiver = "filelog"
defaultLogPathPattern = "/var/log/pods/%s_%s_%s/%s/*.log"
)

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

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

containerOpFound := false
for k, v := range userConf {
if k == filelogOperatorsConfigKey {
vlist, ok := v.([]any)
if !ok {
logger.Debug("could not parse operators configuration from hint", zap.Any("config", userConf))
}
for _, op := range vlist {
operator, ok := op.(map[string]any)
if !ok {
logger.Debug("could not parse operator configuration from hint", zap.Any("operator", op))
}
if operator["type"] == "container" {
containerOpFound = true
}
}
if !containerOpFound {
// if no container operator found then just extend the list
// otherwise we just use the user provided operators as-is
vlist = append(cont, vlist...)
}
defaultConfMap[k] = vlist
} else if k == "include" {
if k == "include" {
// path cannot be other than the one of the target container
continue
} else {
Expand Down
6 changes: 6 additions & 0 deletions receiver/receivercreator/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,16 @@ func TestK8sHintsBuilderLogs(t *testing.T) {
include_file_name: true
max_log_size: "2MiB"
operators:
- type: container
id: container-parser
- type: regex_parser
regex: "^(?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) (?P<sev>[A-Z]*) (?P<msg>.*)$"`
configNginx := `
include_file_name: true
max_log_size: "4MiB"
operators:
- type: container
id: container-parser
- type: add
field: attributes.tag
value: beta`
Expand Down Expand Up @@ -614,6 +618,8 @@ func TestCreateLogsConfig(t *testing.T) {
include_file_name: true
max_log_size: "2MiB"
operators:
- type: container
id: container-parser
- type: regex_parser
regex: "^(?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) (?P<sev>[A-Z]*) (?P<msg>.*)$"`
tests := map[string]struct {
Expand Down

0 comments on commit 1dd06ec

Please sign in to comment.