Skip to content

feat: Add prometheus.echo component for local metrics inspection#4105

Merged
dehaansa merged 25 commits intografana:mainfrom
iamrajiv:ins
Dec 10, 2025
Merged

feat: Add prometheus.echo component for local metrics inspection#4105
dehaansa merged 25 commits intografana:mainfrom
iamrajiv:ins

Conversation

@iamrajiv
Copy link
Contributor

@iamrajiv iamrajiv commented Aug 2, 2025

PR Description

The component provides local inspection of Prometheus metrics by outputting them to stdout in a human-readable format, making debugging and testing much easier.

Which issue(s) this PR fixes

Fixes: #3738

Notes to the Reviewer

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

@iamrajiv iamrajiv requested a review from a team as a code owner August 2, 2025 07:04
@CLAassistant
Copy link

CLAassistant commented Aug 2, 2025

CLA assistant check
All committers have signed the CLA.

@iamrajiv
Copy link
Contributor Author

iamrajiv commented Aug 2, 2025

can you review @dehaansa @smaddock?

@dehaansa
Copy link
Contributor

dehaansa commented Aug 4, 2025

Can this be refactored to use the upstream encoding(s)? For example the expfmt encoder from the prometheus/common package expfmt.NewEncoder(&output, expfmt.NewFormat(expfmt.TypeTextPlain)), and then when things are appended store them using MetricFamily proto rather than an struct unique to this component. This will reduce maintenance requirements on the component and ensure we stay consistent with the upstream, and also allow users to pick a different exposition format if we allow.

@iamrajiv
Copy link
Contributor Author

iamrajiv commented Aug 4, 2025

sure @dehaansa will use prometheus expfmt encoder instead of custom string formatting and standard dto.MetricFamily protocol buffer

@dehaansa
Copy link
Contributor

dehaansa commented Oct 6, 2025

Sorry that this dropped off our radar - it looks good, but needs a docs page.

@iamrajiv
Copy link
Contributor Author

iamrajiv commented Oct 7, 2025

added the doc @dehaansa can you review ?

@iamrajiv
Copy link
Contributor Author

iamrajiv commented Oct 8, 2025

Thanks for reviewing and for the commit, @clayton-cornell. Could you review @dehaansa’s one more time?

Copy link
Contributor

@dehaansa dehaansa left a comment

Choose a reason for hiding this comment

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

Sorry that this slipped off my radar - LGTM. Once CI is happy, we can merge.

@clayton-cornell clayton-cornell added the type/docs Docs Squad label across all Grafana Labs repos label Nov 21, 2025
@clayton-cornell
Copy link
Contributor

@iamrajiv When you have a moment, can you please sign the CLA. It's a requirement for moving forward on your PR. :-)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new prometheus.echo component that receives Prometheus metrics and writes them to stdout in a human-readable format for debugging and testing purposes. The component mirrors the existing loki.echo component functionality but for Prometheus metrics instead of logs.

Key changes:

  • New prometheus.echo component with configurable output format (text or OpenMetrics)
  • Complete test coverage including format validation and metrics processing
  • Documentation following the existing component doc structure

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/component/prometheus/echo/echo.go Core component implementation with storage.Appendable interface, format encoding, and metric family building
internal/component/prometheus/echo/echo_test.go Comprehensive test suite covering component lifecycle, appender operations, and format outputs
internal/component/all/all.go Component registration in the global import list
docs/sources/reference/components/prometheus/prometheus.echo.md Complete component documentation with usage examples and compatibility info
CHANGELOG.md Release notes entry documenting the new feature

Comment on lines +287 to +298
for k := range a.samples {
delete(a.samples, k)
}
for k := range a.exemplars {
delete(a.exemplars, k)
}
for k := range a.histograms {
delete(a.histograms, k)
}
for k := range a.metadata {
delete(a.metadata, k)
}
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

Instead of iterating and deleting keys individually, consider reinitializing the maps with make() which is more efficient: a.samples = make(map[string]sample) etc.

Suggested change
for k := range a.samples {
delete(a.samples, k)
}
for k := range a.exemplars {
delete(a.exemplars, k)
}
for k := range a.histograms {
delete(a.histograms, k)
}
for k := range a.metadata {
delete(a.metadata, k)
}
a.samples = make(map[string]sample)
a.exemplars = make(map[string]seriesExemplar)
a.histograms = make(map[string]seriesHistogram)
a.metadata = make(map[string]metadata.Metadata)

Copilot uses AI. Check for mistakes.
require.NoError(t, err)
}()

time.Sleep(100 * time.Millisecond)
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

Using time.Sleep in tests creates flakiness and unnecessarily slows down test execution. Consider using synchronization primitives or channels to properly wait for the component to start, or remove this line if it's not essential for the test.

Copilot uses AI. Check for mistakes.
@dehaansa dehaansa enabled auto-merge (squash) December 9, 2025 04:54
@dehaansa
Copy link
Contributor

@iamrajiv this should be ready, but it seems the CLA check has lost your info, can you resign the CLA?

@iamrajiv
Copy link
Contributor Author

@dehaansa done can you check now

@dehaansa
Copy link
Contributor

@dehaansa done can you check now

The CLA Assistant seems to still think you haven't accepted: #4105 (comment)

@iamrajiv iamrajiv requested a review from dehaansa December 10, 2025 15:25
iamrajiv and others added 7 commits December 10, 2025 10:56
iamrajiv and others added 17 commits December 10, 2025 10:57
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
…rafana#4862)

* Introduce new dependency management tool

* Move syntax replace to top of go.mod to avoid confusion

* Apply replaces from tool

* Introduce PR workflow to check modules are synced

* Add E2E test

* Address some PR comments

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* Refactor to use a centralised cobra CLI, called by generate.go

* Refactor to not generate .txt files and pass replace text in memory

* Refactor E2E tests to use explicit test data

* Update tools/generate-module-dependencies/replaces-mod.tpl

Co-authored-by: Kyle Eckhart <kgeckhart@users.noreply.github.com>

* Return errors in FileHelper instead of using Fatalf

* Address PR comments

* go mod/mod changes

* Reference actual calculated file to dependency yaml file in error logs

* Group the generate-module-dependencies and Check for go.mod changes properly in workflow

and use git diff instead so we can ignore whitespace changes

* nit: a few improvements for clarity

---------

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>
Co-authored-by: Kyle Eckhart <kgeckhart@users.noreply.github.com>
…ana#5010)

* fix: add StoreBuilder to mimir.alerts.kubernetes eventProcessor

Fixes grafana#4975

* Add integration and unit tests

* Fix lint error

* Add changelog entry

---------

Co-authored-by: Paulin Todev <paulin.todev@gmail.com>
* Add some high level pipeline tests for prometheus

* Remove labelstore interactions from the interceptor

* Move back to uber atomic and fix flaky remote write test

* One more thing to move back to uber atomic

* Actually fix the flaky test and lints

* Fix flaky test for real and add a comment to Fanout about its role in global labels

* Put componentID back on fanout for now
* Improve docker's multiplexed long lines handling

* Fix `dockerChunkWriter` buffer flushing and add test for it

* Update `CHANGELOG.md`

* Fix potential panic in `extractTsFromBytes` and `dockerChunkWriter` buffer allocation
@dehaansa dehaansa merged commit 7f6d0d2 into grafana:main Dec 10, 2025
40 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age type/docs Docs Squad label across all Grafana Labs repos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add local inspection component for Prometheus metrics