Skip to content

Commit

Permalink
Fix Kafka app-info in native
Browse files Browse the repository at this point in the history
Call registerMetrics in AppInfoParser substitution

Fixes quarkusio#42865

(cherry picked from commit 4ea2ff1)
  • Loading branch information
ozangunalp authored and gsmet committed Sep 3, 2024
1 parent 671dc16 commit dad0ce0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,9 @@ public void build(
BuildProducer<NativeImageProxyDefinitionBuildItem> proxies,
Capabilities capabilities,
BuildProducer<UnremovableBeanBuildItem> beans,
BuildProducer<NativeImageResourceBuildItem> nativeLibs,
BuildProducer<ExtensionSslNativeSupportBuildItem> sslNativeSupport) {
final Set<DotName> toRegister = new HashSet<>();

nativeLibs.produce(new NativeImageResourceBuildItem("kafka/kafka-version.properties"));
collectImplementors(toRegister, indexBuildItem, Serializer.class);
collectImplementors(toRegister, indexBuildItem, Deserializer.class);
collectImplementors(toRegister, indexBuildItem, Partitioner.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.kafka.common.metrics.Metrics;
import org.apache.kafka.common.utils.AppInfoParser;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

Expand All @@ -21,14 +22,20 @@ final class RemoveJMXAccess {

@Substitute
public static synchronized void registerAppInfo(String prefix, String id, Metrics metrics, long nowMs) {

registerMetrics(metrics, new AppInfoParser.AppInfo(nowMs));
}

@Substitute
public static synchronized void unregisterAppInfo(String prefix, String id, Metrics metrics) {

unregisterMetrics(metrics);
}

@Alias
private native static void registerMetrics(Metrics metrics, AppInfoParser.AppInfo appInfo);

@Alias
private native static void unregisterMetrics(Metrics metrics);

}

@TargetClass(value = JmxReporter.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -121,7 +122,9 @@ void testPrometheusScrapeEndpointOpenMetrics() {
.body(containsString("quarkus_messaging_message_duration_seconds_sum"))
.body(containsString("quarkus_messaging_message_duration_seconds_count"))
.body(containsString("quarkus_messaging_message_count_total"))
.body(containsString("quarkus_messaging_message_acks_total"));
.body(containsString("quarkus_messaging_message_acks_total"))
.body(containsString("kafka_app_info_start_time_ms"))
.body(not(containsString("kafka_version=\"unknown\"")));
}

}

0 comments on commit dad0ce0

Please sign in to comment.