Skip to content

Commit

Permalink
Refactor function placements
Browse files Browse the repository at this point in the history
  • Loading branch information
mbiscocho committed Apr 16, 2024
1 parent b04bd14 commit 771d823
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ private void handleRequest(SolrParams params, BiConsumer<String, Object> consume
consumer.accept("error", "metrics collection is disabled");
return;
}
boolean compact = params.getBool(COMPACT_PARAM, true);

Set<String> requestedRegistries = parseRegistries(params);
if (PROMETHEUS_METRICS_WT.equals(params.get(CommonParams.WT))) {
response = handlePrometheusRegistry(params, requestedRegistries);
response = handlePrometheusRegistry(params);
consumer.accept("metrics", response);
return;
}
Expand All @@ -145,20 +143,19 @@ private void handleRequest(SolrParams params, BiConsumer<String, Object> consume
return;
}

response = handleDropwizardRegistry(params, requestedRegistries);
response = handleDropwizardRegistry(params);

consumer.accept("metrics", response);
}

private NamedList<Object> handleDropwizardRegistry(
SolrParams params, Set<String> requestedRegistries) {
private NamedList<Object> handleDropwizardRegistry(SolrParams params) {
boolean compact = params.getBool(COMPACT_PARAM, true);
MetricFilter mustMatchFilter = parseMustMatchFilter(params);
Predicate<CharSequence> propertyFilter = parsePropertyFilter(params);
List<MetricType> metricTypes = parseMetricTypes(params);
List<MetricFilter> metricFilters =
metricTypes.stream().map(MetricType::asMetricFilter).collect(Collectors.toList());
metricTypes.stream().map(MetricType::asMetricFilter).collect(Collectors.toList());
Set<String> requestedRegistries = parseRegistries(params);

NamedList<Object> response = new SimpleOrderedMap<>();
for (String registryName : requestedRegistries) {
Expand All @@ -182,18 +179,18 @@ private NamedList<Object> handleDropwizardRegistry(
return response;
}

private NamedList<Object> handlePrometheusRegistry(
SolrParams params, Set<String> requestedRegistries) {
private NamedList<Object> handlePrometheusRegistry(SolrParams params) {
NamedList<Object> response = new SimpleOrderedMap<>();
boolean compact = params.getBool(COMPACT_PARAM, true);
MetricFilter mustMatchFilter = parseMustMatchFilter(params);
Predicate<CharSequence> propertyFilter = parsePropertyFilter(params);
List<MetricType> metricTypes = parseMetricTypes(params);
List<MetricFilter> metricFilters =
metricTypes.stream().map(MetricType::asMetricFilter).collect(Collectors.toList());
Set<String> requestedRegistries = parseRegistries(params);

for (String registryName : requestedRegistries) {
MetricRegistry dropWizardRegistry = metricManager.registry(registryName);

// Currently only export Solr Core registries
if (registryName.startsWith("solr.core")) {
MetricUtils.toPrometheusRegistry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,6 @@ public Map<String, Gauge> copyOfGauges() {
return ImmutableMap.copyOf(metricGauges);
}

private Counter getMetricCounter(String metricName) {
return metricCounters.get(metricName);
}

private Gauge getMetricGauge(String metricName) {
return metricGauges.get(metricName);
}

private void registerCounter(String metricName, String... labelNames) {
Counter counter =
io.prometheus.metrics.core.metrics.Counter.builder()
.name(metricName)
.labelNames(labelNames)
.register(prometheusRegistry);
metricCounters.put(metricName, counter);
}

private void registerGauge(String metricName, String... labelNames) {
Gauge gauge =
io.prometheus.metrics.core.metrics.Gauge.builder()
.name(metricName)
.labelNames(labelNames)
.register(prometheusRegistry);
metricGauges.put(metricName, gauge);
}

public void exportMeter(
Meter dropwizardMetric, String prometheusMetricName, Map<String, String> labelsMap) {
if (!copyOfCounters().containsKey(prometheusMetricName)) {
Expand All @@ -76,7 +50,7 @@ public void exportMeter(
.inc(dropwizardMetric.getCount());
}

protected void exportCounter(
public void exportCounter(
com.codahale.metrics.Counter dropwizardMetric,
String prometheusMetricName,
Map<String, String> labelsMap) {
Expand Down Expand Up @@ -134,4 +108,30 @@ public void exportGauge(
}
}
}

private Counter getMetricCounter(String metricName) {
return metricCounters.get(metricName);
}

private Gauge getMetricGauge(String metricName) {
return metricGauges.get(metricName);
}

private void registerCounter(String metricName, String... labelNames) {
Counter counter =
io.prometheus.metrics.core.metrics.Counter.builder()
.name(metricName)
.labelNames(labelNames)
.register(prometheusRegistry);
metricCounters.put(metricName, counter);
}

private void registerGauge(String metricName, String... labelNames) {
Gauge gauge =
io.prometheus.metrics.core.metrics.Gauge.builder()
.name(metricName)
.labelNames(labelNames)
.register(prometheusRegistry);
metricGauges.put(metricName, gauge);
}
}

0 comments on commit 771d823

Please sign in to comment.