Skip to content
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

feat: support manual reporting of metrics in toolkit #205

Merged
merged 7 commits into from
Sep 23, 2024

Conversation

ShyunnY
Copy link
Contributor

@ShyunnY ShyunnY commented Sep 22, 2024

In the current PR, I implemented the API defined in the toolkit/metric package to support manual construction of metrics to record metric information.

Signed-off-by: shyunny <shyunny@outlook.com>
Signed-off-by: shyunny <shyunny@outlook.com>
Signed-off-by: shyunny <shyunny@outlook.com>
Signed-off-by: shyunny <shyunny@outlook.com>
Signed-off-by: shyunny <shyunny@outlook.com>
@wu-sheng wu-sheng added this to the 0.6.0 milestone Sep 22, 2024
@wu-sheng wu-sheng added the enhancement New feature or request label Sep 22, 2024
@wu-sheng wu-sheng requested a review from mrproliu September 22, 2024 10:57
Signed-off-by: shyunny <shyunny@outlook.com>
@@ -18,16 +18,21 @@
package metric

// NewCounter creates a new counter metrics.
func NewCounter(name string, opt ...MeterOpt) *CounterRef {
func NewCounter(name string, opt ...interface{}) *CounterRef {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need change the opt as interface? If it necessary, please add comment in the method to describe what kind of data we need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the interface{} type will allow us to handle it better in the interceptor, at least we don't need to do heavy type conversion tasks, which will bring a lot of unnecessary work.

I will strive to write detailed comments to explain to users why and how we should use it.

Copy link
Member

Choose a reason for hiding this comment

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

interface{} seems a very general type. For a counter, the parameters should be very certain. And building a counter is not a high-frequency operation, I can't see why change this.

Copy link
Contributor

Choose a reason for hiding this comment

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

But it's not easy understanding in the user, right?
Can we add an opt structure, and using the enhance instance as the option configuration. Then, user can know which kind of opts they can fill the arguments.

Copy link
Member

Choose a reason for hiding this comment

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

But it's not easy understanding in the user, right?

Not only this, more about. How to prevent the wrong implementation in the method? A certain type is a good thing, we should not expose an interface{} but no other condition, unless this is the use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I used MeterOpt as a type constraint to tell users how to use it.
@wu-sheng @mrproliu

Signed-off-by: shyunny <shyunny@outlook.com>
type NewHistogramInterceptor struct{}

func (h *NewHistogramInterceptor) BeforeInvoke(_ operator.Invocation) error {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Please using the defined result when interceptor all metrics constructor. It's better to control all object in the same side, if we change the toolkit API or agent, it could have unknown dependency error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't quite understand this, are you saying that we shouldn't use anonymous function parameters or do you mean something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean is it possible we can construct the metrics by the plugin?

Copy link
Contributor Author

@ShyunnY ShyunnY Sep 22, 2024

Choose a reason for hiding this comment

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

This approach may be possible, but we need to consider the following issues:

  1. Parameter parsing is necessary in the interceptor. Even if we build it in the plugin, we still need to parse the parameters
  2. Using (1) to build a metric instance, if it is implemented in the plugin, will it introduce unnecessary redundant code?
  3. In fact, we don’t do anything complicated in the interceptor, as I said above: parse parameters -> build objects. When the dependent NewXXX changes, compatibility must be considered

So I think we may not need to change this

Copy link
Contributor

Choose a reason for hiding this comment

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

Why it's related to the parameter? I just don't want to use the existing instance created from the toolkit API.
The basic process is: to build and define the result in the BeforeInvoke, then the toolkit implementation will not be invoked. The plugin controls all (toolkit)metrics instances, if we want to extend the metrics it's easy to adapt.

@mrproliu mrproliu merged commit 0b729dd into apache:main Sep 23, 2024
37 checks passed
@wu-sheng
Copy link
Member

Do we have a complete doc? @ShyunnY Would you like to write a blog to introduce the API usage through a blog?

@ShyunnY ShyunnY deleted the impl-metric branch September 23, 2024 06:05
@ShyunnY
Copy link
Contributor Author

ShyunnY commented Sep 23, 2024

yeah, I would write docs and blogs about the latest new features in toolkit. I have added it to my schedule and I will finish it as soon as possible. @wu-sheng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants