Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-8053 added metrics endpoint #3

Merged
merged 1 commit into from
Sep 9, 2024
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
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.13.2</quarkus.platform.version>
<quarkus.platform.version>3.14.2</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.4.0</surefire-plugin.version>
<testcontainers.version>1.20.1</testcontainers.version>
Expand All @@ -39,6 +39,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/de/svs/Namespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bson.types.ObjectId;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -32,6 +33,15 @@ public static List<Namespace> findByActivatedUntilOlderThan(Instant activatedUnt
return find("activatedUntil < ?1", activatedUntil).list();
}

public static long countActiveNamespaces() {
LocalDateTime now = LocalDateTime.now();
return count("activatedUntil > ?1", now);
}

public static long countTotalNamespaces() {
return count();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/de/svs/metrics/CustomNamespaceActivatorMetrics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.svs.metrics;

import de.svs.Namespace;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.quarkus.runtime.Startup;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

@Startup
@ApplicationScoped
public class CustomNamespaceActivatorMetrics {

@Inject
public CustomNamespaceActivatorMetrics(MeterRegistry registry) {
Gauge.builder("active_namespaces", Namespace::countActiveNamespaces)
.description("Number of active namespaces")
.register(registry);

Gauge.builder("total_namespaces", Namespace::countTotalNamespaces)
.description("Total number of namespaces known by the activator")
.register(registry);
}

}
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ quarkus.mongodb.connection-string=mongodb://localhost:27017/keda
baseDomain=.brb.dbildungscloud.dev
quarkus.mongodb.database=keda
namespace.deletion.cron=30 * * * * ?
# to set a kubeconfig you have to set the kubeconfig variable, yes lowercase
# to set a kubeconfig you have to set the kubeconfig variable, yes lowercase

quarkus.management.enabled=true
quarkus.management.port=9999
quarkus.micrometer.export.prometheus.enabled=true