Skip to content

Commit

Permalink
Bump keycloak-event-metrics from 0.2.1 to 1.0.0 (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
sschnabe committed May 3, 2023
1 parent a5d8705 commit 86bc046
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

<!-- dependencies -->

<version.io.kokuwa.keycloak.metrics>0.2.1</version.io.kokuwa.keycloak.metrics>
<version.io.kokuwa.keycloak.metrics>1.0.0</version.io.kokuwa.keycloak.metrics>
<version.io.kubernetes.client>18.0.0</version.io.kubernetes.client>
<version.org.junit.jupiter>5.9.2</version.org.junit.jupiter>
<version.org.keycloak>21.1.1</version.org.keycloak>
Expand Down
1 change: 1 addition & 0 deletions src/main/docker/distroless/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ENV \
KC_HEALTH_ENABLED=true \
KC_METRICS_ENABLED=true \
KC_METRICS_EVENT_REPLACE_IDS=true \
KC_METRICS_STATS_ENABLED=true \
URI_METRICS_ENABLED=false \
URI_METRICS_DETAILED=false \
KC_PROXY=edge \
Expand Down
1 change: 1 addition & 0 deletions src/main/docker/temurin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ENV \
KC_HEALTH_ENABLED=true \
KC_METRICS_ENABLED=true \
KC_METRICS_EVENT_REPLACE_IDS=true \
KC_METRICS_STATS_ENABLED=true \
URI_METRICS_ENABLED=false \
URI_METRICS_DETAILED=false \
KC_PROXY=edge \
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/io/kokuwa/keycloak/K3sIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Instant;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -79,6 +80,17 @@ void metrics(Keycloak keycloak, Kubernetes kubernetes, OpenIDConnect oidc, Prome
() -> assertEquals(loginFailedGrayc + 2, prometheus.loginErrors(kokuwa), "kokuwa loginFailed"),
() -> assertEquals(loginSuccessTest + 2, prometheus.logins(test), "test loginSuccess"),
() -> assertEquals(loginFailedTest + 1, prometheus.loginErrors(test), "test loginFailed"));

// wait for user metrics

var end = Instant.now().plusSeconds(90);
while (Instant.now().isBefore(end) && prometheus.users("test") == 0) {
prometheus.scrap();
assertDoesNotThrow(() -> Thread.sleep(1000));
}
assertEquals(1, prometheus.users("master"), "user count master");
assertEquals(2, prometheus.users("kokuwa"), "user count kokuwa");
assertEquals(2, prometheus.users("test"), "user count test");
}

@DisplayName("keycloak mail configured")
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/io/kokuwa/keycloak/keycloak/Prometheus.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public int loginErrors(RealmRepresentation realm) {
.sum();
}

public int users(String realm) {
return state.stream()
.filter(metric -> Objects.equals(metric.name(), "keycloak_users"))
.filter(metric -> Objects.equals(metric.tags().get("realm"), realm))
.mapToInt(metric -> metric.value().intValue())
.sum();
}

public void scrap() {
state.clear();
Stream.of(client.scrap().split("[\\r\\n]+"))
Expand Down

0 comments on commit 86bc046

Please sign in to comment.