Skip to content

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>
Signed-off-by: Saumyacodes-40 <saumyabshah90@gmail.com>
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>
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

2 participants