Provide metrics for user/client/session counts #16

Closed
opened 2023-04-05 22:43:59 +02:00 by xgp · 7 comments
xgp commented 2023-04-05 22:43:59 +02:00 (Migrated from github.com)

First of all, a thousand thank yous for writing this. Was hoping for someone to replace the aerogear metrics lib with something elegant, and this is it!

Curious if you'd consider adding gauges for stats like number of users, number of sessions (per client), etc.? I can do a PoC if it's something you'd be interested in.

First of all, a thousand thank yous for writing this. Was hoping for someone to replace the aerogear metrics lib with something elegant, and this is it! Curious if you'd consider adding gauges for stats like number of users, number of sessions (per client), etc.? I can do a PoC if it's something you'd be interested in.
sschnabe commented 2023-04-06 08:42:24 +02:00 (Migrated from github.com)

Thank you.

Regarding your request for number of users/sessions - can you explain how to measure them?

Number of user sessions this would be keycloak_event_user_total{type="LOGIN"} - keycloak_event_user_total{type="LOGOUT"}. Or do i miss something?

Thank you. Regarding your request for number of users/sessions - can you explain how to measure them? Number of user sessions this would be `keycloak_event_user_total{type="LOGIN"} - keycloak_event_user_total{type="LOGOUT"}`. Or do i miss something?
xgp commented 2023-04-06 14:57:26 +02:00 (Migrated from github.com)

I made an example here where you can see the changes: https://github.com/kokuwaio/keycloak-event-metrics/compare/main...xgp:keycloak-event-metrics:xgp/gauges?expand=1

They are not metrics you can derive from events, but from the session. For the example, I put them on a timer, but you could also use Gauges that have a function that looks at the stats when observed.

I made an example here where you can see the changes: https://github.com/kokuwaio/keycloak-event-metrics/compare/main...xgp:keycloak-event-metrics:xgp/gauges?expand=1 They are not metrics you can derive from events, but from the session. For the example, I put them on a timer, but you could also use Gauges that have a function that looks at the stats when observed.
sschnabe commented 2023-04-06 23:40:48 +02:00 (Migrated from github.com)

Ok, got it. Let me think about this. Right now i would change something:

  • add env flag to enable this behavior (like KC_METRICS_EVENT_REPLACE_IDS), maybe KC_METRICS_DATA_COUNT?
  • interval should be a flag too (default 60s), maybe KC_METRICS_DATA_COUNT_INTERVAL?
  • avoid transitive dependency com.google.common
  • create testcases in integration test (must have for me)

I'll pick up your branch and will work on this next week.

Thx for the request!

Ok, got it. Let me think about this. Right now i would change something: - add env flag to enable this behavior (like `KC_METRICS_EVENT_REPLACE_IDS`), maybe `KC_METRICS_DATA_COUNT`? - interval should be a flag too (default 60s), maybe `KC_METRICS_DATA_COUNT_INTERVAL`? - avoid transitive dependency `com.google.common` - create testcases in integration test (must have for me) I'll pick up your branch and will work on this next week. Thx for the request!
xgp commented 2023-04-07 10:45:48 +02:00 (Migrated from github.com)

Great. Thanks for the feedback. I updated the branch to include KC_METRICS_DATA_COUNT and KC_METRICS_DATA_COUNT_INTERVAL. I also extracted out the configuration into a separate class to make it easier to add new params in the future. https://github.com/kokuwaio/keycloak-event-metrics/compare/main...xgp:keycloak-event-metrics:xgp/gauges?expand=1

avoid transitive dependency com.google.common

The google guava library is a Keycloak dependency (https://github.com/keycloak/keycloak/blob/main/pom.xml#L670), so this would not be pulling in an additional transitive dependency. I use it in all of my extensions. As long as it's marked provided in the pom, it doesn't produce problems.

create testcases in integration test (must have for me)

Great rule! I will take a pass at updating and creating new tests this weekend.

Great. Thanks for the feedback. I updated the branch to include `KC_METRICS_DATA_COUNT` and `KC_METRICS_DATA_COUNT_INTERVAL`. I also extracted out the configuration into a separate class to make it easier to add new params in the future. https://github.com/kokuwaio/keycloak-event-metrics/compare/main...xgp:keycloak-event-metrics:xgp/gauges?expand=1 > avoid transitive dependency com.google.common The google guava library is a Keycloak dependency (https://github.com/keycloak/keycloak/blob/main/pom.xml#L670), so this would not be pulling in an additional transitive dependency. I use it in all of my extensions. As long as it's marked `provided` in the pom, it doesn't produce problems. > create testcases in integration test (must have for me) Great rule! I will take a pass at updating and creating new tests this weekend.
xgp commented 2023-04-15 11:02:03 +02:00 (Migrated from github.com)

Just an update that I spent quite a bit of time wrestling with the tests, but I wasn't able to get them working or understand your testing setup. My apologies, but there's just too much for me in there that I'm not familiar with. Apologies for taking your time.

Just an update that I spent quite a bit of time wrestling with the tests, but I wasn't able to get them working or understand your testing setup. My apologies, but there's just too much for me in there that I'm not familiar with. Apologies for taking your time.
sschnabe commented 2023-05-02 10:41:31 +02:00 (Migrated from github.com)

Please check release 1.0.0

Please check release [1.0.0](https://github.com/kokuwaio/keycloak-event-metrics/releases/tag/1.0.0)
xgp commented 2023-05-02 12:43:34 +02:00 (Migrated from github.com)

@sschnabe Very cool. I'm glad you were able to incorporate some of those metrics.

In case you want to have the Gauges calculated when they are called, rather than using a timer task, I found that you can create a Gauge that is lazy evaluated. I made an example here: https://github.com/xgp/keycloak-event-metrics/blob/xgp/gauges/src/main/java/io/kokuwa/keycloak/metrics/RealmGauges.java#L33

@sschnabe Very cool. I'm glad you were able to incorporate some of those metrics. In case you want to have the Gauges calculated when they are called, rather than using a timer task, I found that you can create a Gauge that is lazy evaluated. I made an example here: https://github.com/xgp/keycloak-event-metrics/blob/xgp/gauges/src/main/java/io/kokuwa/keycloak/metrics/RealmGauges.java#L33
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference: kokuwaio/keycloak-event-metrics#16
No description provided.