-
Notifications
You must be signed in to change notification settings - Fork 95
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
WIP: new prometheus middleware #94
Conversation
ab6f30c
to
39bb116
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #94 +/- ##
==========================================
+ Coverage 58.79% 63.77% +4.97%
==========================================
Files 8 9 +1
Lines 682 944 +262
==========================================
+ Hits 401 602 +201
- Misses 258 302 +44
- Partials 23 40 +17
☔ View full report in Codecov by Sentry. |
@lammel your thoughts? |
The API you're putting forward looks really good to me. I especially like the way you expose I left a few nitty comments about implementation details although I have to say I'm very fond of the public API being exposed here. A few quick questions
|
} | ||
|
||
// ToMiddleware converts configuration to middleware or returns an error. | ||
func (conf MiddlewareConfig) ToMiddleware() (echo.MiddlewareFunc, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this have to be public? I guess most use cases are using NewMiddlewareWithConfig anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to allow handling problems with middleware creation without panics. Similar to https://github.com/labstack/echo-jwt/blob/95b0b607987a3bed484870b2052ef212763742a4/jwt.go#L173
For background Feedback - What comes to my mind
About the PR
For the way forward I'm thinking of what @yabberyabber probably referred to func NewPrometheus(subsystem string, skipper middleware.Skipper, customMetricsList ...[]*Metric) *Prometheus {} Making this compatible with the new implementation could be made working if we simply ignore the customMetricsList or adding to the Registerer. The current implementation is rather awkward, so I guess the best way for developers would be to only have the simplified function for compatibility and fail-fast in case someone is using func NewPrometheus(subsystem string, skipper middleware.Skipper) *Prometheus {} |
About package name: customRegistry := prometheus.NewRegistry()
customCounter := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "custom_requests_total",
Help: "How many HTTP requests processed, partitioned by status code and HTTP method.",
},
)
if err := customRegistry.Register(customCounter); err != nil {
t.Fatal(err)
}
e.Use(echoprometheus.NewMiddlewareWithConfig(echoprometheus.MiddlewareConfig{
AfterNext: func(c echo.Context, err error) {
customCounter.Inc() // use our custom metric in middleware
},
Registerer: customRegistry,
}))
e.GET("/metrics", echoprometheus.NewHandlerWithConfig(echoprometheus.HandlerConfig{Gatherer: customRegistry})) is good example why having middleware in This is similar to JWT middleware situation.
I really not think we should force this newer API on older API or hack these two to work together. It would be confusing as new API is conceptionally different - it has separated concerns where older API has About current echo-contrib/prometheus/prometheus.go Line 130 in b6855c2
I think it started out as a abstraction so middleware API would not be too tied to Prometheus own API but as because of Dropping all of this logic/abstrction from middleware package resposibilities moves all resposibilities to the user. echo-contrib/prometheus/prometheus.go Line 300 in b6855c2
To be able to create collectors as you see fit and use them in Middleware with
It is probably helpful.
I do not understand what you mean by that? In case you are creating custom collectors (metrics) for your background processes etc, you can register them with your
There are issues where people want to change buckets, namespace etc. It felt like most flexible way to allow users control over how default collectors/metrics are created. With that function you can change single one or all that pass through.
I think separate package would be better. Currently new API and old Prometheus MW API is atleast compatible when it comes to Prometheus own package structs/interfaces. Direct leap from Prometheus lib to VictoriaMetrics implementation is probably that takes time. Going from old API to new API is much easier when you do not do fancy things. |
I thought about it - for example we could have some object created at the start of request and it implements Currently if you want to pass some "state" from
I do not actually know what exactly are you meaning by I do not think it should exists. Creation and usage of custom collector should be left to the developer. If we are talking about collectors/metrics related to HTTP requests then If we are talking about these default metrics HTTP middleware registers and I really think echo-contrib/prometheus/prometheus.go Line 300 in b6855c2
If it is about other custom collectors (maybe you have background processes that you meter). Then you would just register these collectors/metrics to your custom Registry or use |
Although aliasing for import works quite well I see your point. Conflicting package names can cause some headache.
Ok, keep it.
I was referring to the deployment on servers, where a go daemon is usually just a small part of the puzzle. If push is required for metrics there is probably already a pushgateway running somewhere near to also push other node metrics (system metrics, other applications, ...). But as above, just keep it, as it's there already.
Understood, I agree this is the must flexible option we have.
I completely agree. So to summarize:
|
I guess what I'm trying to say is do we need to provide the |
This API as written satisfies my usecase and I think is much easier to use than the previous API. Thanks for putting this together 👍 Let me know if there's anything I can do on my end to help you get this in. I did a brief walk through and I only had a couple small comments. |
Hey @aldas any update on this? I've got a project building off your fork and I would love to be able to point my go.mod replace rule at the upstream repo :) Is there anything I can do to help this PR along? |
@yabberyabber If you are in a hurry and want to help - could you copy this middleware code at the moment in your application and start to use it - this would give us practical information how it works in real world. If you are worried about licencing - this is MIT so just add the header and you are good. I'll fix @lammel review comments and try to get this PR finished this week. |
@lammel please re-review. Mostly addresses these points from previous review
and you know - I am no Shakespeare. so there is room for improvement in migration section. |
Great! Just need some time to review. Give me a few days. |
Thanks @aldas ! I just rebased my local projects to use the new middleware and it has been working great. I was just about to suggest you put the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Only some minor textual suggestions.
all right, textual changes done. @lammel, your approvement please and I'll merge and create next release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks @yabberyabber and @lammel. I'll update Echo website soon |
Proposal for new prometheus middleware (see #80).
This package
Metric
struct related features you are better off creating prometheus metrics (collectors) directly and not from indirections provided by old middleware. This way we (maintainers) free ourselves of maintenance of these structs that build collectors. We hand full ownership of custom metrics to the user.p.s. package name is
echoprometheus
because this way we get clean sheet and also it is quite annoying then you have conflicting package names (thing that we are using and middleware package).p.s.s. naming of things needs work.
Usage (shortest form):
Example for custom registry and custom metric usage:
that custom metric will appear in output as
Example for custom labels for middleware default metrics:
Example for changing middleware default metrics options before registering metrics:
Example running push gateway goroutine