Skip to content

Commit

Permalink
Address more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mlbiscoc committed Dec 22, 2024
1 parent 3ae9106 commit b700157
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ private List<MetricType> parseMetricTypes(SolrParams params) {

private String getCoreNameFromRegistry(String registryName) {
String coreName = registryName.substring(registryName.indexOf('.') + 1);
return coreName.replaceAll("\\.", "_");
return coreName.replace(".", "_");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.solr.metrics.prometheus.core;

import java.util.regex.Pattern;

public interface PrometheusCoreFormatterInfo {
/** Category of prefix Solr Core dropwizard handler metric names */
enum CoreCategory {
Expand All @@ -32,9 +30,4 @@ enum CoreCategory {
INDEX,
CORE
}

Pattern CLOUD_CORE_PATTERN =
Pattern.compile(
"(?<core>^core_(?<collection>.*)_(?<shard>shard[0-9]+)_(?<replica>replica_.[0-9]+)).(.*)$");
Pattern STANDALONE_CORE_PATTERN = Pattern.compile("^core_(?<core>.*?)\\.(.*)$");
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,37 @@
*/
package org.apache.solr.metrics.prometheus.core;

import static org.apache.solr.metrics.prometheus.core.PrometheusCoreFormatterInfo.CLOUD_CORE_PATTERN;
import static org.apache.solr.metrics.prometheus.core.PrometheusCoreFormatterInfo.STANDALONE_CORE_PATTERN;

import com.codahale.metrics.Metric;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.solr.common.SolrException;
import org.apache.solr.metrics.prometheus.SolrMetric;

/** Base class is a wrapper to export a solr.core {@link com.codahale.metrics.Metric} */
public abstract class SolrCoreMetric extends SolrMetric {

public static Pattern CLOUD_CORE_PATTERN =
Pattern.compile(
"(?<core>^core_(?<collection>.*)_(?<shard>shard[0-9]+)_(?<replica>replica_.[0-9]+)).(.*)$");
public static Pattern STANDALONE_CORE_PATTERN = Pattern.compile("^core_(?<core>.*?)\\.(.*)$");

public String coreName;

public SolrCoreMetric(Metric dropwizardMetric, String metricName) {
// Remove Core Name prefix from metric as it is no longer needed for tag parsing from this point
super(dropwizardMetric, metricName.substring(metricName.indexOf(".") + 1));
Matcher cloudPattern = CLOUD_CORE_PATTERN.matcher(metricName);
Matcher standalonePattern = STANDALONE_CORE_PATTERN.matcher(metricName);
if (cloudPattern.find()) {
coreName = cloudPattern.group("core");
labels.put("core", cloudPattern.group("core"));
labels.put("collection", cloudPattern.group("collection"));
labels.put("shard", cloudPattern.group("shard"));
labels.put("replica", cloudPattern.group("replica"));
cloudPattern
.namedGroups()
.forEach((key, value) -> labels.put(key, cloudPattern.group(value)));
} else if (standalonePattern.find()) {
coreName = standalonePattern.group("core");
labels.put("core", standalonePattern.group("core"));
standalonePattern
.namedGroups()
.forEach((key, value) -> labels.put(key, standalonePattern.group(value)));
} else {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package org.apache.solr.metrics;

import static org.apache.solr.metrics.prometheus.core.PrometheusCoreFormatterInfo.CLOUD_CORE_PATTERN;
import static org.apache.solr.metrics.prometheus.core.PrometheusCoreFormatterInfo.STANDALONE_CORE_PATTERN;
import static org.apache.solr.metrics.prometheus.core.SolrCoreMetric.CLOUD_CORE_PATTERN;
import static org.apache.solr.metrics.prometheus.core.SolrCoreMetric.STANDALONE_CORE_PATTERN;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
Expand Down

0 comments on commit b700157

Please sign in to comment.