-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Prometheus metrics #1381
Prometheus metrics #1381
Conversation
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
So this will be a fun PR to merge with all them conflicts. Hopefully we can just force the merge when it's ready since I forgot to sign off on a merge commit. Highlights:
Todo:
|
Nice! What should I look out for when reviewing the WIP changes? Regarding Segment, it is very important that the existing fields, keys, and events stay unchanged. I also want to avoid to move stuff from |
Gotya. That is actually the kind of information I was looking for! I'm looking for general ideas more than anything, like maybe, "this stuff would be better in ory/x", or "this isn't suitable for the manager" kind of stuff. I'll make sure that the fields, keys, and events stay the same. There's not a whole lot to review; usually when I open a WIP PR I'm just making sure I'm heading in the right direction. |
Ok, perfect! Would it make sense to have the bridge in x? |
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
I was actually thinking the same thing! I went ahead and did that. In order for this to pass, it'll need this: ory/x#49 There might be some metrics missing or collected in an inopportune time, or just flat-out wrong, as my understanding of Hydra's code doesn't expand far beyond changes I've made. |
Signed-off-by: Kevin Minehart <kmineh0151@gmail.com>
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.
Interim review submission to see if my comments got lost or not :/
|
||
var ( | ||
metricClients = prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Namespace: "hydra", |
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.
Would it make sense to have the namespace fixed as a const somewhere? We should also decide if it's ory-hydra
, ory_hydra
, ORY Hydra
, hydra
or any other combination.
@@ -77,6 +82,7 @@ func RunServeAdmin(version, build, date string) func(cmd *cobra.Command, args [] | |||
return func(cmd *cobra.Command, args []string) { | |||
d := driver.NewDefaultDriver( | |||
logrusx.New(), | |||
prometheus.NewRegistry(), |
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.
If this is always prometheus.NewRegistry()
, wouldn't it make more sense to create that within the registry_base
?
ctx = context.Background() | ||
) | ||
|
||
optOut, err := cmd.Flags().GetBool("sqa-opt-out") |
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.
Do we need all of this here or could we hide that in metricsx
as it was previously?
}, | ||
) | ||
} | ||
b, err := metricsx.NewFormattedSegmentBridge(ctx, s, l, d.Registry().PrometheusManager().Registry) |
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.
Ok I see - so segment actually works (mostly) independent of Prometheus except for e.g. memory stats?
@@ -351,9 +352,56 @@ func (m *SQLManager) GetClients(ctx context.Context, limit, offset int) (clients | |||
func (m *SQLManager) CountClients(ctx context.Context) (int, error) { | |||
var n int | |||
if err := m.DB.QueryRow("SELECT count(*) FROM hydra_client").Scan(&n); err != nil { | |||
fmt.Println(err.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.
😅
|
||
defer func(p *HandledLoginRequest, err error) { | ||
recordAcceptLoginRequest(p, err) | ||
}(&p, err) |
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.
Relying on a global error is very flaky - there are several places where err will be overshadowed, e.g. here and here and here. I'm not sure about other projects but I feel that multiple return values usually re-define/overshadow the original err scope:
package main
import (
"fmt"
)
func main() {
a := "a"
fmt.Println(a) // "a"
b, a := "b", "c"
fmt.Println(a) // "c"
fmt.Println(b) // "b"
}
@@ -118,13 +119,17 @@ func (m *MemoryManager) RevokeSubjectClientConsentSession(ctx context.Context, u | |||
// do nothing | |||
} else if err != nil { | |||
return err | |||
} else { |
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 else is not really required right?
I'm gonna close this and re-open a new one when its ready. |
Related issue
#1176
Proposed changes
Add custom Prometheus metrics and HTTP middlewares for request count, duration, and size.
Checklist
vulnerability, I confirm that I got green light (please contact hi@ory.sh) from the maintainers to push the changes.
by signing my commit(s). You can amend your signature to the most recent commit by using
git commit --amend -s
. If youamend the commit, you might need to force push using
git push --force HEAD:<branch>
. Please be very careful when usingforce push.
Further comments
This is still a work in progress. Wanted to make sure that I was heading in the right direction code quality-wise. :)