[ https://issues.apache.org/jira/browse/FLINK-7502?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16145155#comment-16145155 ]
ASF GitHub Bot commented on FLINK-7502: --------------------------------------- Github user zentol commented on a diff in the pull request: https://github.com/apache/flink/pull/4586#discussion_r135764923 --- Diff: flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java --- @@ -160,6 +151,43 @@ public void invalidCharactersAreReplacedWithUnderscore() { assertThat(PrometheusReporter.replaceInvalidChars("a,=;:?'b,=;:?'c"), equalTo("a___:__b___:__c")); } + @Test + public void registeringSameMetricTwiceDoesNotThrowException() { + Counter counter = new SimpleCounter(); + counter.inc(); + String counterName = "testCounter"; + final FrontMetricGroup<TaskManagerMetricGroup> group = new FrontMetricGroup<>(0, new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER)); + + reporter.notifyOfAddedMetric(counter, counterName, group); + reporter.notifyOfAddedMetric(counter, counterName, group); + } + + @Test + public void cannotStartTwoReportersOnSamePort() { + final MetricRegistry fixedPort1 = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", "12345"))); + final MetricRegistry fixedPort2 = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test2", "12345"))); + assertThat(fixedPort1.getReporters(), hasSize(1)); + assertThat(fixedPort2.getReporters(), hasSize(0)); + } + + @Test + public void canStartTwoReportersWhenUsingPortRange() { + final MetricRegistry portRange1 = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", "9249-9252"))); + final MetricRegistry portRange2 = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test2", "9249-9252"))); + assertThat(portRange1.getReporters(), hasSize(1)); + assertThat(portRange2.getReporters(), hasSize(1)); + } + + @Test + public void cannotStartThreeReportersWhenPortRangeIsTooSmall() { + final MetricRegistry smallPortRange1 = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", "9253-9254"))); --- End diff -- You should call `MetricRegistry#shutdown()` when you no longer need it. > PrometheusReporter improvements > ------------------------------- > > Key: FLINK-7502 > URL: https://issues.apache.org/jira/browse/FLINK-7502 > Project: Flink > Issue Type: Improvement > Components: Metrics > Affects Versions: 1.4.0 > Reporter: Maximilian Bode > Assignee: Maximilian Bode > Priority: Minor > > * do not throw exceptions on metrics being registered for second time > * allow port ranges for setups where multiple reporters are on same host > (e.g. one TaskManager and one JobManager) > * do not use nanohttpd anymore, there is now a minimal http server included > in [Prometheus JVM client|https://github.com/prometheus/client_java] -- This message was sent by Atlassian JIRA (v6.4.14#64029)