use of org.apache.kafka.common.metrics.KafkaMetric in project micrometer by micrometer-metrics.
the class KafkaMetricsTest method shouldBindMetersWithSameTags.
@Test
void shouldBindMetersWithSameTags() {
Supplier<Map<MetricName, ? extends Metric>> supplier = () -> {
Map<String, String> firstTags = new LinkedHashMap<>();
firstTags.put("key0", "value0");
MetricName firstName = new MetricName("a", "b", "c", firstTags);
KafkaMetric firstMetric = new KafkaMetric(this, firstName, new Value(), new MetricConfig(), Time.SYSTEM);
Map<String, String> secondTags = new LinkedHashMap<>();
secondTags.put("key0", "value1");
MetricName secondName = new MetricName("a", "b", "c", secondTags);
KafkaMetric secondMetric = new KafkaMetric(this, secondName, new Value(), new MetricConfig(), Time.SYSTEM);
Map<MetricName, KafkaMetric> metrics = new LinkedHashMap<>();
metrics.put(firstName, firstMetric);
metrics.put(secondName, secondMetric);
return metrics;
};
kafkaMetrics = new KafkaMetrics(supplier);
MeterRegistry registry = new SimpleMeterRegistry();
kafkaMetrics.bindTo(registry);
assertThat(registry.getMeters()).hasSize(2);
// version + key0
assertThat(registry.getMeters().get(0).getId().getTags()).hasSize(2);
}
use of org.apache.kafka.common.metrics.KafkaMetric in project micrometer by micrometer-metrics.
the class KafkaMetricsTest method shouldRemoveOlderMeterWithLessTagsWhenCommonTagsConfigured.
@Issue("#1968")
@Test
void shouldRemoveOlderMeterWithLessTagsWhenCommonTagsConfigured() {
// Given
Map<String, String> tags = new LinkedHashMap<>();
Supplier<Map<MetricName, ? extends Metric>> supplier = () -> {
MetricName metricName = new MetricName("a", "b", "c", tags);
KafkaMetric metric = new KafkaMetric(this, metricName, new Value(), new MetricConfig(), Time.SYSTEM);
return Collections.singletonMap(metricName, metric);
};
kafkaMetrics = new KafkaMetrics(supplier);
MeterRegistry registry = new SimpleMeterRegistry();
registry.config().commonTags("common", "value");
kafkaMetrics.bindTo(registry);
assertThat(registry.getMeters()).hasSize(1);
// only version
assertThat(registry.getMeters().get(0).getId().getTags()).containsExactlyInAnyOrder(Tag.of("kafka.version", "unknown"), Tag.of("common", "value"));
tags.put("key0", "value0");
kafkaMetrics.checkAndBindMetrics(registry);
assertThat(registry.getMeters()).hasSize(1);
assertThat(registry.getMeters().get(0).getId().getTags()).containsExactlyInAnyOrder(Tag.of("kafka.version", "unknown"), Tag.of("key0", "value0"), Tag.of("common", "value"));
}
use of org.apache.kafka.common.metrics.KafkaMetric in project ksql by confluentinc.
the class PullQueryMetricsFunctionalTest method shouldVerifyMetrics.
@Test
public void shouldVerifyMetrics() {
// Given:
final KafkaMetric recordsReturnedTableMetric = metrics.metric(recordsReturnedTable);
final KafkaMetric latencyTableMetric = metrics.metric(latencyTable);
final KafkaMetric responseSizeTableMetric = metrics.metric(responseSizeTable);
final KafkaMetric totalRequestsTableMetric = metrics.metric(totalRequestsTable);
final KafkaMetric requestDistributionTableMetric = metrics.metric(requestDistributionTable);
final KafkaMetric recordsReturnedStreamMetric = metrics.metric(recordsReturnedStream);
final KafkaMetric latencyStreamMetric = metrics.metric(latencyStream);
final KafkaMetric responseSizeStreamMetric = metrics.metric(responseSizeStream);
final KafkaMetric totalRequestsStreamMetric = metrics.metric(totalRequestsStream);
final KafkaMetric requestDistributionStreamMetric = metrics.metric(requestDistributionStream);
// When:
final List<StreamedRow> tableRows = RestIntegrationTestUtil.makeQueryRequest(REST_APP, "SELECT COUNT, USERID from " + AGG_TABLE + " WHERE USERID='" + AN_AGG_KEY + "';", Optional.empty());
assertThat(tableRows.size(), is(2));
final List<StreamedRow> streamRows = RestIntegrationTestUtil.makeQueryRequest(REST_APP, "SELECT * from " + PAGE_VIEW_STREAM + " WHERE PAGEID='" + A_STREAM_KEY + "';", Optional.empty());
assertThat(streamRows.size(), is(2));
// Then:
assertThat(recordsReturnedTableMetric.metricValue(), is(1.0));
assertThat((Double) latencyTableMetric.metricValue(), greaterThan(1.0));
assertThat((Double) responseSizeTableMetric.metricValue(), greaterThan(1.0));
assertThat(totalRequestsTableMetric.metricValue(), is(1.0));
assertThat((Double) requestDistributionTableMetric.metricValue(), greaterThan(1.0));
assertThat(recordsReturnedStreamMetric.metricValue(), is(1.0));
assertThat((Double) latencyStreamMetric.metricValue(), greaterThan(1.0));
assertThat((Double) responseSizeStreamMetric.metricValue(), greaterThan(1.0));
assertThat(totalRequestsStreamMetric.metricValue(), is(1.0));
assertThat((Double) requestDistributionStreamMetric.metricValue(), greaterThan(1.0));
}
use of org.apache.kafka.common.metrics.KafkaMetric in project ksql by confluentinc.
the class PullQueryMetricsWSFunctionalTest method shouldVerifyMetrics.
@Test
public void shouldVerifyMetrics() {
// Given:
final KafkaMetric recordsReturnedTableMetric = metrics.metric(recordsReturnedTable);
final KafkaMetric latencyTableMetric = metrics.metric(latencyTable);
final KafkaMetric totalRequestsTableMetric = metrics.metric(totalRequestsTable);
final KafkaMetric requestDistributionTableMetric = metrics.metric(requestDistributionTable);
final KafkaMetric recordsReturnedStreamMetric = metrics.metric(recordsReturnedStream);
final KafkaMetric latencyStreamMetric = metrics.metric(latencyStream);
final KafkaMetric totalRequestsStreamMetric = metrics.metric(totalRequestsStream);
final KafkaMetric requestDistributionStreamMetric = metrics.metric(requestDistributionStream);
// When:
RestIntegrationTestUtil.makeWsRequest(REST_APP.getWsListener(), "SELECT COUNT, USERID from " + AGG_TABLE + " WHERE USERID='" + AN_AGG_KEY + "';", Optional.of(MediaType.APPLICATION_JSON), Optional.of(MediaType.APPLICATION_JSON), Optional.of(SUPER_USER), Optional.empty(), Optional.empty());
RestIntegrationTestUtil.makeWsRequest(REST_APP.getWsListener(), "SELECT * from " + PAGE_VIEW_STREAM + " WHERE PAGEID='" + A_STREAM_KEY + "';", Optional.of(MediaType.APPLICATION_JSON), Optional.of(MediaType.APPLICATION_JSON), Optional.of(SUPER_USER), Optional.empty(), Optional.empty());
// Then:
assertThat(recordsReturnedTableMetric.metricValue(), is(1.0));
assertThat((Double) latencyTableMetric.metricValue(), greaterThan(1.0));
assertThat(totalRequestsTableMetric.metricValue(), is(1.0));
assertThat((Double) requestDistributionTableMetric.metricValue(), greaterThan(1.0));
assertThat(recordsReturnedStreamMetric.metricValue(), is(1.0));
assertThat((Double) latencyStreamMetric.metricValue(), greaterThan(1.0));
assertThat(totalRequestsStreamMetric.metricValue(), is(1.0));
assertThat((Double) requestDistributionStreamMetric.metricValue(), greaterThan(1.0));
}
use of org.apache.kafka.common.metrics.KafkaMetric in project ksql by confluentinc.
the class PullQueryMetricsHttp2FunctionalTest method shouldVerifyMetrics.
@Test
public void shouldVerifyMetrics() {
// Given:
final KafkaMetric recordsReturnedTableMetric = metrics.metric(recordsReturnedTable);
final KafkaMetric latencyTableMetric = metrics.metric(latencyTable);
final KafkaMetric responseSizeTableMetric = metrics.metric(responseSizeTable);
final KafkaMetric totalRequestsTableMetric = metrics.metric(totalRequestsTable);
final KafkaMetric requestDistributionTableMetric = metrics.metric(requestDistributionTable);
final KafkaMetric recordsReturnedStreamMetric = metrics.metric(recordsReturnedStream);
final KafkaMetric latencyStreamMetric = metrics.metric(latencyStream);
final KafkaMetric responseSizeStreamMetric = metrics.metric(responseSizeStream);
final KafkaMetric totalRequestsStreamMetric = metrics.metric(totalRequestsStream);
final KafkaMetric requestDistributionStreamMetric = metrics.metric(requestDistributionStream);
// When:
final String sqlTable = "SELECT COUNT, USERID from " + AGG_TABLE + " WHERE USERID='" + AN_AGG_KEY + "';";
QueryResponse queryResponse1 = executeQuery(sqlTable);
assertThat(queryResponse1.rows, hasSize(1));
final String sqlStream = "SELECT * from " + PAGE_VIEW_STREAM + " WHERE PAGEID='" + A_STREAM_KEY + "';";
QueryResponse queryResponse2 = executeQuery(sqlStream);
assertThat(queryResponse2.rows, hasSize(1));
// Then:
assertThat(recordsReturnedTableMetric.metricValue(), is(1.0));
assertThat((Double) latencyTableMetric.metricValue(), greaterThan(1.0));
assertThat((Double) responseSizeTableMetric.metricValue(), greaterThan(1.0));
assertThat(totalRequestsTableMetric.metricValue(), is(1.0));
assertThat((Double) requestDistributionTableMetric.metricValue(), greaterThan(1.0));
assertThat(recordsReturnedStreamMetric.metricValue(), is(1.0));
assertThat((Double) latencyStreamMetric.metricValue(), greaterThan(1.0));
assertThat((Double) responseSizeStreamMetric.metricValue(), greaterThan(1.0));
assertThat(totalRequestsStreamMetric.metricValue(), is(1.0));
assertThat((Double) requestDistributionStreamMetric.metricValue(), greaterThan(1.0));
}
Aggregations