Skip to content

feat: Add new CollectorFunc utility #1724

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

Merged

Conversation

Saumya40-codes
Copy link
Contributor

@Saumya40-codes Saumya40-codes commented Jan 29, 2025

Issue it is resolving

Resolves #1701

Description of changes

  • Added a new CollectorFunc utility in promethues package.
  • Instead of having boilerplate code which consisted of explicit Collect and Describe functions, CollectorFunc just requires to have Collect logic in it. Thus reducing extra boilerplate code (under certain scenerios)
  • Message to CollectorFunc function that it leverages the DescribeByCollector function

Testing

  • Added test: collectorfunc_test.go (more test might be needed)
  • Ran an example code with CollectorFunc and without it

cc: @bwplotka

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
update
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
Saumya40-codes and others added 3 commits January 29, 2025 10:30

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…/Saumya40-codes/client_golang into implement-new-collectorfunc-util
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks! Amazing 💪🏽

Can we also add one example to https://github.com/prometheus/client_golang/blob/main/prometheus/examples_test.go ?

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
@Saumya40-codes
Copy link
Contributor Author

Can we also add one example to https://github.com/prometheus/client_golang/blob/main/prometheus/examples_test.go ?

I've added an example related to CollectorFunc there, can you PTAL?

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks!

@bwplotka bwplotka merged commit 8afccc7 into prometheus:main Jan 31, 2025
9 checks passed
ying-jeanne pushed a commit to ying-jeanne/client_golang that referenced this pull request Mar 28, 2025
* feat: add CollectorFunc utility

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>

* update

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>

* added license to the test

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>

* address req changes

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>

* update license part in test file

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>

* add collectorFunc example to prometheus/examples_test.go

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>

---------

Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new utility CollectorFunc for simple Collector implementations
2 participants