Add MetricsReporter interface so that databaseBackend's can share their connection counts with CensusManager - #31269
Merged
Conversation
|
CI Results: |
elliesterner
marked this pull request as ready for review
July 14, 2025 16:45
|
Build Results: |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new MetricsReporter interface and implements it in the database backend to expose connection counts, adds constants for supported database plugins, and covers the new functionality with unit tests.
- Define
MetricsReporterinsdk/logical/logical.go - Implement
GetConnectionMetricsinbuiltin/logical/database/backend.go - Add database plugin identifiers in
helper/pluginconsts/plugin_consts.go - Add tests for connection‐count reporting and Cassandra multiplexing in
builtin/logical/database/backend_test.go
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sdk/logical/logical.go | Introduce MetricsReporter interface |
| helper/pluginconsts/plugin_consts.go | Add constants for supported database plugin names |
| builtin/logical/database/backend.go | Implement GetConnectionMetrics on the backend |
| builtin/logical/database/backend_test.go | Add tests for GetConnectionMetrics and Cassandra |
Comments suppressed due to low confidence (4)
sdk/logical/logical.go:206
- [nitpick] The comment says "returns a metric" but the method returns multiple metrics; consider updating it to "returns metrics" for clarity.
// MetricsReporter is an optional interface that returns a
helper/pluginconsts/plugin_consts.go:29
- [nitpick] The acronym "DB" is typically capitalized in Go; consider renaming constants from
Db*toDB*for consistency with Go conventions.
DbCassandraPlugin = "cassandra"
helper/pluginconsts/plugin_consts.go:36
- [nitpick] The constant name suggests PostgreSQL but the value is "pgx"; consider aligning the name and value or adding a comment to explain the mapping.
DbPostgresqlPlugin = "pgx"
builtin/logical/database/backend.go:510
- [nitpick] It would be helpful to clarify in the comment that the returned map keys are plugin type strings and values are connection counts.
// GetConnectionMetrics returns a count of the active Database connections.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
fairclothjm
approved these changes
Jul 14, 2025
Erfankam
pushed a commit
to Erfankam/vault
that referenced
this pull request
Sep 1, 2025
…ir connection counts with CensusManager (hashicorp#31269) * add interface and impl * add tests * fix comments * Update builtin/logical/database/backend.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a MetricsReporter interface so that core can fetch the database backend's connection counts when reporting product usage metrics to census manager.
I'm going to add the changelog to the follow up PR that actually uses this new interface. This PR just defines it and includes a test.
This will go out in 1.21.0 and won't be backported.
TODO only if you're a HashiCorp employee
backport/label that matches the desired release branch. Note that in the CE repo, the latest release branch will look likebackport/x.x.x, but older release branches will bebackport/ent/x.x.x+ent.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.
in the PR description, commit message, or branch name.
description. Also, make sure the changelog is in this PR, not in your ENT PR.
PCI review checklist
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.