use of com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions in project cruise-control by linkedin.
the class PrometheusMetricSamplerTest method testGetSamplesCustomPrometheusQuerySupplier.
@Test
public void testGetSamplesCustomPrometheusQuerySupplier() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(PROMETHEUS_SERVER_ENDPOINT_CONFIG, "http://kafka-cluster-1.org:9090");
addCapacityConfig(config);
config.put(PROMETHEUS_QUERY_SUPPLIER_CONFIG, TestQuerySupplier.class.getName());
_prometheusMetricSampler.configure(config);
MetricSamplerOptions metricSamplerOptions = buildMetricSamplerOptions(TEST_TOPIC);
_prometheusMetricSampler._prometheusAdapter = _prometheusAdapter;
expect(_prometheusAdapter.queryMetric(eq(TestQuerySupplier.TEST_QUERY), anyLong(), anyLong())).andReturn(buildBrokerResults());
replay(_prometheusAdapter);
_prometheusMetricSampler.getSamples(metricSamplerOptions);
verify(_prometheusAdapter);
}
use of com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions in project cruise-control by linkedin.
the class PrometheusMetricSamplerTest method testGetSamplesSuccess.
@Test
public void testGetSamplesSuccess() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(PROMETHEUS_SERVER_ENDPOINT_CONFIG, "http://kafka-cluster-1.org:9090");
addCapacityConfig(config);
Set<String> topics = new HashSet<>(Arrays.asList(TEST_TOPIC, TEST_TOPIC_WITH_DOT));
for (String topic : topics) {
setUp();
_prometheusMetricSampler.configure(config);
MetricSamplerOptions metricSamplerOptions = buildMetricSamplerOptions(topic);
_prometheusMetricSampler._prometheusAdapter = _prometheusAdapter;
for (RawMetricType rawMetricType : _prometheusQueryMap.keySet()) {
setupPrometheusAdapterMock(rawMetricType, buildBrokerResults(), buildTopicResults(topic), buildPartitionResults(topic));
}
replay(_prometheusAdapter);
MetricSampler.Samples samples = _prometheusMetricSampler.getSamples(metricSamplerOptions);
assertSamplesValid(samples, topic);
verify(_prometheusAdapter);
}
}
use of com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions in project cruise-control by linkedin.
the class PrometheusMetricSamplerTest method testPrometheusQueryReturnsInvalidResults.
public void testPrometheusQueryReturnsInvalidResults(List<PrometheusQueryResult> brokerResults, List<PrometheusQueryResult> topicResults, List<PrometheusQueryResult> partitionResults) throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(PROMETHEUS_SERVER_ENDPOINT_CONFIG, "http://kafka-cluster-1.org:9090");
addCapacityConfig(config);
_prometheusMetricSampler.configure(config);
MetricSamplerOptions metricSamplerOptions = buildMetricSamplerOptions(TEST_TOPIC);
_prometheusMetricSampler._prometheusAdapter = _prometheusAdapter;
for (RawMetricType rawMetricType : _prometheusQueryMap.keySet()) {
setupPrometheusAdapterMock(rawMetricType, brokerResults, topicResults, partitionResults);
}
replay(_prometheusAdapter);
_prometheusMetricSampler.getSamples(metricSamplerOptions);
}
use of com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions in project cruise-control by linkedin.
the class PrometheusMetricSamplerTest method testGetSamplesQueryThrowsException.
@Test(expected = SamplingException.class)
public void testGetSamplesQueryThrowsException() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(PROMETHEUS_SERVER_ENDPOINT_CONFIG, "http://kafka-cluster-1.org:9090");
addCapacityConfig(config);
_prometheusMetricSampler.configure(config);
MetricSamplerOptions metricSamplerOptions = buildMetricSamplerOptions(TEST_TOPIC);
_prometheusMetricSampler._prometheusAdapter = _prometheusAdapter;
expect(_prometheusAdapter.queryMetric(anyString(), anyLong(), anyLong())).andThrow(new IOException("Exception in fetching metrics"));
replay(_prometheusAdapter);
try {
_prometheusMetricSampler.getSamples(metricSamplerOptions);
} finally {
verify(_prometheusAdapter);
}
}
Aggregations