Skip to content

Commit

Permalink
fix: change metrics tag (#8268)
Browse files Browse the repository at this point in the history
(cherry picked from commit caded5a)
  • Loading branch information
wcarlson5 committed Oct 20, 2021
1 parent 21f4e03 commit ff277ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,21 @@ private static class PerQueryListener {
this.metrics = Objects.requireNonNull(metrics, "metrics cannot be null.");
this.ticker = Objects.requireNonNull(ticker, "ticker");

final String type = queryId.toLowerCase().contains("transient") ? "transient_" : "query_" ;

final String tag = "_confluent-ksql-" + groupPrefix + type + queryId;

this.stateMetricName = metrics.metricName(
"query-status",
groupPrefix + "ksql-queries",
"The current status of the given query.",
Collections.singletonMap("status", queryId));
Collections.singletonMap("status", tag));

errorMetricName = metrics.metricName(
"error-status",
groupPrefix + "ksql-queries",
"The current error status of the given query, if the state is in ERROR state",
Collections.singletonMap("status", queryId)
Collections.singletonMap("status", tag)
);
this.metrics.addMetric(stateMetricName, (Gauge<String>) (config, now) -> state);
this.metrics.addMetric(errorMetricName, (Gauge<String>) (config, now) -> error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class QueryStateMetricsReportingListenerTest {
private static final MetricName METRIC_NAME_2 =
new MetricName("dylan", "g1", "d1", ImmutableMap.of());
private static final QueryId QUERY_ID = new QueryId("foo");
private static final String TAG = "_confluent-ksql-" + "some-prefix-" + "query_" + QUERY_ID.toString();

@Mock
private Metrics metrics;
Expand All @@ -73,7 +74,7 @@ public void setUp() {
.thenReturn(METRIC_NAME_2);
when(query.getQueryId()).thenReturn(QUERY_ID);

listener = new QueryStateMetricsReportingListener(metrics, "");
listener = new QueryStateMetricsReportingListener(metrics, "some-prefix-");
}

@Test
Expand All @@ -87,12 +88,12 @@ public void shouldAddMetricOnCreation() {
listener.onCreate(serviceContext, metaStore, query);

// Then:
verify(metrics).metricName("query-status", "ksql-queries",
verify(metrics).metricName("query-status", "some-prefix-ksql-queries",
"The current status of the given query.",
ImmutableMap.of("status", QUERY_ID.toString()));
verify(metrics).metricName("error-status", "ksql-queries",
ImmutableMap.of("status", TAG));
verify(metrics).metricName("error-status", "some-prefix-ksql-queries",
"The current error status of the given query, if the state is in ERROR state",
ImmutableMap.of("status", QUERY_ID.toString()));
ImmutableMap.of("status", TAG));

verify(metrics).addMetric(eq(METRIC_NAME_1), isA(Gauge.class));
verify(metrics).addMetric(eq(METRIC_NAME_2), isA(Gauge.class));
Expand Down Expand Up @@ -132,10 +133,10 @@ public void shouldAddMetricWithSuppliedPrefix() {
// Then:
verify(metrics).metricName("query-status", groupPrefix + "ksql-queries",
"The current status of the given query.",
ImmutableMap.of("status", QUERY_ID.toString()));
ImmutableMap.of("status", TAG));
verify(metrics).metricName("error-status", groupPrefix + "ksql-queries",
"The current error status of the given query, if the state is in ERROR state",
ImmutableMap.of("status", QUERY_ID.toString()));
ImmutableMap.of("status", TAG));
}

@Test
Expand Down

0 comments on commit ff277ba

Please sign in to comment.