Skip to content

Commit

Permalink
[chore] [processor/k8sattributes] Fix extract config documentation (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#20249)

- Fix messed up config examples
- Move field documentation to the fields
  • Loading branch information
dmitryax committed Mar 22, 2023
1 parent 1573341 commit 77aaab5
Showing 1 changed file with 49 additions and 59 deletions.
108 changes: 49 additions & 59 deletions processor/k8sattributesprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,69 +103,59 @@ type ExtractConfig struct {
Labels []FieldExtractConfig `mapstructure:"labels"`
}

// FieldExtractConfig allows specifying an extraction rule to extract a value from exactly one field.
//
// The field accepts a list FilterExtractConfig map. The map accepts several keys
//
// from, tag_name, key, key_regex and regex
//
// - tag_name represents the name of the tag that will be added to the span.
// When not specified a default tag name will be used of the format:
// k8s.pod.annotations.<annotation key>
// k8s.pod.labels.<label key>
// For example, if tag_name is not specified and the key is git_sha,
// then the attribute name will be `k8s.pod.annotations.git_sha`.
// When key_regex is present, tag_name supports back reference to both named capturing and positioned capturing.
// For example, if your pod spec contains the following labels,
//
// app.kubernetes.io/component: mysql
// app.kubernetes.io/version: 5.7.21
//
// and you'd like to add tags for all labels with prefix app.kubernetes.io/ and also trim the prefix,
// then you can specify the following extraction rules:
//
// processors:
// k8sattributes:
// extract:
// labels:
//
// - tag_name: $$1
// key_regex: kubernetes.io/(.*)
//
// this will add the `component` and `version` tags to the spans or metrics.
//
// - key represents the annotation name. This must exactly match an annotation name.
//
// - regex is an optional field used to extract a sub-string from a complex field value.
// The supplied regular expression must contain one named parameter with the string "value"
// as the name. For example, if your pod spec contains the following annotation,
//
// kubernetes.io/change-cause: 2019-08-28T18:34:33Z APP_NAME=my-app GIT_SHA=58a1e39 CI_BUILD=4120
//
// and you'd like to extract the GIT_SHA and the CI_BUILD values as tags, then you must
// specify the following two extraction rules:
//
// processors:
// k8sattributes:
// extract:
// annotations:
//
// - tag_name: git.sha
// key: kubernetes.io/change-cause
// regex: GIT_SHA=(?P<value>\w+)
//
// - tag_name: ci.build
// key: kubernetes.io/change-cause
// regex: JENKINS=(?P<value>[\w]+)
//
// this will add the `git.sha` and `ci.build` tags to the spans or metrics.
// FieldExtractConfig allows specifying an extraction rule to extract a resource attribute from pod (or namespace)
// annotations (or labels).
type FieldExtractConfig struct {
// TagName represents the name of the resource attribute that will be added to logs, metrics or spans.
// When not specified, a default tag name will be used of the format:
// - k8s.pod.annotations.<annotation key>
// - k8s.pod.labels.<label key>
// For example, if tag_name is not specified and the key is git_sha,
// then the attribute name will be `k8s.pod.annotations.git_sha`.
// When key_regex is present, tag_name supports back reference to both named capturing and positioned capturing.
// For example, if your pod spec contains the following labels,
//
// app.kubernetes.io/component: mysql
// app.kubernetes.io/version: 5.7.21
//
// and you'd like to add tags for all labels with prefix app.kubernetes.io/ and also trim the prefix,
// then you can specify the following extraction rules:
//
// extract:
// labels:
// - tag_name: $$1
// key_regex: kubernetes.io/(.*)
//
// this will add the `component` and `version` tags to the spans or metrics.
TagName string `mapstructure:"tag_name"`
Key string `mapstructure:"key"`

// Key represents the annotation (or label) name. This must exactly match an annotation (or label) name.
Key string `mapstructure:"key"`
// KeyRegex is a regular expression used to extract a Key that matches the regex.
// Out of Key or KeyRegex only one option is expected to be configured at a time.
// Out of Key or KeyRegex, only one option is expected to be configured at a time.
KeyRegex string `mapstructure:"key_regex"`
Regex string `mapstructure:"regex"`

// Regex is an optional field used to extract a sub-string from a complex field value.
// The supplied regular expression must contain one named parameter with the string "value"
// as the name. For example, if your pod spec contains the following annotation,
//
// kubernetes.io/change-cause: 2019-08-28T18:34:33Z APP_NAME=my-app GIT_SHA=58a1e39 CI_BUILD=4120
//
// and you'd like to extract the GIT_SHA and the CI_BUILD values as tags, then you must
// specify the following two extraction rules:
//
// extract:
// annotations:
// - tag_name: git.sha
// key: kubernetes.io/change-cause
// regex: GIT_SHA=(?P<value>\w+)
// - tag_name: ci.build
// key: kubernetes.io/change-cause
// regex: JENKINS=(?P<value>[\w]+)
//
// this will add the `git.sha` and `ci.build` resource attributes.
Regex string `mapstructure:"regex"`

// From represents the source of the labels/annotations.
// Allowed values are "pod" and "namespace". The default is pod.
From string `mapstructure:"from"`
Expand Down

0 comments on commit 77aaab5

Please sign in to comment.