Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ public MetricsController(UserRepository userRepository,
.description("Internal linked account count")
.register(meterRegistry);

Gauge.builder("registered_apps_count",
() -> metricsRepository.countTotalRegisteredApps())
.description("Registered apps count")
Gauge.builder("app_registration_count",
() -> metricsRepository.countTotalAppRegistrations())
.description("App registration count")
.register(meterRegistry);

Gauge.builder("used_services_count",
() -> metricsRepository.countTotalUsedServices())
.description("Used services count")
.register(meterRegistry);

Stream.of(IdpScoping.values())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public Integer countTotalLinkedAccounts() {
), "totalLinkedAccounts");
}

public Integer countTotalAppRegistrations() {
return doInCollection("registrations",
List.of(
"{ \"$count\": \"totalAppRegistrations\" }"
), "totalAppRegistrations");
}

public Integer countTotalExternalLinkedAccountsByType(IdpScoping idpScoping) {
return doInCollection("users",
List.of(
Expand All @@ -34,14 +41,14 @@ public Integer countTotalExternalLinkedAccountsByType(IdpScoping idpScoping) {
), "countExternalLinkedAccounts");
}

public Integer countTotalRegisteredApps() {
public Integer countTotalUsedServices() {
return doInCollection("users",
List.of(
"{ \"$unwind\": \"$eduIDS\" }",
"{ \"$unwind\": \"$eduIDS.services\" }",
"{ \"$group\": { \"_id\": \"$eduIDS.services.entityId\" } },",
"{ \"$count\": \"countTotalRegisteredApps\" }"
), "countTotalRegisteredApps");
"{ \"$count\": \"countTotalUsedServices\" }"
), "countTotalUsedServices");
}

private Integer doInCollection(String collectionName, List<String> pipeLines, String resultKeyWord) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void prometheus() throws IOException {

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

List.of("user_count", "linked_account_count", "registered_apps_count")
List.of("user_count", "linked_account_count", "app_registration_count", "used_services_count")
.forEach(s -> assertTrue(metrics.contains(s)));
Stream.of(IdpScoping.values()).forEach(idpScoping ->
assertTrue(metrics.contains("external_linked_account_" + idpScoping.name())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void getTotalLinkedAccountCount() {
assertEquals(2, totalLinkedAccountCount);
Integer idinExternalAccounts = metricsRepository.countTotalExternalLinkedAccountsByType(IdpScoping.idin);
assertEquals(0, idinExternalAccounts);
Integer countTotalRegisteredApps = metricsRepository.countTotalRegisteredApps();
assertEquals(2, countTotalRegisteredApps);
Integer countTotalUsedServices = metricsRepository.countTotalUsedServices();
assertEquals(2, countTotalUsedServices);
}

}
Loading