@Test public void shouldThrowIfTryingToRegisterMetricWithMoreThanTenTags() throws Exception { Map<String, String> tags = IntStream.range(0, 11) .boxed() .collect(Collectors.toMap(i -> "tag" + i, i -> "tagVal" + i)); assertThat(tags.size()).isEqualTo(11); assertThatThrownBy(() -> MetricNameUtils.getMetricName(METRIC_NAME, tags)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Too many tags set on the metric metricName. " + "Maximum allowed number of tags is 10, found 11."); }
public static String getMetricName(String metricName, Map<String, String> tags) { Preconditions.checkArgument(tags.size() <= MAX_ALLOWED_TAGS, "Too many tags set on the metric %s. " + "Maximum allowed number of tags is %s, found %s.", metricName, MAX_ALLOWED_TAGS, tags.size()); validateMetricComponentName(metricName, "metric"); validateMetricTagNames(tags); return tags.entrySet().stream() .map(e -> e.getKey() + EQUALS + e.getValue()) .collect(Collectors.joining(DELIMITER, metricName + DELIMITER, "")); }
MetricNameUtils { public static String getMetricName(String metricName, Map<String, String> tags) { Preconditions.checkArgument(tags.size() <= MAX_ALLOWED_TAGS, "Too many tags set on the metric %s. " + "Maximum allowed number of tags is %s, found %s.", metricName, MAX_ALLOWED_TAGS, tags.size()); validateMetricComponentName(metricName, "metric"); validateMetricTagNames(tags); return tags.entrySet().stream() .map(e -> e.getKey() + EQUALS + e.getValue()) .collect(Collectors.joining(DELIMITER, metricName + DELIMITER, "")); } }
MetricNameUtils { public static String getMetricName(String metricName, Map<String, String> tags) { Preconditions.checkArgument(tags.size() <= MAX_ALLOWED_TAGS, "Too many tags set on the metric %s. " + "Maximum allowed number of tags is %s, found %s.", metricName, MAX_ALLOWED_TAGS, tags.size()); validateMetricComponentName(metricName, "metric"); validateMetricTagNames(tags); return tags.entrySet().stream() .map(e -> e.getKey() + EQUALS + e.getValue()) .collect(Collectors.joining(DELIMITER, metricName + DELIMITER, "")); } private  MetricNameUtils(); }
MetricNameUtils { public static String getMetricName(String metricName, Map<String, String> tags) { Preconditions.checkArgument(tags.size() <= MAX_ALLOWED_TAGS, "Too many tags set on the metric %s. " + "Maximum allowed number of tags is %s, found %s.", metricName, MAX_ALLOWED_TAGS, tags.size()); validateMetricComponentName(metricName, "metric"); validateMetricTagNames(tags); return tags.entrySet().stream() .map(e -> e.getKey() + EQUALS + e.getValue()) .collect(Collectors.joining(DELIMITER, metricName + DELIMITER, "")); } private  MetricNameUtils(); static String getMetricName(String metricName, Map<String, String> tags); }
MetricNameUtils { public static String getMetricName(String metricName, Map<String, String> tags) { Preconditions.checkArgument(tags.size() <= MAX_ALLOWED_TAGS, "Too many tags set on the metric %s. " + "Maximum allowed number of tags is %s, found %s.", metricName, MAX_ALLOWED_TAGS, tags.size()); validateMetricComponentName(metricName, "metric"); validateMetricTagNames(tags); return tags.entrySet().stream() .map(e -> e.getKey() + EQUALS + e.getValue()) .collect(Collectors.joining(DELIMITER, metricName + DELIMITER, "")); } private  MetricNameUtils(); static String getMetricName(String metricName, Map<String, String> tags);  }