Search in sources :

Example 61 with KafkaMetric

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);
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) MetricName(org.apache.kafka.common.MetricName) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Value(org.apache.kafka.common.metrics.stats.Value) Metric(org.apache.kafka.common.Metric) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 62 with KafkaMetric

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"));
}
Also used : MetricConfig(org.apache.kafka.common.metrics.MetricConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) LinkedHashMap(java.util.LinkedHashMap) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) MetricName(org.apache.kafka.common.MetricName) Value(org.apache.kafka.common.metrics.stats.Value) Metric(org.apache.kafka.common.Metric) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Issue(io.micrometer.core.Issue) Test(org.junit.jupiter.api.Test)

Example 63 with KafkaMetric

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));
}
Also used : StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 64 with KafkaMetric

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));
}
Also used : KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Example 65 with KafkaMetric

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));
}
Also used : QueryResponse(io.confluent.ksql.api.utils.QueryResponse) KafkaMetric(org.apache.kafka.common.metrics.KafkaMetric) Test(org.junit.Test)

Aggregations

KafkaMetric (org.apache.kafka.common.metrics.KafkaMetric)129 Test (org.junit.Test)84 MetricName (org.apache.kafka.common.MetricName)59 HashMap (java.util.HashMap)30 LinkedHashMap (java.util.LinkedHashMap)24 Test (org.junit.jupiter.api.Test)23 Map (java.util.Map)18 MetricConfig (org.apache.kafka.common.metrics.MetricConfig)16 Metric (org.apache.kafka.common.Metric)15 MemoryRecordsBuilder (org.apache.kafka.common.record.MemoryRecordsBuilder)14 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)13 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)12 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)12 Value (org.apache.kafka.common.metrics.stats.Value)12 Windowed (org.apache.kafka.streams.kstream.Windowed)12 Sensor (org.apache.kafka.common.metrics.Sensor)11 TopicPartition (org.apache.kafka.common.TopicPartition)10 Metrics (org.apache.kafka.common.metrics.Metrics)10 List (java.util.List)8 Cluster (org.apache.kafka.common.Cluster)8