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

Export the versions of Go modules linked into the binary #578

Merged
merged 4 commits into from
Nov 1, 2022

Conversation

kylelemons
Copy link
Contributor

@kylelemons kylelemons commented Nov 1, 2022

💸 TL;DR

Backport of module metrics from v2.0.0

✅ Checks

  • CI tests (if present) are passing
  • Adheres to code style for repo
  • Contributor License Agreement (CLA) completed if not a Reddit employee

@kylelemons kylelemons requested a review from a team as a code owner November 1, 2022 16:21
@kylelemons kylelemons requested review from fishy, konradreiche and ghirsch-reddit and removed request for a team November 1, 2022 16:21
Path: "example.com/path/to/main/module",
Version: "(devel)",
},
Deps: []*debug.Module{{
Copy link
Member

Choose a reason for hiding this comment

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

nit: consider adding a case of replaced=true?

goModules.With(prometheus.Labels{
"go_module": mod.Path,
"module_role": role,
"replaced": strconv.FormatBool(mod.Replace != nil),
Copy link
Member

@fishy fishy Nov 1, 2022

Choose a reason for hiding this comment

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

🔕 I think overall we want to avoid using single word labels, as the whole label indices are global so two unrelated metrics emitting with the same label (e.g. conflicted labels) will make searching by label slower. I'd suggest use module_replaced instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, makes it a not-strict backport but I can make the change to v2 as well.

}, []string{"go_module", "module_role", "module_replaced", "module_version"})

func RecordModuleVersions(info *debug.BuildInfo) {
record := func(role string, mod *debug.Module) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what's the reason for defining this inside rather than at the top-level?

Help: "Export the version information for included Go modules, and whether the module is the 'main' module or a 'dependency'. Always 1",
}, []string{"go_module", "module_role", "module_replaced", "module_version"})

func RecordModuleVersions(info *debug.BuildInfo) {
Copy link
Member

Choose a reason for hiding this comment

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

🔕 also, do we want to consider moving this to prometheusbp so some more customized services (that don't use baseplate.New) can also use it?

Copy link
Member

Choose a reason for hiding this comment

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

+1 I think it would be useful to not lock this behind internal

Help: "Export the version information for included Go modules, and whether the module is the 'main' module or a 'dependency'. Always 1",
}, []string{"go_module", "module_role", "module_replaced", "module_version"})

func RecordModuleVersions(info *debug.BuildInfo) {
Copy link
Member

Choose a reason for hiding this comment

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

+1 I think it would be useful to not lock this behind internal

baseplate.go Outdated
@@ -310,7 +309,7 @@ func New(ctx context.Context, args NewArgs) (context.Context, Baseplate, error)
bp := impl{cfg: cfg, closers: batchcloser.New()}

if info, ok := debug.ReadBuildInfo(); ok {
prometheusbpint.RecordModuleVersions(info)
metricsbp.RecordModuleVersions(info)
Copy link
Member

Choose a reason for hiding this comment

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

you want prometheusbp instead of metricsbp 😅

@kylelemons kylelemons merged commit 53a15ba into master Nov 1, 2022
@kylelemons kylelemons deleted the modulemetrics branch November 1, 2022 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants