Skip to content

SOLR-17458: Give request handler base errors its own metric #3415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions solr/core/src/java/org/apache/solr/handler/RequestHandlerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,39 +223,45 @@ public HandlerMetrics(
var baseRequestMetric =
solrMetricsContext.longCounter("solr_metrics_core_requests", "HTTP Solr request counts");

var baseErrorRequestMetric =
solrMetricsContext.longCounter(
"solr_metrics_core_requests_errors", "HTTP Solr request error counts");

var baseRequestTimeMetric =
solrMetricsContext.longHistogram(
"solr_metrics_core_requests_times", "HTTP Solr request times", "ms");

otelRequests =
new AttributedLongCounter(
baseRequestMetric,
Attributes.builder().putAll(attributes).put(TYPE_ATTR, "requests").build());
baseRequestMetric, Attributes.builder().putAll(attributes).build());

otelNumServerErrors =
new AttributedLongCounter(
baseRequestMetric,
baseErrorRequestMetric,
Attributes.builder()
.putAll(attributes)
.put(AttributeKey.stringKey("source"), "server")
.put(TYPE_ATTR, "errors")
.build());

otelNumClientErrors =
new AttributedLongCounter(
baseRequestMetric,
baseErrorRequestMetric,
Attributes.builder()
.putAll(attributes)
.put(AttributeKey.stringKey("source"), "client")
.put(TYPE_ATTR, "errors")
.build());

otelNumTimeouts =
new AttributedLongCounter(
baseRequestMetric,
baseErrorRequestMetric,
Attributes.builder().putAll(attributes).put(TYPE_ATTR, "timeouts").build());

otelRequestTimes = new AttributedLongTimer(baseRequestTimeMetric, attributes);
// NOCOMMIT: Temporary to see metrics
otelRequests.add(0L);
otelNumTimeouts.add(0L);
otelNumClientErrors.add(0L);
otelNumServerErrors.add(0L);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.solr.handler;

import static org.apache.solr.metrics.SolrMetricProducer.TYPE_ATTR;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -80,11 +79,7 @@ public void testEachNonSolrExceptionIncrementsTheServerErrorCount() {

verify(mockLongCounter, never())
.add(
eq(1L),
argThat(
attrs ->
"errors".equals(attrs.get(TYPE_ATTR))
&& "source".equals(attrs.get(AttributeKey.stringKey("client")))));
eq(1L), argThat(attrs -> "source".equals(attrs.get(AttributeKey.stringKey("client")))));
}

@Test
Expand All @@ -95,19 +90,9 @@ public void test409SolrExceptionsSkipMetricRecording() {
RequestHandlerBase.processErrorMetricsOnException(e, metrics);

verify(mockLongCounter, never())
.add(
eq(1L),
argThat(
attrs ->
"errors".equals(attrs.get(TYPE_ATTR))
&& "client".equals(attrs.get(SOURCE_ATTR))));
.add(eq(1L), argThat(attrs -> "client".equals(attrs.get(SOURCE_ATTR))));
verify(mockLongCounter, never())
.add(
eq(1L),
argThat(
attrs ->
"errors".equals(attrs.get(TYPE_ATTR))
&& "server".equals(attrs.get(SOURCE_ATTR))));
.add(eq(1L), argThat(attrs -> "server".equals(attrs.get(SOURCE_ATTR))));
}

@Test
Expand All @@ -118,20 +103,10 @@ public void testEach4xxSolrExceptionIncrementsTheClientErrorCount() {
RequestHandlerBase.processErrorMetricsOnException(e, metrics);

verify(mockLongCounter, times(1))
.add(
eq(1L),
argThat(
attrs ->
"errors".equals(attrs.get(TYPE_ATTR))
&& "client".equals(attrs.get(SOURCE_ATTR))));
.add(eq(1L), argThat(attrs -> "client".equals(attrs.get(SOURCE_ATTR))));

verify(mockLongCounter, never())
.add(
eq(1L),
argThat(
attrs ->
"errors".equals(attrs.get(TYPE_ATTR))
&& "server".equals(attrs.get(SOURCE_ATTR))));
.add(eq(1L), argThat(attrs -> "server".equals(attrs.get(SOURCE_ATTR))));
}

@Test
Expand Down