Skip to content

Commit

Permalink
[FLINK-12325][metrics] Add counter/gauge tests for StatsD
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeli authored and zentol committed May 9, 2019
1 parent 7b806e7 commit a8cc170
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.MetricOptions;
import org.apache.flink.metrics.Counter;
import org.apache.flink.metrics.Gauge;
import org.apache.flink.metrics.Histogram;
import org.apache.flink.metrics.HistogramStatistics;
import org.apache.flink.metrics.Metric;
Expand Down Expand Up @@ -163,6 +164,28 @@ public void testStatsDMetersReporting() throws Exception {
testMetricAndAssert(new TestMeter(), "metric", expectedLines);
}

/**
* Tests that counter are properly reported via the StatsD reporter.
*/
@Test
public void testStatsDCountersReporting() throws Exception {
Set<String> expectedLines = new HashSet<>(2);
expectedLines.add("metric:100|g");

Counter counter = new SimpleCounter();
counter.inc(100);

testMetricAndAssert(counter, "metric", expectedLines);
}

@Test
public void testStatsDGaugesReporting() throws Exception {
Set<String> expectedLines = new HashSet<>(2);
expectedLines.add("metric:75|g");

testMetricAndAssert((Gauge) () -> 75, "metric", expectedLines);
}

private void testMetricAndAssert(Metric metric, String metricName, Set<String> expectation) throws Exception {
StatsDReporter reporter = null;
DatagramSocketReceiver receiver = null;
Expand Down

0 comments on commit a8cc170

Please sign in to comment.