use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.
the class DescribeConnectorExecutorTest method setUp.
@Before
public void setUp() {
final MetricCollectors metricCollectors = new MetricCollectors();
when(engine.getMetaStore()).thenReturn(metaStore);
when(engine.metricCollectors()).thenReturn(metricCollectors);
when(serviceContext.getConnectClient()).thenReturn(connectClient);
when(metaStore.getAllDataSources()).thenReturn(ImmutableMap.of(SourceName.of("source"), source));
when(source.getKafkaTopicName()).thenReturn(TOPIC);
when(source.getSqlExpression()).thenReturn(STATEMENT);
when(source.getKsqlTopic()).thenReturn(new KsqlTopic(TOPIC, KeyFormat.nonWindowed(FormatInfo.of(FormatFactory.AVRO.name()), SerdeFeatures.of()), ValueFormat.of(FormatInfo.of(FormatFactory.AVRO.name()), SerdeFeatures.of())));
when(source.getSchema()).thenReturn(LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("foo"), SqlPrimitiveType.of(SqlBaseType.STRING)).build());
when(source.getDataSourceType()).thenReturn(DataSourceType.KTABLE);
when(source.getName()).thenReturn(SourceName.of("source"));
when(connectClient.status(CONNECTOR_NAME)).thenReturn(ConnectResponse.success(STATUS, HttpStatus.SC_OK));
when(connectClient.describe("connector")).thenReturn(ConnectResponse.success(INFO, HttpStatus.SC_OK));
connectorFactory = info -> Optional.of(connector);
executor = new DescribeConnectorExecutor(connectorFactory, new DefaultConnectServerErrors());
final DescribeConnector describeConnector = new DescribeConnector(Optional.empty(), "connector");
final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
describeStatement = ConfiguredStatement.of(PreparedStatement.of("statementText", describeConnector), SessionConfig.of(ksqlConfig, ImmutableMap.of()));
}
use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.
the class StandaloneExecutorTest method shouldStartTheVersionCheckerAgentWithCorrectProperties.
@Test
public void shouldStartTheVersionCheckerAgentWithCorrectProperties() throws InterruptedException {
// Given:
final ArgumentCaptor<Properties> captor = ArgumentCaptor.forClass(Properties.class);
final StandaloneExecutor standaloneExecutor = new StandaloneExecutor(serviceContext, processingLogConfig, new KsqlConfig(ImmutableMap.of("confluent.support.metrics.enable", false)), ksqlEngine, queriesFile.toString(), udfLoader, false, versionChecker, injectorFactory, new MetricCollectors());
// When:
standaloneExecutor.startAsync();
// Then:
verify(versionChecker).start(eq(KsqlModuleType.SERVER), captor.capture());
assertThat(captor.getValue().getProperty("confluent.support.metrics.enable"), equalTo("false"));
standaloneExecutor.shutdown();
}
use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.
the class KsqlResourceTest method shouldShowStreamsExtended.
@Test
public void shouldShowStreamsExtended() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(ColumnName.of("FIELD1"), SqlTypes.BOOLEAN).valueColumn(ColumnName.of("FIELD2"), SqlTypes.STRING).build();
givenSource(DataSourceType.KSTREAM, "new_stream", "new_topic", schema);
// When:
final SourceDescriptionList descriptionList = makeSingleRequest("SHOW STREAMS EXTENDED;", SourceDescriptionList.class);
// Then:
assertThat(descriptionList.getSourceDescriptions(), containsInAnyOrder(SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("TEST_STREAM")), true, Collections.emptyList(), Collections.emptyList(), Optional.of(kafkaTopicClient.describeTopic("KAFKA_TOPIC_2")), Collections.emptyList(), Collections.emptyList(), new MetricCollectors()), SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("new_stream")), true, Collections.emptyList(), Collections.emptyList(), Optional.of(kafkaTopicClient.describeTopic("new_topic")), Collections.emptyList(), Collections.emptyList(), new MetricCollectors())));
}
use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.
the class KsqlResourceTest method setUp.
@Before
public void setUp() throws IOException, RestClientException {
commandStatus = new QueuedCommandStatus(0, new CommandStatusFuture(new CommandId(TOPIC, "whateva", CREATE)));
commandStatus1 = new QueuedCommandStatus(1, new CommandStatusFuture(new CommandId(TABLE, "something", DROP)));
final QueuedCommandStatus commandStatus2 = new QueuedCommandStatus(2, new CommandStatusFuture(new CommandId(STREAM, "something", EXECUTE)));
kafkaTopicClient = new FakeKafkaTopicClient();
kafkaConsumerGroupClient = new FakeKafkaConsumerGroupClient();
serviceContext = TestServiceContext.create(kafkaTopicClient, kafkaConsumerGroupClient);
schemaRegistryClient = serviceContext.getSchemaRegistryClient();
registerValueSchema(schemaRegistryClient);
ksqlRestConfig = new KsqlRestConfig(getDefaultKsqlConfig());
ksqlConfig = new KsqlConfig(ksqlRestConfig.getKsqlConfigProperties());
final KsqlExecutionContext.ExecuteResult result = mock(KsqlExecutionContext.ExecuteResult.class);
when(sandbox.execute(any(), any(ConfiguredKsqlPlan.class))).thenReturn(result);
when(result.getQuery()).thenReturn(Optional.empty());
MutableFunctionRegistry fnRegistry = new InternalFunctionRegistry();
final Metrics metrics = new Metrics();
UserFunctionLoader.newInstance(ksqlConfig, fnRegistry, ".", metrics).load();
metaStore = new MetaStoreImpl(fnRegistry);
final MetricCollectors metricCollectors = new MetricCollectors(metrics);
realEngine = KsqlEngineTestUtil.createKsqlEngine(serviceContext, metaStore, (engine) -> new KsqlEngineMetrics("", engine, Collections.emptyMap(), Optional.empty(), metricCollectors), new SequentialQueryIdGenerator(), ksqlConfig, metricCollectors);
securityContext = new KsqlSecurityContext(Optional.empty(), serviceContext);
when(commandRunner.getCommandQueue()).thenReturn(commandStore);
when(commandRunnerWarning.get()).thenReturn("");
when(commandStore.createTransactionalProducer()).thenReturn(transactionalProducer);
ksqlEngine = realEngine;
when(sandbox.getMetaStore()).thenAnswer(inv -> metaStore.copy());
addTestTopicAndSources();
when(commandStore.enqueueCommand(any(), any(), any(Producer.class))).thenReturn(commandStatus).thenReturn(commandStatus1).thenReturn(commandStatus2);
streamName = KsqlIdentifierTestUtil.uniqueIdentifierName();
when(schemaInjectorFactory.apply(any())).thenReturn(sandboxSchemaInjector);
when(schemaInjectorFactory.apply(serviceContext)).thenReturn(schemaInjector);
when(topicInjectorFactory.apply(any())).thenReturn(sandboxTopicInjector);
when(topicInjectorFactory.apply(ksqlEngine)).thenReturn(topicInjector);
when(sandboxSchemaInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(schemaInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(sandboxTopicInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(topicInjector.inject(any())).thenAnswer(inv -> inv.getArgument(0));
when(errorsHandler.generateResponse(any(), any())).thenAnswer(new Answer<EndpointResponse>() {
@Override
public EndpointResponse answer(final InvocationOnMock invocation) throws Throwable {
final Object[] args = invocation.getArguments();
return (EndpointResponse) args[1];
}
});
setUpKsqlResource();
}
use of io.confluent.ksql.metrics.MetricCollectors in project ksql by confluentinc.
the class KsqlResourceTest method shouldDescribeStatement.
@Test
public void shouldDescribeStatement() {
// Given:
final List<RunningQuery> queries = createRunningQueries("CREATE STREAM described_stream AS SELECT * FROM test_stream;" + "CREATE STREAM down_stream AS SELECT * FROM described_stream;", emptyMap());
// When:
final SourceDescriptionEntity description = makeSingleRequest("DESCRIBE DESCRIBED_STREAM;", SourceDescriptionEntity.class);
// Then:
final SourceDescription expectedDescription = SourceDescriptionFactory.create(ksqlEngine.getMetaStore().getSource(SourceName.of("DESCRIBED_STREAM")), false, Collections.singletonList(queries.get(1)), Collections.singletonList(queries.get(0)), Optional.empty(), Collections.emptyList(), Collections.emptyList(), new MetricCollectors());
assertThat(description.getSourceDescription(), is(expectedDescription));
}
Aggregations