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);
}
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"));
}
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())));
}
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())));
}
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())));
}
Aggregations