Search in sources :

Example 6 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class PrometheusPushGatewayReporterTest method testConnectToPushGatewayUsingHostUrl.

@Test
void testConnectToPushGatewayUsingHostUrl() {
    PrometheusPushGatewayReporterFactory factory = new PrometheusPushGatewayReporterFactory();
    MetricConfig metricConfig = new MetricConfig();
    metricConfig.setProperty(HOST_URL.key(), "https://localhost:18080");
    PrometheusPushGatewayReporter reporter = factory.createMetricReporter(metricConfig);
    String gatewayBaseURL = factory.createMetricReporter(metricConfig).hostUrl.toString();
    assertThat(gatewayBaseURL).isEqualTo("https://localhost:18080");
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Test(org.junit.jupiter.api.Test)

Example 7 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class PrometheusPushGatewayReporterTest method testConnectToPushGatewayPreferHostUrl.

@Test
void testConnectToPushGatewayPreferHostUrl() {
    PrometheusPushGatewayReporterFactory factory = new PrometheusPushGatewayReporterFactory();
    MetricConfig metricConfig = new MetricConfig();
    metricConfig.setProperty(HOST_URL.key(), "https://localhost:18080");
    metricConfig.setProperty(HOST.key(), "localhost1");
    metricConfig.setProperty(PORT.key(), "18081");
    String gatewayBaseURL = factory.createMetricReporter(metricConfig).hostUrl.toString();
    assertThat(gatewayBaseURL).isEqualTo("https://localhost:18080");
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Test(org.junit.jupiter.api.Test)

Example 8 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class PrometheusPushGatewayReporterTest method testConnectToPushGatewayThrowsExceptionWithoutHostInformation.

@Test
void testConnectToPushGatewayThrowsExceptionWithoutHostInformation() {
    PrometheusPushGatewayReporterFactory factory = new PrometheusPushGatewayReporterFactory();
    MetricConfig metricConfig = new MetricConfig();
    assertThatThrownBy(() -> factory.createMetricReporter(metricConfig)).isInstanceOf(IllegalArgumentException.class);
    metricConfig.setProperty(HOST.key(), "localhost");
    assertThatThrownBy(() -> factory.createMetricReporter(metricConfig)).isInstanceOf(IllegalArgumentException.class);
    metricConfig.clear();
    metricConfig.setProperty(PORT.key(), "18080");
    assertThatThrownBy(() -> factory.createMetricReporter(metricConfig)).isInstanceOf(IllegalArgumentException.class);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Test(org.junit.jupiter.api.Test)

Example 9 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class PrometheusPushGatewayReporterTest method testConnectToPushGatewayUsingHostAndPort.

@Test
void testConnectToPushGatewayUsingHostAndPort() {
    PrometheusPushGatewayReporterFactory factory = new PrometheusPushGatewayReporterFactory();
    MetricConfig metricConfig = new MetricConfig();
    metricConfig.setProperty(HOST.key(), "localhost");
    metricConfig.setProperty(PORT.key(), "18080");
    PrometheusPushGatewayReporter reporter = factory.createMetricReporter(metricConfig);
    String gatewayBaseURL = factory.createMetricReporter(metricConfig).hostUrl.toString();
    assertThat(gatewayBaseURL).isEqualTo("http://localhost:18080");
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) Test(org.junit.jupiter.api.Test)

Example 10 with MetricConfig

use of org.apache.flink.metrics.MetricConfig in project flink by apache.

the class StatsDReporterTest method testAddingMetrics.

/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
void testAddingMetrics() {
    String counterName = "testCounter";
    final String scope = "scope";
    final char delimiter = '_';
    MetricGroup metricGroup = TestMetricGroup.newBuilder().setMetricIdentifierFunction((metricName, characterFilter) -> scope + delimiter + metricName).build();
    TestingStatsDReporter reporter = new TestingStatsDReporter();
    reporter.open(new MetricConfig());
    SimpleCounter myCounter = new SimpleCounter();
    reporter.notifyOfAddedMetric(myCounter, counterName, metricGroup);
    Map<Counter, String> counters = reporter.getCounters();
    assertThat(counters).containsKey(myCounter);
    String expectedCounterName = reporter.filterCharacters(scope) + delimiter + reporter.filterCharacters(counterName);
    assertThat(counters.get(myCounter)).isEqualTo(expectedCounterName);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) TestMeter(org.apache.flink.metrics.util.TestMeter) Metric(org.apache.flink.metrics.Metric) TestCounter(org.apache.flink.metrics.util.TestCounter) Test(org.junit.jupiter.api.Test) DatagramSocket(java.net.DatagramSocket) HashSet(java.util.HashSet) MetricGroup(org.apache.flink.metrics.MetricGroup) SocketException(java.net.SocketException) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Map(java.util.Map) ConfigConstants(org.apache.flink.configuration.ConfigConstants) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) DatagramPacket(java.net.DatagramPacket) Counter(org.apache.flink.metrics.Counter) MetricConfig(org.apache.flink.metrics.MetricConfig) TestCounter(org.apache.flink.metrics.util.TestCounter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) Test(org.junit.jupiter.api.Test)

Aggregations

MetricConfig (org.apache.flink.metrics.MetricConfig)19 Test (org.junit.jupiter.api.Test)6 Test (org.junit.Test)5 MetricGroup (org.apache.flink.metrics.MetricGroup)4 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)4 Map (java.util.Map)3 ConfigConstants (org.apache.flink.configuration.ConfigConstants)3 Configuration (org.apache.flink.configuration.Configuration)3 TestMetricGroup (org.apache.flink.metrics.util.TestMetricGroup)3 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 MetricOptions (org.apache.flink.configuration.MetricOptions)2 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)2 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)2 MetricGroupAndName (org.apache.flink.runtime.metrics.CollectingMetricsReporter.MetricGroupAndName)2 SlidingWindowReservoir (com.codahale.metrics.SlidingWindowReservoir)1 Snapshot (com.codahale.metrics.Snapshot)1 File (java.io.File)1 IOException (java.io.IOException)1