Search in sources :

Example 16 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class SourceTopicsExtractorTest method setUp.

@Before
public void setUp() {
    metaStore = new MetaStoreImpl(new InternalFunctionRegistry());
    ksqlEngine = KsqlEngineTestUtil.createKsqlEngine(serviceContext, metaStore, new MetricCollectors());
    extractor = new SourceTopicsExtractor(metaStore);
    givenStreamWithTopic(STREAM_TOPIC_1, TOPIC_1);
    givenStreamWithTopic(STREAM_TOPIC_2, TOPIC_2);
}
Also used : MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) Before(org.junit.Before)

Example 17 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class SourceDescriptionFactoryTest method shouldReturnTimestampColumnIfPresent.

@Test
public void shouldReturnTimestampColumnIfPresent() {
    // Given:
    final String kafkaTopicName = "kafka";
    final DataSource dataSource = buildDataSource(kafkaTopicName, Optional.of(new TimestampColumn(ColumnName.of("foo"), Optional.empty())));
    // When
    final SourceDescription sourceDescription = SourceDescriptionFactory.create(dataSource, true, Collections.emptyList(), Collections.emptyList(), Optional.empty(), Collections.emptyList(), Collections.emptyList(), new MetricCollectors());
    // Then:
    assertThat(sourceDescription.getTimestamp(), is("foo"));
}
Also used : MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 18 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class SourceDescriptionFactoryTest method shouldReturnLocalStatsBasedOnKafkaTopic.

@Test
public void shouldReturnLocalStatsBasedOnKafkaTopic() {
    // Given:
    final String kafkaTopicName = "kafka";
    final DataSource dataSource = buildDataSource(kafkaTopicName, Optional.empty());
    final MetricCollectors mock = Mockito.mock(MetricCollectors.class);
    Mockito.when(mock.getAndFormatStatsFor(anyString(), anyBoolean())).thenReturn(mockStringStat);
    Mockito.when(mock.getStatsFor(dataSource.getKafkaTopicName(), true)).thenReturn(errorStats);
    Mockito.when(mock.getStatsFor(dataSource.getKafkaTopicName(), false)).thenReturn(stats);
    KsqlHostInfo localhost = new KsqlHostInfo("myhost", 10);
    // When
    final SourceDescription sourceDescription = SourceDescriptionFactory.create(dataSource, true, Collections.emptyList(), Collections.emptyList(), Optional.empty(), Collections.emptyList(), Collections.emptyList(), Stream.empty(), Stream.empty(), localhost, mock);
    // Then:
    // TODO deprecate and remove
    assertThat(sourceDescription.getStatistics(), containsString(mockStringStat));
    assertThat(sourceDescription.getErrorStats(), containsString(mockStringStat));
    // Also check includes its own stats in cluster stats
    final Stream<QueryHostStat> localStats = stats.stream().map((s) -> QueryHostStat.fromStat(s, new KsqlHostInfoEntity(localhost)));
    assertThat(localStats.collect(Collectors.toList()), everyItem(isIn(sourceDescription.getClusterStatistics())));
    final Stream<QueryHostStat> localErrors = errorStats.stream().map((s) -> QueryHostStat.fromStat(s, new KsqlHostInfoEntity(localhost)));
    assertThat(localErrors.collect(Collectors.toList()), everyItem(isIn(sourceDescription.getClusterErrorStats())));
}
Also used : KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 19 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class SourceDescriptionFactoryTest method testShouldIncludeRemoteStatsIfProvided.

@Test
public void testShouldIncludeRemoteStatsIfProvided() {
    final List<QueryHostStat> remoteStats = IntStream.range(0, 5).boxed().map(x -> new QueryHostStat(new KsqlHostInfoEntity("otherhost:1090"), ConsumerCollector.CONSUMER_MESSAGES_PER_SEC, x, x)).collect(Collectors.toList());
    final List<QueryHostStat> remoteErrors = IntStream.range(0, 5).boxed().map(x -> new QueryHostStat(new KsqlHostInfoEntity("otherhost:1090"), StreamsErrorCollector.CONSUMER_FAILED_MESSAGES_PER_SEC, x, x)).collect(Collectors.toList());
    // Given:
    final String kafkaTopicName = "kafka";
    final DataSource dataSource = buildDataSource(kafkaTopicName, Optional.empty());
    final MetricCollectors mock = Mockito.mock(MetricCollectors.class);
    Mockito.when(mock.getAndFormatStatsFor(anyString(), anyBoolean())).thenReturn(mockStringStat);
    Mockito.when(mock.getStatsFor(dataSource.getKafkaTopicName(), true)).thenReturn(errorStats);
    Mockito.when(mock.getStatsFor(dataSource.getKafkaTopicName(), false)).thenReturn(stats);
    // When
    final SourceDescription sourceDescription = SourceDescriptionFactory.create(dataSource, true, Collections.emptyList(), Collections.emptyList(), Optional.empty(), Collections.emptyList(), Collections.emptyList(), remoteStats.stream(), remoteErrors.stream(), new KsqlHostInfo("myhost", 10), mock);
    // Then:
    assertThat(remoteStats, everyItem(isIn(sourceDescription.getClusterStatistics())));
    assertThat(remoteErrors, everyItem(isIn(sourceDescription.getClusterErrorStats())));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DataSource(io.confluent.ksql.metastore.model.DataSource) IntStream(java.util.stream.IntStream) TopicSensors(io.confluent.ksql.metrics.TopicSensors) ColumnName(io.confluent.ksql.name.ColumnName) SourceName(io.confluent.ksql.name.SourceName) FormatFactory(io.confluent.ksql.serde.FormatFactory) KeyFormat(io.confluent.ksql.serde.KeyFormat) Mock(org.mockito.Mock) Mockito.mockStatic(org.mockito.Mockito.mockStatic) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) Matchers.everyItem(org.hamcrest.Matchers.everyItem) ImmutableList(com.google.common.collect.ImmutableList) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) Matchers.isIn(org.hamcrest.Matchers.isIn) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Test(org.junit.Test) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) ValueFormat(io.confluent.ksql.serde.ValueFormat) Collectors(java.util.stream.Collectors) TimestampColumn(io.confluent.ksql.execution.timestamp.TimestampColumn) Mockito(org.mockito.Mockito) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Stream(java.util.stream.Stream) StreamsErrorCollector(io.confluent.ksql.metrics.StreamsErrorCollector) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Optional(java.util.Optional) FormatInfo(io.confluent.ksql.serde.FormatInfo) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) Collections(java.util.Collections) ConsumerCollector(io.confluent.ksql.metrics.ConsumerCollector) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataSource(io.confluent.ksql.metastore.model.DataSource) Test(org.junit.Test)

Example 20 with MetricCollectors

use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.

the class ListSourceExecutorTest method shouldDescribeTables.

@Test
public void shouldDescribeTables() {
    // Given:
    final KsqlTable<?> table1 = engine.givenSource(DataSourceType.KTABLE, "table1");
    final KsqlTable<?> table2 = engine.givenSource(DataSourceType.KTABLE, "table2", ImmutableSet.of(SourceName.of("table1")));
    engine.givenSource(DataSourceType.KSTREAM, "stream");
    // When:
    final SourceDescriptionList descriptionList = (SourceDescriptionList) CUSTOM_EXECUTORS.describeTables().execute((ConfiguredStatement<DescribeTables>) engine.configure("DESCRIBE TABLES;"), SESSION_PROPERTIES, engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(descriptionList.getSourceDescriptions(), containsInAnyOrder(SourceDescriptionFactory.create(table1, false, ImmutableList.of(), ImmutableList.of(), Optional.of(topicWith1PartitionAndRfOf1), ImmutableList.of(), ImmutableList.of("table2"), new MetricCollectors()), SourceDescriptionFactory.create(table2, false, ImmutableList.of(), ImmutableList.of(), Optional.of(topicWith1PartitionAndRfOf1), ImmutableList.of(), ImmutableList.of(), new MetricCollectors())));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Test(org.junit.Test)

Aggregations

MetricCollectors (io.confluent.ksql.metrics.MetricCollectors)46 Test (org.junit.Test)29 KsqlConfig (io.confluent.ksql.util.KsqlConfig)15 SourceDescriptionList (io.confluent.ksql.rest.entity.SourceDescriptionList)13 Before (org.junit.Before)13 InternalFunctionRegistry (io.confluent.ksql.function.InternalFunctionRegistry)12 MetaStoreImpl (io.confluent.ksql.metastore.MetaStoreImpl)10 DataSource (io.confluent.ksql.metastore.model.DataSource)10 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)10 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)9 ServiceContext (io.confluent.ksql.services.ServiceContext)9 SequentialQueryIdGenerator (io.confluent.ksql.query.id.SequentialQueryIdGenerator)8 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 SourceDescriptionEntity (io.confluent.ksql.rest.entity.SourceDescriptionEntity)7 TestServiceContext (io.confluent.ksql.services.TestServiceContext)7 Collections (java.util.Collections)7 Map (java.util.Map)7 Optional (java.util.Optional)7