Skip to content

Commit

Permalink
Bump metrics dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
schnapster committed Nov 10, 2024
1 parent 8bbe2b5 commit 8c5cf1f
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 156 deletions.
13 changes: 5 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ allprojects {

dependencies {
globalPlatforms platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion")
globalPlatforms platform("io.prometheus:simpleclient_bom:$prometheusVersion")
globalPlatforms platform("io.sentry:sentry-bom:$sentryVersion")
}
}
Expand Down Expand Up @@ -287,13 +286,11 @@ dependencies {
implementation(group: "io.netty", name: "netty-transport-native-epoll", classifier: "linux-x86_64")
implementation(group: "io.netty", name: "netty-transport-native-kqueue", classifier: "osx-x86_64")

implementation "io.prometheus:simpleclient"
implementation "io.prometheus:simpleclient_hotspot"
implementation "io.prometheus:simpleclient_logback"
implementation "io.prometheus:simpleclient_common"
implementation "io.prometheus:simpleclient_caffeine"
implementation "space.npstr:prometheus_extensions:$promExtVersion"
implementation "io.micrometer:micrometer-registry-prometheus-simpleclient"
// not part of v1.3.2 BOM for some reason
implementation "io.prometheus:prometheus-metrics-instrumentation-caffeine:$prometheusClientVersion"
implementation "io.prometheus:prometheus-metrics-instrumentation-jvm"
implementation "space.npstr:prometheus_extensions:$prometheusExtensionsVersion"
implementation "io.micrometer:micrometer-registry-prometheus"

implementation "org.postgresql:postgresql"
implementation "com.zaxxer:HikariCP"
Expand Down
24 changes: 13 additions & 11 deletions gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ io.micrometer:micrometer-commons:1.13.6=compileClasspath,compileOnlyDependencies
io.micrometer:micrometer-core:1.13.6=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.micrometer:micrometer-jakarta9:1.13.6=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.micrometer:micrometer-observation:1.13.6=compileClasspath,compileOnlyDependenciesMetadata,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.micrometer:micrometer-registry-prometheus-simpleclient:1.13.6=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.micrometer:micrometer-registry-prometheus:1.13.6=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.netty:netty-buffer:4.1.114.Final=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.netty:netty-codec:4.1.114.Final=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.netty:netty-common:4.1.114.Final=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
Expand All @@ -85,15 +85,17 @@ io.opentelemetry:opentelemetry-sdk-metrics:1.42.1=testCompileClasspath,testImple
io.opentelemetry:opentelemetry-sdk-trace:1.42.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.opentelemetry:opentelemetry-sdk:1.42.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.projectreactor:reactor-core:3.6.11=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:simpleclient:0.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:simpleclient_bom:0.16.0=annotationProcessor,apiDependenciesMetadata,compile,compileClasspath,compileOnlyDependenciesMetadata,developmentOnly,flywayMigration,implementationDependenciesMetadata,intransitiveDependenciesMetadata,jacocoAgent,jacocoAnt,jooqGenerator,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,productionRuntimeClasspath,runtimeClasspath,testAndDevelopmentOnly,testAnnotationProcessor,testApiDependenciesMetadata,testCompileClasspath,testCompileOnlyDependenciesMetadata,testImplementationDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntimeClasspath
io.prometheus:simpleclient_caffeine:0.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:simpleclient_common:0.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:simpleclient_hotspot:0.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:simpleclient_logback:0.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:simpleclient_tracer_common:0.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:simpleclient_tracer_otel:0.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:simpleclient_tracer_otel_agent:0.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-config:1.3.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-core:1.3.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-exposition-formats:1.2.1=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
io.prometheus:prometheus-metrics-instrumentation-caffeine:1.3.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-instrumentation-jvm:1.2.1=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-model:1.3.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-shaded-protobuf:1.2.1=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
io.prometheus:prometheus-metrics-tracer-common:1.3.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-tracer-initializer:1.3.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-tracer-otel-agent:1.3.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.prometheus:prometheus-metrics-tracer-otel:1.3.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.r2dbc:r2dbc-spi:1.0.0.RELEASE=compileClasspath,implementationDependenciesMetadata,jooqGenerator,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
io.sentry:sentry-bom:7.16.0=annotationProcessor,apiDependenciesMetadata,compile,compileClasspath,compileOnlyDependenciesMetadata,developmentOnly,flywayMigration,implementationDependenciesMetadata,intransitiveDependenciesMetadata,jacocoAgent,jacocoAnt,jooqGenerator,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDef,kotlinScriptDefExtensions,productionRuntimeClasspath,runtimeClasspath,testAndDevelopmentOnly,testAnnotationProcessor,testApiDependenciesMetadata,testCompileClasspath,testCompileOnlyDependenciesMetadata,testImplementationDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDef,testKotlinScriptDefExtensions,testRuntimeClasspath
io.sentry:sentry-kotlin-extensions:7.16.0=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
Expand Down Expand Up @@ -314,5 +316,5 @@ org.wildfly.client:wildfly-client-config:1.0.1.Final=compileClasspath,implementa
org.wildfly.common:wildfly-common:1.5.4.Final=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.xmlunit:xmlunit-core:2.9.1=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.yaml:snakeyaml:2.2=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
space.npstr:prometheus_extensions:1.7.1=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
space.npstr:prometheus_extensions:1.10.1=compileClasspath,implementationDependenciesMetadata,productionRuntimeClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
empty=
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ orgJsonVersion=20231013
jaxbImplVersion=[4.0.2, 5.0[
nashornVersion=[15.4, 18[

prometheusVersion=[0.16.0, 1.0[
promExtVersion=[1.6, 1.8[
# for caffeine metrics
prometheusClientVersion=1.3.2
prometheusExtensionsVersion=1.10.1

dsProxyVersion=[1.9, 2.0[
jooqVersion=[3.19.2, 3.20[
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/space/npstr/wolfia/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package space.npstr.wolfia;

import io.prometheus.client.CollectorRegistry;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDAInfo;
Expand Down Expand Up @@ -45,11 +44,6 @@ public class Launcher implements ApplicationRunner {

private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Launcher.class);

static {
// https://github.com/prometheus/client_java/issues/279
CollectorRegistry.defaultRegistry.clear();
}

private final ThreadPoolCollector poolMetrics;
private final WolfiaConfig wolfiaConfig;
@SuppressWarnings({"FieldCanBeLocal", "unused", "squid:S1068"}) //see EagerLoader
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/space/npstr/wolfia/ShutdownHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package space.npstr.wolfia;

import io.prometheus.client.CollectorRegistry;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -149,9 +148,6 @@ private void shutdown() {
//shutdown Redis connection
log.info("Shutting down redis connection");
redis.shutdown();

//avoid trouble with spring dev tools, see https://github.com/prometheus/client_java/issues/279#issuecomment-335817904
CollectorRegistry.defaultRegistry.clear();
}

public void shutdown(int code) {
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/space/npstr/wolfia/commands/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package space.npstr.wolfia.commands;

import io.prometheus.client.Summary;
import io.micrometer.core.instrument.Timer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -53,8 +53,6 @@
import space.npstr.wolfia.utils.discord.RestActions;
import space.npstr.wolfia.utils.discord.TextchatUtils;

import static io.prometheus.client.Summary.Timer;

/**
* Some architectural notes:
* Issued commands will always go through here. It is their own job to find out for which game they have been issued,
Expand Down Expand Up @@ -86,7 +84,7 @@ public CommandHandler(GameRegistry gameRegistry, CommandContextParser commandCon

@EventListener
public void onMessageReceived(MessageReceivedEvent event) {
Timer received = metricsService.commandRetentionTime.startTimer();
Timer.Sample received = Timer.start();
//ignore bot accounts generally
if (event.getAuthor().isBot()) {
return;
Expand Down Expand Up @@ -178,7 +176,7 @@ private List<TextChannel> suggestGameEnabledChannels(CommandContext context) {
/**
* @param context the parsed input of a user
*/
private void handleCommand(CommandContext context, Timer received) {
private void handleCommand(CommandContext context, Timer.Sample received) {
try {
boolean canCallCommand = context.command instanceof PublicCommand || context.isOwner();
if (!canCallCommand) {
Expand All @@ -190,9 +188,12 @@ private void handleCommand(CommandContext context, Timer received) {
log.info("user {}, channel {}, command {} about to be executed",
context.invoker, context.channel, context.msg.getContentRaw());

received.observeDuration();//retention
try (Summary.Timer ignored = metricsService.commandProcessTime.labels(context.command.getClass().getSimpleName()).startTimer()) {
received.stop(metricsService.commandRetentionTime()); //retention
Timer.Sample sample = Timer.start();
try {
context.command.execute(context);
} finally {
sample.stop(metricsService.commandProcessTime(context.command.getClass().getSimpleName()));
}
} catch (UserFriendlyException e) {
context.reply("There was a problem executing your command:\n" + e.getMessage());
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/space/npstr/wolfia/commands/MessageContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package space.npstr.wolfia.commands;

import io.prometheus.client.Collector;
import io.micrometer.core.instrument.Timer;
import java.awt.Color;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import java.util.function.Consumer;
import net.dv8tion.jda.api.EmbedBuilder;
Expand Down Expand Up @@ -180,13 +182,13 @@ public static EmbedBuilder getDefaultEmbedBuilder() {
// ********************************************************************************

private void reply0(MessageCreateData message, @Nullable Consumer<Message> onSuccess) {
long started = System.nanoTime();
Timer.Sample sample = Timer.start();

Consumer<Message> successWrapper = m -> {
metricsService.commandResponseTime.observe((System.nanoTime() - started) / Collector.NANOSECONDS_PER_SECOND);
long in = getMessage().getTimeCreated().toInstant().toEpochMilli();
long out = m.getTimeCreated().toInstant().toEpochMilli();
metricsService.commandTotalTime.observe((out - in) / Collector.MILLISECONDS_PER_SECOND);
sample.stop(metricsService.commandResponseTime());
Instant in = getMessage().getTimeCreated().toInstant();
Instant out = m.getTimeCreated().toInstant();
metricsService.commandTotalTime().record(Duration.between(in, out));
if (onSuccess != null) {
onSuccess.accept(m);
}
Expand Down
38 changes: 11 additions & 27 deletions src/main/java/space/npstr/wolfia/config/MetricsConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@

package space.npstr.wolfia.config;

import ch.qos.logback.classic.LoggerContext;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.cache.caffeine.CacheMetricsCollector;
import io.prometheus.client.logback.InstrumentedAppender;
import io.prometheus.metrics.instrumentation.caffeine.CacheMetricsCollector;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
import java.util.concurrent.ScheduledExecutorService;
import net.dv8tion.jda.api.sharding.ShardManager;
import net.ttddyy.dsproxy.listener.SingleQueryCountHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -38,22 +34,10 @@ public class MetricsConfiguration {

//caffeine cache metrics
@Bean
public CacheMetricsCollector cacheMetrics(CollectorRegistry registry) {
return new CacheMetricsCollector().register(registry);
}

@Bean
public InstrumentedAppender instrumentedAppender(CollectorRegistry registry) {
var instrumentedAppender = new InstrumentedAppender(registry);

// register with logging framework
LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
var root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
instrumentedAppender.setContext(root.getLoggerContext());
instrumentedAppender.start();
root.addAppender(instrumentedAppender);

return instrumentedAppender;
public CacheMetricsCollector cacheMetrics(PrometheusRegistry registry) {
CacheMetricsCollector cacheMetricsCollector = new CacheMetricsCollector();
registry.register(cacheMetricsCollector);
return cacheMetricsCollector;
}

@Bean
Expand All @@ -62,20 +46,20 @@ public SingleQueryCountHolder queryCountHolder() {
}

@Bean
public QueryCountCollector queryCountCollector(SingleQueryCountHolder queryCountHolder, CollectorRegistry registry) {
return new QueryCountCollector(queryCountHolder).register(registry);
public QueryCountCollector queryCountCollector(SingleQueryCountHolder queryCountHolder, PrometheusRegistry registry) {
return new QueryCountCollector(queryCountHolder, registry);
}

@Bean
public ThreadPoolCollector threadPoolCollector(CollectorRegistry registry) {
return new ThreadPoolCollector().register(registry);
public ThreadPoolCollector threadPoolCollector(PrometheusRegistry registry) {
return new ThreadPoolCollector(registry);
}

@Bean
public JdaMetrics jdaMetrics(
ShardManager shardManager,
@Qualifier("jdaThreadPool") ScheduledExecutorService scheduler,
CollectorRegistry registry
PrometheusRegistry registry
) {

return new JdaMetrics(shardManager, scheduler, registry);
Expand Down
Loading

0 comments on commit 8c5cf1f

Please sign in to comment.