Skip to content

[logs] Inherit source/service name in some cases#7310

Merged
prognant merged 2 commits intomasterfrom
prognant/logsK8s-fix-source-service-value
Feb 2, 2021
Merged

[logs] Inherit source/service name in some cases#7310
prognant merged 2 commits intomasterfrom
prognant/logsK8s-fix-source-service-value

Conversation

@prognant
Copy link
Copy Markdown
Contributor

@prognant prognant commented Jan 29, 2021

What does this PR do?

When tailing a file from a pod annotation (feature introduced by #7176) and the file config has no source/service it inherits the ones set for the container for consistency purpose.

Motivation

Source&service mapping consistency

Additional Notes

N/A

Describe your test plan

Same as #7176

@prognant prognant requested review from a team as code owners January 29, 2021 17:09
@prognant prognant added this to the 7.26.0 milestone Jan 29, 2021
@prognant prognant added changelog/no-changelog No changelog entry needed [deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead.. labels Jan 29, 2021
Copy link
Copy Markdown
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prognant LGTM w/ two nit comments

Comment thread pkg/logs/scheduler/scheduler.go Outdated

configName := s.configName(config)
// Used to fill empty source/service in some cases
serviceName, sourceName := s.extractMainSourceAndService(configs)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would this be better to put in the specific block where it's used? It seems like it's only useful for a small slice of configurations so having it out here seem like it's associating it with a much larger context without a need.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to run it against the whole configs slice, note that the configs slice will be rather small (like < 5) most of the time (it comes from a single annotation/label). I tried to make it more explicit.

Comment thread pkg/logs/scheduler/scheduler.go Outdated
// cfg.Type is not overwritten as tailing a file from a Docker or Kubernetes AD configuration
// is explicitly supported (other combinations may be supported later)
cfg.Identifier = service.Identifier
// We copy service and source name from the parent container if they are not set
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would be good to add a note about what cases can lead to the service/source name being empty on the container

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configs slice is coming straight from user inputs, I added comment to reflect that.

@prognant prognant requested a review from sgnn7 February 1, 2021 17:42
@prognant prognant merged commit 8e56591 into master Feb 2, 2021
@prognant prognant deleted the prognant/logsK8s-fix-source-service-value branch February 2, 2021 09:51
}

// extractMainSourceAndService extracts the source & service attached to the container config
func (s *Scheduler) extractMainSourceAndService(configs []*logsConfig.LogsConfig) (string, string) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prognant It's unclear to me when this logic is useful, and why we need to extract a source and service from the entire slice of LogsConfigs. Also I'm not sure what container config refers to (does that refer to a docker label/pod annotation, or something different?).

Could you clarify this and add a unit test that covers a scenario where this logic is useful? (and maybe refer to this unit test from code comments, so that there's a clear example of when it's useful)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to detail a bit this piece of code, the main use case (for now) is to handle annotation looking like :

[{"source":"mySource","service":"myService"}, {"type":"file","path":"/tmp/share/test.log"}]

And copy source/service to the file config (else it will get an empty service/source) as the foreseen behaviour was to get the same metadata attached to the lines collected from the file and the ones collected from the container.

Copy link
Copy Markdown
Member

@olivielpeau olivielpeau Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting example: is this an annotation that is "created" by the Agent's autodiscovery logic, or does it really reflect an annotation that a user would set?

Because, to me, it is expected that your example for the logs annotation:

[{"source":"mySource","service":"myService"}, {"type":"file","path":"/tmp/share/test.log"}]

would not set the source:mySource and service:myService on the file source, since IMO the 2 items in the list should be regarded as independent. IMO the annotation should be modified to:

[{"source":"mySource","service":"myService"}, {"source":"mySource","service":"myService","type":"file","path":"/tmp/share/test.log"}]

for mySource and myService to be applied to the file source. This behavior is more consistent with instances annotations for example.

Am I missing something though, or a specific use case?

In any case, if the service or source defaults to "container/pod" values defined by the Agent's autodiscovery or the Logs Agent (for example the short image name, etc), then it makes sense to have the file source defined in logs annotation to default to these values as well, but I think this was already handled in your original PR (#7176).

prognant added a commit that referenced this pull request Feb 3, 2021
prognant added a commit that referenced this pull request Feb 3, 2021
prognant added a commit that referenced this pull request Feb 4, 2021
sergei-deliveroo pushed a commit to deliveroo/datadog-agent that referenced this pull request Mar 24, 2021
sergei-deliveroo pushed a commit to deliveroo/datadog-agent that referenced this pull request Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog No changelog entry needed [deprecated] team/agent-core Deprecated. Use metrics-logs / shared-components labels instead..

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants