Skip to content

metrics: introduce custom registry #7051

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Conversation

mohammed90
Copy link
Member

Module developers who add custom metrics are used to wrapping the registration with a sync.Once to avoid duplicate registration panic and control the registration. However, the flow of caddy reload doesn't play nice with this idiom.

Since the introduction of registry-per-context, we've told some users to ignore the duplicate registration error if received. However, checking for this particular error is annoying. I wonder if owning the sync.Once and tracking the registration is better. I don't know if this is the best flow.

Signed-off-by: Mohammed Al Sahaf <[email protected]>
@mohammed90 mohammed90 added discussion 💬 The right solution needs to be found under review 🧐 Review is pending before merging labels Jun 5, 2025
Signed-off-by: Mohammed Al Sahaf <[email protected]>
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

I don't fully understand this (the metrics stuff in general) but it looks good to me -- no obvious red flags 😅

@mohammed90
Copy link
Member Author

The key I'm using to track uniqueness isn't optimal because a single Caddy module may register multiple collectors. Extracting the unique identifiers using the Describe method is hard because theDesc type only has String method, and it's hard to extract both fqName and the const labels (unique combo) from the string. So I changed it to just swallow the duplicate registration error but bubble the rest. I doubt it's best-practice but cannot think of a better way.

@mholt
Copy link
Member

mholt commented Jun 9, 2025

That does sound like a tricky one. That's probably fine? We can see if it causes any issues but maybe it's not too likely, or is at least preventable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion 💬 The right solution needs to be found under review 🧐 Review is pending before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants