Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore][exporter/datadog] Only start hostmetadata.Reporter if host_metadata.enabled #36669

Merged

Conversation

jade-guiton-dd
Copy link
Contributor

@jade-guiton-dd jade-guiton-dd commented Dec 4, 2024

Description

This PR avoids creating an inframetadata.Reporter and starting the metadata-sending goroutine when host_metadata.enabled is false, and removes some code that was used to work around the previous behavior. See tracking issue for context.

When enabled is false, we leave the exporter.metadataReporter field as nil. The parts of the code accessing this field were already gated behind enabled: true, or only_metadata: true (which, in a valid config, implies enabled: false), so it should not cause issues. However, tests that modify the config after the exporter is created, or which manually create invalid Config structs may encounter segfaults. I assumed we do not mind segfaults in cases of incorrect internal use, and fixed the one test that was failing because of this.

Link to tracking issue

Fixes #36522

@jade-guiton-dd jade-guiton-dd changed the title [exporter/datadog] Only start hostmetadata.Reporter if host_metadata.enabled [chore][exporter/datadog] Only start hostmetadata.Reporter if host_metadata.enabled Dec 4, 2024
@jade-guiton-dd jade-guiton-dd marked this pull request as ready for review December 4, 2024 16:32
@jade-guiton-dd jade-guiton-dd requested a review from a team as a code owner December 4, 2024 16:32
cancel()
return nil, fmt.Errorf("failed to build host metadata reporter: %w", err)

// These variables are referenced below, but only used if HostMetadata.Enabled
Copy link
Member

Choose a reason for hiding this comment

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

I find this comment a bit confusing, why not define them inside the if block then?

Copy link
Contributor Author

@jade-guiton-dd jade-guiton-dd Dec 5, 2024

Choose a reason for hiding this comment

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

Because they're referenced below. Unless we structure the whole function, we need these variables to be defined for the rest of the function, with metadataReporter left as nil if the if branch wasn't taken.

Copy link
Member

Choose a reason for hiding this comment

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

I guess I find the usage of "referenced" and "used" here confusing on the comment then: from your message I take that they are "used" (mentioned in code) both if HostMetadata.Enabled and if not, right?

Copy link
Contributor Author

@jade-guiton-dd jade-guiton-dd Dec 5, 2024

Choose a reason for hiding this comment

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

Right, I guess we have different definitions of "used".

The two variables are mentioned / referenced in the code below, which requires their scope to be larger than the if statement if we want the code to compile. This is independent of what path the code takes.

Even when !HostMetadata.Enabled, metadataReporter will still be read (not pcfg however), in order to be passed to the new(Logs|Traces|Metrics)Exporter function. It will be nil in that case, and gets stored as the exp.metadataReporter field.

But the pointer won't be used later down the line, ie. no methods will be called on it. (Which is good, because that would cause a segfault.)

I can reword the comment to make this clearer if you'd like.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, right, thanks! I will let you decide whether to reword it. I did find it confusing, and I don't feel like this is standard wording for this, but maybe it's just me 😄

Copy link
Contributor Author

@jade-guiton-dd jade-guiton-dd Dec 6, 2024

Choose a reason for hiding this comment

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

I simplified the logic and the comments somewhat, tell me if you think things are clearer or not

@mx-psi mx-psi merged commit 8da4542 into open-telemetry:main Dec 10, 2024
158 checks passed
@github-actions github-actions bot added this to the next release milestone Dec 10, 2024
sbylica-splunk pushed a commit to sbylica-splunk/opentelemetry-collector-contrib that referenced this pull request Dec 17, 2024
…_metadata.enabled` (open-telemetry#36669)

#### Description

This PR avoids creating an `inframetadata.Reporter` and starting the
metadata-sending goroutine when `host_metadata.enabled` is `false`, and
removes some code that was used to work around the previous behavior.
See tracking issue for context.

When `enabled` is `false`, we leave the `exporter.metadataReporter`
field as `nil`. The parts of the code accessing this field were already
gated behind `enabled: true`, or `only_metadata: true` (which, in a
valid config, implies `enabled: false`), so it should not cause issues.
However, tests that modify the config after the exporter is created, or
which manually create invalid `Config` structs may encounter segfaults.
I assumed we do not mind segfaults in cases of incorrect internal use,
and fixed the one test that was failing because of this.

#### Link to tracking issue
Fixes open-telemetry#36522
AkhigbeEromo pushed a commit to sematext/opentelemetry-collector-contrib that referenced this pull request Jan 13, 2025
…_metadata.enabled` (open-telemetry#36669)

#### Description

This PR avoids creating an `inframetadata.Reporter` and starting the
metadata-sending goroutine when `host_metadata.enabled` is `false`, and
removes some code that was used to work around the previous behavior.
See tracking issue for context.

When `enabled` is `false`, we leave the `exporter.metadataReporter`
field as `nil`. The parts of the code accessing this field were already
gated behind `enabled: true`, or `only_metadata: true` (which, in a
valid config, implies `enabled: false`), so it should not cause issues.
However, tests that modify the config after the exporter is created, or
which manually create invalid `Config` structs may encounter segfaults.
I assumed we do not mind segfaults in cases of incorrect internal use,
and fixed the one test that was failing because of this.

#### Link to tracking issue
Fixes open-telemetry#36522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter/datadog Datadog components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[exporter/datadog] Host metrics export is never fully disabled
4 participants