Question - MetricsEventListener - getClientId - event - context check #116
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
renovate
renovate/manager
cargo
renovate/manager
dockerfile
renovate/manager
git-submodules
renovate/manager
gomod
renovate/manager
kustomize
renovate/manager
kustomize
renovate/manager
maven
renovate/manager
maven
renovate/manager
npm
renovate/manager
pip_requirements
renovate/manager
regex
renovate/manager
renovate-config-presets
renovate/manager
woodpecker
renovate/type
bump
renovate/type
digest
renovate/type
lockFileMaintenance
renovate/type
major
renovate/type
minor
renovate/type
patch
renovate/type
pin
renovate/type
pinDigest
renovate/type
replacement
renovate/type
rollback
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Reference: kokuwaio/keycloak-event-metrics#116
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hello,
if I try out your event listener with account and account console clients provided by keycloak:
http://localhost:8080/auth/realms/sample-realm/account/
login and logout - I do not get the client in the LOGOUT metrics client label because the event is created by account-console, but the check finds account client in the keycloak context. Then I just get UNKNOWN because of the miss match. I get the account-console as client e.g. for the LOGIN event.
As there is already a clientId in the event itself, is this extra event clientId - context clientId check really necessary. - correct?
https://github.com/kokuwaio/keycloak-event-metrics/blob/main/src/main/java/io/kokuwa/keycloak/metrics/event/MetricsEventListener.java
private String getClientId(String clientId) {
return Optional.ofNullable(session.getContext())
.map(KeycloakContext::getClient)
.filter(model -> Objects.equals(model.getClientId(), clientId))
.map(ClientModel::getClientId)
.orElseGet(() -> {
log.tracev("Client for id {0} is unknown", clientId);
return "UNKNOWN";
});
}
I don't understand already how these 2 Keycloak clients work - but I have 2 correct clients and get UNKNOWN?
I'm using Keycloak 24.0.5.
Best Regards, Hermann
The clientId at the event is always set, even if there exists no client with the given clientId in Keycloak. The line MetricsEventListener.java#L73 checks if the event clientId matches the clientId from context. If the clientId is unknown to Keycloak the client from context would be null. This line is maybe obsolete because Line #72 already checks for missing client.
This was introduced with #105/#100 to mitigate clientId spamming.
If also tried to reproduce your issue with Keycloak 26.2.1 but i failed. Do you have a hint how to reproduce? E.g.
realm.json
to import.No repsonse on github, closed.