Skip to content

Commit

Permalink
Refactor BuildInfoCollector (apache#22956)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Dec 18, 2022
1 parent 4b9e47a commit 000b85b
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import io.prometheus.client.Collector;
import io.prometheus.client.GaugeMetricFamily;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.agent.metrics.core.constant.MetricIds;
import org.apache.shardingsphere.agent.metrics.prometheus.wrapper.PrometheusWrapperFactory;
import org.apache.shardingsphere.proxy.Bootstrap;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -35,13 +35,10 @@
@RequiredArgsConstructor
public final class BuildInfoCollector extends Collector {

private static final String PROXY_BOOTSTRAP_CLASS = "org.apache.shardingsphere.proxy.Bootstrap";

private static final PrometheusWrapperFactory FACTORY = new PrometheusWrapperFactory();

private final boolean isEnhancedForProxy;

@SneakyThrows(ClassNotFoundException.class)
@Override
public List<MetricFamilySamples> collect() {
Optional<GaugeMetricFamily> artifactInfo = FACTORY.createGaugeMetricFamily(MetricIds.BUILD_INFO);
Expand All @@ -50,7 +47,7 @@ public List<MetricFamilySamples> collect() {
}
addMetric(artifactInfo.get(), getClass().getPackage());
if (isEnhancedForProxy) {
addMetric(artifactInfo.get(), Class.forName(PROXY_BOOTSTRAP_CLASS).getPackage());
addMetric(artifactInfo.get(), Bootstrap.class.getPackage());
}
return Collections.singletonList(artifactInfo.get());
}
Expand Down

0 comments on commit 000b85b

Please sign in to comment.