Skip to content

feat: Add new CollectorFunc utility#1724

Merged
bwplotka merged 8 commits intoprometheus:mainfrom
Saumya40-codes:implement-new-collectorfunc-util
Jan 31, 2025
Merged

feat: Add new CollectorFunc utility#1724
bwplotka merged 8 commits intoprometheus:mainfrom
Saumya40-codes:implement-new-collectorfunc-util

Conversation

@Saumya40-codes
Copy link
Copy Markdown
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>
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
Copy link
Copy Markdown
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.

Comment thread prometheus/collectorfunc.go Outdated
Comment thread prometheus/collectorfunc.go Outdated
Comment thread prometheus/collectorfunc.go Outdated
Comment thread prometheus/collectorfunc_test.go Outdated
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
@Saumya40-codes
Copy link
Copy Markdown
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
Copy Markdown
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
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