Skip to content

cmd/dockerd: Add workaround for OTEL meter leak#48690

Merged
thaJeztah merged 1 commit intomoby:masterfrom
vvoland:otel-meter-leak
Oct 18, 2024
Merged

cmd/dockerd: Add workaround for OTEL meter leak#48690
thaJeztah merged 1 commit intomoby:masterfrom
vvoland:otel-meter-leak

Conversation

@vvoland
Copy link
Contributor

@vvoland vvoland commented Oct 18, 2024

OTEL meter implementation has a memory leak issue which causes each meter counter invocation to create a new instrument when the meter provider is not set.

Also add a test, which will fail once a fixed OTEL is vendored.

- What I did

- How I did it

- How to verify it

- Description for the changelog

Fix a possible memory leak caused by OTEL meters

- A picture of a cute animal (not mandatory but encouraged)

Comment on lines +248 to +254

// Workaround OTEL memory leak
// See: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5190
// The need for this workaround is checked by the TestOtelMeterLeak test
// TODO: Remove this workaround after upgrading to v1.30.0
otel.SetMeterProvider(noop.MeterProvider{})

Copy link
Member

Choose a reason for hiding this comment

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

Curious if this should be "as early as possible" in the chain (as a default, which can be overridden by "whatever" will override).

Would this fix still work if we'd put it (e.g.) in newDaemonCommand (assuming setting it in main() wouldn't make it easy to test)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would work, but I think it's much better to have it in the same place as other OTEL related stuff. If we'd like to actually override it, we can just remove it as it won't be needed anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's also that we don't always know where things are overridden (at least I recall some of the ugly bits where BuildKit setup things in an init().

but I think it's much better to have it in the same place as other OTEL related stuff

Yeah, even wondering if there's bits around that that we should also set up earlier (making sure that we trace as much as possible, starting with main ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can move it to main, so at least it stops the leak earlier. Although that shouldn't be the case as AFAIK the only meter counting on our side come from otelhttp.

I don't think it's reasonable for us to consider dependencies silently override the meter provider without our deliberate decision though.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @vvoland

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Assuming this fixes the issue, happy to hear from others of course.

(left some minor nits)

OTEL meter implementation has a memory leak issue which causes each
meter counter invocation to create a new instrument when the meter
provider is not set.

Also add a test, which will fail once a fixed OTEL is vendored.

Signed-off-by: Paweł Gronowski <[email protected]>
@thaJeztah
Copy link
Member

I added cherry-pick labels for older releases as well, but not sure if those need it, so verify if needed before backporting (it's more as a "reminder") @cpuguy83 @austinvazquez @corhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory Leak in Docker 27.0.3

4 participants