Skip to content

Commit 7f3dc9d

Browse files
authored
Merge pull request #1228 from OpenConext/featuire/count_tiqr_registration
Add total number of linked accounts to metrics endpoint
2 parents 1104af8 + 8c1fd41 commit 7f3dc9d

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public MetricsController(UserRepository userRepository,
3737
.description("Used services count")
3838
.register(meterRegistry);
3939

40+
Gauge.builder("total_external_linked_account_count",
41+
() -> metricsRepository.countTotalExternalLinkedAccounts())
42+
.description("Total external linked account count")
43+
.register(meterRegistry);
44+
4045
Stream.of(IdpScoping.values())
4146
.forEach(idpScoping -> Gauge
4247
.builder("external_linked_account_" + idpScoping.name(),

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public Integer countTotalExternalLinkedAccountsByType(IdpScoping idpScoping) {
4141
), "countExternalLinkedAccounts");
4242
}
4343

44+
public Integer countTotalExternalLinkedAccounts() {
45+
return doInCollection("users",
46+
List.of(
47+
"{ \"$unwind\": \"$externalLinkedAccounts\" }",
48+
"{ \"$count\": \"totalExternalLinkedAccounts\" }"
49+
), "totalExternalLinkedAccounts");
50+
}
51+
4452
public Integer countTotalUsedServices() {
4553
return doInCollection("users",
4654
List.of(

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", "app_registration_count", "used_services_count")
36+
List.of("user_count", "linked_account_count", "app_registration_count", "used_services_count", "total_external_linked_account_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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ void getTotalLinkedAccountCount() {
1818
assertEquals(2, totalLinkedAccountCount);
1919
Integer idinExternalAccounts = metricsRepository.countTotalExternalLinkedAccountsByType(IdpScoping.idin);
2020
assertEquals(0, idinExternalAccounts);
21+
Integer totalExternalLinkedAccounts = metricsRepository.countTotalExternalLinkedAccounts();
22+
assertEquals(0, totalExternalLinkedAccounts);
2123
Integer countTotalUsedServices = metricsRepository.countTotalUsedServices();
2224
assertEquals(2, countTotalUsedServices);
2325
}

0 commit comments

Comments
 (0)