Search in sources :

Example 1 with MetricSamplerOptions

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);
}
Also used : HashMap(java.util.HashMap) MetricSamplerOptions(com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions) Test(org.junit.Test)

Example 2 with MetricSamplerOptions

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);
    }
}
Also used : MetricSampler(com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSampler) PrometheusMetricSampler(com.linkedin.kafka.cruisecontrol.monitor.sampling.prometheus.PrometheusMetricSampler) HashMap(java.util.HashMap) MetricSamplerOptions(com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions) RawMetricType(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.RawMetricType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with MetricSamplerOptions

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);
}
Also used : HashMap(java.util.HashMap) MetricSamplerOptions(com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions) RawMetricType(com.linkedin.kafka.cruisecontrol.metricsreporter.metric.RawMetricType)

Example 4 with 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);
    }
}
Also used : HashMap(java.util.HashMap) MetricSamplerOptions(com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

MetricSamplerOptions (com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSamplerOptions)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)3 RawMetricType (com.linkedin.kafka.cruisecontrol.metricsreporter.metric.RawMetricType)2 MetricSampler (com.linkedin.kafka.cruisecontrol.monitor.sampling.MetricSampler)1 PrometheusMetricSampler (com.linkedin.kafka.cruisecontrol.monitor.sampling.prometheus.PrometheusMetricSampler)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1