Skip to content

Commit e58f22a

Browse files
authored
Merge pull request #1226 from OpenConext/featuire/count_tiqr_registration
Add tiqr mfa registrations to metrics, rename apps to services. Fixes #1225
2 parents be37db1 + 03b2bd5 commit e58f22a

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

myconext-server/src/main/java/myconext/api/MetricsController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ public MetricsController(UserRepository userRepository,
2727
.description("Internal linked account count")
2828
.register(meterRegistry);
2929

30-
Gauge.builder("registered_apps_count",
31-
() -> metricsRepository.countTotalRegisteredApps())
32-
.description("Registered apps count")
30+
Gauge.builder("app_registration_count",
31+
() -> metricsRepository.countTotalAppRegistrations())
32+
.description("App registration count")
33+
.register(meterRegistry);
34+
35+
Gauge.builder("used_services_count",
36+
() -> metricsRepository.countTotalUsedServices())
37+
.description("Used services count")
3338
.register(meterRegistry);
3439

3540
Stream.of(IdpScoping.values())

myconext-server/src/main/java/myconext/repository/MetricsRepository.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public Integer countTotalLinkedAccounts() {
2525
), "totalLinkedAccounts");
2626
}
2727

28+
public Integer countTotalAppRegistrations() {
29+
return doInCollection("registrations",
30+
List.of(
31+
"{ \"$count\": \"totalAppRegistrations\" }"
32+
), "totalAppRegistrations");
33+
}
34+
2835
public Integer countTotalExternalLinkedAccountsByType(IdpScoping idpScoping) {
2936
return doInCollection("users",
3037
List.of(
@@ -34,14 +41,14 @@ public Integer countTotalExternalLinkedAccountsByType(IdpScoping idpScoping) {
3441
), "countExternalLinkedAccounts");
3542
}
3643

37-
public Integer countTotalRegisteredApps() {
44+
public Integer countTotalUsedServices() {
3845
return doInCollection("users",
3946
List.of(
4047
"{ \"$unwind\": \"$eduIDS\" }",
4148
"{ \"$unwind\": \"$eduIDS.services\" }",
4249
"{ \"$group\": { \"_id\": \"$eduIDS.services.entityId\" } },",
43-
"{ \"$count\": \"countTotalRegisteredApps\" }"
44-
), "countTotalRegisteredApps");
50+
"{ \"$count\": \"countTotalUsedServices\" }"
51+
), "countTotalUsedServices");
4552
}
4653

4754
private Integer doInCollection(String collectionName, List<String> pipeLines, String resultKeyWord) {

myconext-server/src/test/java/myconext/api/MetricsControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void prometheus() throws IOException {
3333

3434
String metrics = IOUtils.toString(inputStream, Charset.defaultCharset());
3535

36-
List.of("user_count", "linked_account_count", "registered_apps_count")
36+
List.of("user_count", "linked_account_count", "app_registration_count", "used_services_count")
3737
.forEach(s -> assertTrue(metrics.contains(s)));
3838
Stream.of(IdpScoping.values()).forEach(idpScoping ->
3939
assertTrue(metrics.contains("external_linked_account_" + idpScoping.name())));

myconext-server/src/test/java/myconext/repository/MetricsRepositoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ void getTotalLinkedAccountCount() {
1818
assertEquals(2, totalLinkedAccountCount);
1919
Integer idinExternalAccounts = metricsRepository.countTotalExternalLinkedAccountsByType(IdpScoping.idin);
2020
assertEquals(0, idinExternalAccounts);
21-
Integer countTotalRegisteredApps = metricsRepository.countTotalRegisteredApps();
22-
assertEquals(2, countTotalRegisteredApps);
21+
Integer countTotalUsedServices = metricsRepository.countTotalUsedServices();
22+
assertEquals(2, countTotalUsedServices);
2323
}
2424

2525
}

0 commit comments

Comments
 (0)