Skip to content

VAULT-38888 Add prefix vault to metric summary definitions #31489

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

roh-a
Copy link

@roh-a roh-a commented Aug 13, 2025

Description

This PR fixes an issue where duplicate metrics for core_leadership_lost, core_step_down and leadership_setup_failed were being exposed on the /sys/metrics?format=prometheus endpoint.
Refer this escalation ticket.

The Problem
Currently, the endpoint returns two versions of these metrics:

core_leadership_lost_*: A statically registered metric that is always zero.

vault_core_leadership_lost_*: The correct metric, which is properly populated at runtime.

This duplication is caused by a previous fix (PR #27966) that pre-registered the metrics to ensure their consistent availability. However, that registration did not account for the service name prefix added to metrics (in this case - vault).

The Solution
This change resolves the issue by adding the vault prefix to the static metric registrations. This aligns the pre-registered keys with the runtime keys, effectively eliminating the redundant, zero-value metrics from the output.

TODO only if you're a HashiCorp employee

  • Backport Labels: If this fix needs to be backported, use the appropriate backport/ label that matches the desired release branch. Note that in the CE repo, the latest release branch will look like backport/x.x.x, but older release branches will be backport/ent/x.x.x+ent.
    • LTS: If this fixes a critical security vulnerability or severity 1 bug, it will also need to be backported to the current LTS versions of Vault. To ensure this, use all available enterprise labels.
  • ENT Breakage: If this PR either 1) removes a public function OR 2) changes the signature
    of a public function, even if that change is in a CE file, double check that
    applying the patch for this PR to the ENT repo and running tests doesn't
    break any tests. Sometimes ENT only tests rely on public functions in CE
    files.
  • Jira: If this change has an associated Jira, it's referenced either
    in the PR description, commit message, or branch name.
  • RFC: If this change has an associated RFC, please link it in the description.
  • ENT PR: If this change has an associated ENT PR, please link it in the
    description. Also, make sure the changelog is in this PR, not in your ENT PR.

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.
  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
  • If applicable, I've documented the impact of any changes to security controls.

Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@roh-a roh-a added hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed backport/ent/1.18.x+ent labels Aug 13, 2025
Copy link

hashicorp-cla-app bot commented Aug 13, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

vercel bot commented Aug 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
vault-ui Ready Ready Preview Comment Aug 19, 2025 5:52am

Copy link

github-actions bot commented Aug 13, 2025

CI Results:
All Go tests succeeded! ✅

@roh-a roh-a changed the title [WIP] VAULT-38888 Add prefix vault to metric summary definitions VAULT-38888 Add prefix vault to metric summary definitions Aug 13, 2025
Copy link

@stuti-sr stuti-sr left a comment

Choose a reason for hiding this comment

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

I have provided a comment related to consistency of name in code base

@@ -56,15 +56,15 @@ func init() {
// telemetry reference docs so if updated should probably stay in sync.
metricregistry.RegisterSummaries([]metricregistry.SummaryDefinition{
{
Name: []string{"core", "step_down"},
Name: []string{"vault", "core", "step_down"},

Choose a reason for hiding this comment

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

Instead of hardcoding metric name arrays at multiple places, we should define them as constants/variables and reuse them.
var (
metricCoreStepDown = []string{"vault","core", "step_down"}
metricCoreLeadershipLost = []string{"vault","core", "leadership_lost"}
metricCoreLeadershipSetupFailed = []string{"vault","core", "leadership_setup_failed"}
)

Instead of using hard coded value: metrics.MeasureSince([]string{"core", "step_down"}, time.Now())
use metrics.MeasureSince(metricCoreStepDown, startTime)
similarly should also update:
line 314, 586 , 595, 659, 684, 696, 716, 753

This will help with maintainability, reduces duplication, and ensures metric names stay consistent across the codebase.

@roh-a roh-a marked this pull request as ready for review August 19, 2025 06:50
@roh-a roh-a requested a review from a team as a code owner August 19, 2025 06:50
@roh-a roh-a requested a review from AnPucel August 19, 2025 06:51
Copy link

Build Results:
All builds succeeded! ✅

@hc-github-team-secure-vault-core
Copy link
Collaborator

Copy workflow completed!

From To Error
hashicorp/vault#2743677675 hashicorp/vault-enterprise#2758925202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed pr/no-milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants