madrob commented on a change in pull request #657:
URL: https://github.com/apache/solr/pull/657#discussion_r811455653



##########
File path: solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java
##########
@@ -154,23 +138,50 @@ public SolrMetricsContext getSolrMetricsContext() {
   @Override
   public void initializeMetrics(SolrMetricsContext parentContext, String 
scope) {
     this.solrMetricsContext = parentContext.getChildContext(this);
-    numErrors = solrMetricsContext.meter("errors", getCategory().toString(), 
scope);
-    numServerErrors = solrMetricsContext.meter("serverErrors", 
getCategory().toString(), scope);
-    numClientErrors = solrMetricsContext.meter("clientErrors", 
getCategory().toString(), scope);
-    numTimeouts = solrMetricsContext.meter("timeouts", 
getCategory().toString(), scope);
-    requests = solrMetricsContext.counter("requests", 
getCategory().toString(), scope);
-    MetricsMap metricsMap = new MetricsMap(map ->
-        shardPurposes.forEach((k, v) -> map.putNoEx(k, v.getCount())));
-    solrMetricsContext.gauge(metricsMap, true, "shardRequests", 
getCategory().toString(), scope);
-    requestTimes = solrMetricsContext.timer("requestTimes", 
getCategory().toString(), scope);
-    distribRequestTimes = solrMetricsContext.timer("requestTimes", 
getCategory().toString(), scope, "distrib");
-    localRequestTimes = solrMetricsContext.timer("requestTimes", 
getCategory().toString(), scope, "local");
-    totalTime = solrMetricsContext.counter("totalTime", 
getCategory().toString(), scope);
-    distribTotalTime = solrMetricsContext.counter("totalTime", 
getCategory().toString(), scope, "distrib");
-    localTotalTime = solrMetricsContext.counter("totalTime", 
getCategory().toString(), scope, "local");
+    metrics = new RhMetrics(solrMetricsContext, getCategory().toString(), 
scope);
+    if (supportsDistribedRequests()) {
+      metricsShard = new RhMetrics(solrMetricsContext, 
getCategory().toString(), scope + "[shard]");
+    }
     solrMetricsContext.gauge(() -> handlerStart, true, "handlerStart", 
getCategory().toString(), scope);
   }
 
+  /**
+   * Does this handler receive per-shard (or similar) requests contributing to 
larger request?
+   * This is used to track metrics separately.
+   * @see ShardParams#IS_SHARD
+   */
+  protected boolean supportsDistribedRequests() {
+    return false;
+  }
+
+  protected static class RhMetrics {

Review comment:
       What does Rh mean in this context?

##########
File path: solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java
##########
@@ -154,23 +138,50 @@ public SolrMetricsContext getSolrMetricsContext() {
   @Override
   public void initializeMetrics(SolrMetricsContext parentContext, String 
scope) {
     this.solrMetricsContext = parentContext.getChildContext(this);
-    numErrors = solrMetricsContext.meter("errors", getCategory().toString(), 
scope);
-    numServerErrors = solrMetricsContext.meter("serverErrors", 
getCategory().toString(), scope);
-    numClientErrors = solrMetricsContext.meter("clientErrors", 
getCategory().toString(), scope);
-    numTimeouts = solrMetricsContext.meter("timeouts", 
getCategory().toString(), scope);
-    requests = solrMetricsContext.counter("requests", 
getCategory().toString(), scope);
-    MetricsMap metricsMap = new MetricsMap(map ->
-        shardPurposes.forEach((k, v) -> map.putNoEx(k, v.getCount())));
-    solrMetricsContext.gauge(metricsMap, true, "shardRequests", 
getCategory().toString(), scope);
-    requestTimes = solrMetricsContext.timer("requestTimes", 
getCategory().toString(), scope);
-    distribRequestTimes = solrMetricsContext.timer("requestTimes", 
getCategory().toString(), scope, "distrib");
-    localRequestTimes = solrMetricsContext.timer("requestTimes", 
getCategory().toString(), scope, "local");
-    totalTime = solrMetricsContext.counter("totalTime", 
getCategory().toString(), scope);
-    distribTotalTime = solrMetricsContext.counter("totalTime", 
getCategory().toString(), scope, "distrib");
-    localTotalTime = solrMetricsContext.counter("totalTime", 
getCategory().toString(), scope, "local");
+    metrics = new RhMetrics(solrMetricsContext, getCategory().toString(), 
scope);
+    if (supportsDistribedRequests()) {
+      metricsShard = new RhMetrics(solrMetricsContext, 
getCategory().toString(), scope + "[shard]");
+    }
     solrMetricsContext.gauge(() -> handlerStart, true, "handlerStart", 
getCategory().toString(), scope);
   }
 
+  /**
+   * Does this handler receive per-shard (or similar) requests contributing to 
larger request?
+   * This is used to track metrics separately.
+   * @see ShardParams#IS_SHARD
+   */
+  protected boolean supportsDistribedRequests() {
+    return false;
+  }
+
+  protected static class RhMetrics {
+    static final RhMetrics NO_OP;
+    static {
+      var metricsConfig = new 
MetricsConfig.MetricsConfigBuilder().setEnabled(false).build();
+      var ctx = new SolrMetricsContext(new SolrMetricManager(null, 
metricsConfig), "dummy", "dummy");
+      NO_OP = new RhMetrics(ctx, "dummy", "dummy");

Review comment:
       Why does path need two elements here?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to