-
Notifications
You must be signed in to change notification settings - Fork 359
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: feat(prometheus): add prometheus endpoint providing basic request met… #404
Conversation
b92a8ed
to
b3c5b21
Compare
cmd/server/server.go
Outdated
} | ||
|
||
// TODO: Make prom settings (port/path) configurable | ||
promAddr := ":9124" |
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.
I think we can simply export this at the admin api endpoint :)
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.
Ehm, what admin api endpoint? :D
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.
Sorry, I meant API endpoint!
Sorry, I forgot to press on "submit review" :) |
So I'm not sure what you mean regarding the config but I've build the version from the PR locally and tested it by curling the scraping endpoint which looks good:
|
Now that I see your TODO I don't understand you comment :D |
b3c5b21
to
58a499e
Compare
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 looks pretty good to me! I've found a couple of things that could be improved. Also, would you be able to add a small section at the bottom of https://github.com/ory/oathkeeper/blob/master/docs/docs/configure-deploy.md#authorizing-requests on setting up ORY Oathkeeper with prometheus (optionally grafana if it's easy to do).
metrics/prometheus.go
Outdated
} | ||
|
||
// NewPrometheusRepository creates a new prometheus repository with the given settings | ||
func NewPrometheusRepository(logger log.FieldLogger) (*PrometheusRepository, 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.
No error is returned so is the error return value required?
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.
fixed
cmd/server/server.go
Outdated
promAddr := d.Configuration().PrometheusServeAddress() | ||
go func() { | ||
// Expose the registered metrics via HTTP. | ||
httpServer := &http.Server{Handler: promhttp.HandlerFor(prometheusRepo.Registry, promhttp.HandlerOpts{}), Addr: promAddr} |
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.
prometheusRepo.Registry
will panic when prometheusRepo, err := metrics.NewPrometheusRepository(logger)
returns an 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.
yeah right, I removed the returning error is it did not make sense anyways...
cmd/server/server.go
Outdated
|
||
promPath := d.Configuration().PrometheusMetricsPath() | ||
promAddr := d.Configuration().PrometheusServeAddress() | ||
go func() { |
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.
You could add this to the tasks listed below: https://github.com/ory/oathkeeper/pull/404/files#diff-4c51d95b26718af4a2ac3bec33e54e49R220
Because it makes sense to use a waitgroup for shutdown here right?
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.
done ;)
cmd/server/server.go
Outdated
httpServer := &http.Server{Handler: promhttp.HandlerFor(prometheusRepo.Registry, promhttp.HandlerOpts{}), Addr: promAddr} | ||
http.Handle(promPath, promhttp.Handler()) | ||
logger.Infof("Proemtheus listening on %s...", promAddr) | ||
if err := httpServer.ListenAndServe(); err != nil { |
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.
Let's run this gracefully - see: https://github.com/ory/oathkeeper/pull/404/files#diff-4c51d95b26718af4a2ac3bec33e54e49R100-R111
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.
done ;)
If you merge with master, the weird failing test cases (flaky) will stop to happen :) |
8ede182
to
9b77989
Compare
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.
Not sure if you've missed this comment:
This looks pretty good to me! I've found a couple of things that could be improved. Also, would you be able to add a small section at the bottom of https://github.com/ory/oathkeeper/blob/master/docs/docs/configure-deploy.md#authorizing-requests on setting up ORY Oathkeeper with prometheus (optionally grafana if it's easy to do).
Let me know :)
Oh yeah, I've missed that comment :D Will add some words about this once it's running as I would also setup a Grafana board for us internally which I surely can share afterwards. |
If you have ideas how to e2e test it that would be awesome! |
A dirty one... ;) Put it on our staging ENV, didn't crash or log any error and provided metrics on :9000/metrics as expected. So I guess it's good to go ;) |
Ok nice, I thought you meant automated e2e test :D Do you need help with the docs? |
Will come up with something next week, should be OK. |
Awesome, thanks! |
Thank you for your hard work! |
Proposed changes
This will add an basic prometheus endpoint providing request metrics to get some application insights
Checklist
vulnerability, I confirm that I got green light (please contact [email protected]) from the maintainers to push the changes.
Further comments