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

c8d: Prometheus metrics #47555

Merged
merged 5 commits into from Mar 13, 2024
Merged

c8d: Prometheus metrics #47555

merged 5 commits into from Mar 13, 2024

Conversation

rumpl
Copy link
Member

@rumpl rumpl commented Mar 12, 2024

- What I did

Sprinkled some prometheus metrics in the containerd backed image service, this implements the same events we have in the graph driver case.

Fixes #45268
Fixes #43855

- How I did it

- How to verify it

- Description for the changelog

containerd image store: Implement prometheus metrics

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

@rumpl rumpl added area/images containerd-integration Issues and PRs related to containerd integration area/metrics labels Mar 12, 2024
@rumpl rumpl changed the title c8d: Add the image labeled timer c8d: Prometheus metrics Mar 12, 2024
@rumpl rumpl self-assigned this Mar 12, 2024
@rumpl rumpl force-pushed the feat-c8d-prom branch 3 times, most recently from b614b37 to 2271fbd Compare March 12, 2024 14:51
@vvoland
Copy link
Contributor

vvoland commented Mar 12, 2024

Should we also surface this in changelog?

@rumpl
Copy link
Member Author

rumpl commented Mar 12, 2024

Should we also surface this in changelog?

done

Comment on lines 7 to 10
var imageActions metrics.LabeledTimer
var ImageActions metrics.LabeledTimer
Copy link
Member

Choose a reason for hiding this comment

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

This led me down a bit of dive. I was curious if this variable must be shared, or if it was ok to create a new instance in each package. I noticed this was set through init() (did I mention I hate init()?), and was even considering; if this must be shared (and now exported) would it make sense to use a sync.Once and a ImageActions() function for this instead of an exported var.

But this is when The funny thing I noticed when looking how it was used elsewhere is that in some places we use init()

func init() {
ns := metrics.NewNamespace("engine", "daemon", nil)

But in some we just define the package level variable;

moby/daemon/metrics.go

Lines 18 to 23 in 825635a

var (
metricsNS = metrics.NewNamespace("engine", "daemon", nil)
containerActions = metricsNS.NewLabeledTimer("container_actions", "The number of seconds it takes to process each container action", "action")
networkActions = metricsNS.NewLabeledTimer("network_actions", "The number of seconds it takes to process each network action", "action")
hostInfoFunctions = metricsNS.NewLabeledTimer("host_info_functions", "The number of seconds it takes to call functions gathering info about the host", "function")

Both of the above initialise a namespace with the same options (metrics.NewNamespace("engine", "daemon", nil)), which makes me consider that the variable may not have to be shared (so doesn't have to be a singleton)?

Do we know if that's correct? (in that case we may not have to export this, and just instance a namespace in each package / implementation, as long as they share the same name and subsystem? If that's not the case, then I'm wondering if some of the existing uses are .. wrong?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the issue is because we have the same labeled timer name, if you try and register a second one it fails with panic: duplicate metrics collector registration attempted. See here: https://github.com/moby/moby/actions/runs/8250723611/job/22566071811?pr=47555#step:6:1853

Copy link
Member

Choose a reason for hiding this comment

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

Ah, thanks! Yeah, I guess that makes sense, because in that case we need the same?

I think exporting the var is fine for now; we could add a comment describing why it's exported (to share between the implementations, as they share some code), and perhaps a disclaimer in it "not intended for external consumption for other purposes"

@@ -19,6 +20,7 @@ import (
"github.com/distribution/reference"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/registry"
dimages "github.com/docker/docker/daemon/images"
Copy link
Member

Choose a reason for hiding this comment

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

A bit related to that, and I didn't really consider that's already the case, but the containerd and images packages are the two implementations we have for handling the image-store. I see there's multiple imports of the images package into the containerd implementation. Not "critical", but it feels a bit odd. Perhaps we should look at what parts are used "in common" and if that code is in the right place (or should be in a "common" package that's shared between the two if duplicating those parts is undesirable)

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

but perhaps (see my comment above) adding a comment to the exported var wouldn't hurt.

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
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

@thaJeztah thaJeztah merged commit 342923b into moby:master Mar 13, 2024
138 checks passed
@thaJeztah thaJeztah deleted the feat-c8d-prom branch March 13, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/images area/metrics containerd-integration Issues and PRs related to containerd integration impact/changelog
Projects
None yet
3 participants