SparkBeamMetric implements Metric { @VisibleForTesting String renderName(MetricResult<?> metricResult) { MetricKey key = metricResult.getKey(); MetricName name = key.metricName(); String step = key.stepName(); ArrayList<String> pieces = new ArrayList<>(); if (step != null) { step = step.replaceAll(ILLEGAL_CHARACTERS, "_"); if (step.endsWith("_")) { step = step.substring(0, step.length() - 1); } pieces.add(step); } pieces.addAll( ImmutableList.of(name.getNamespace(), name.getName()).stream() .map(str -> str.replaceAll(ILLEGAL_CHARACTERS, "_")) .collect(toList())); return String.join(".", pieces); }    }
@Test public void testRenderName() { MetricResult<Object> metricResult = MetricResult.create( MetricKey.create( "myStep.one.two(three)", MetricName.named("myNameSpace 123, 456); String renderedName = new SparkBeamMetric().renderName(metricResult); assertThat( "Metric name was not rendered correctly", renderedName, equalTo("myStep_one_two_three.myNameSpace__.myName__")); }