|
18 | 18 |
|
19 | 19 | import com.codahale.metrics.Gauge;
|
20 | 20 | import com.google.common.collect.ImmutableList;
|
| 21 | +import com.google.common.collect.Iterables; |
21 | 22 | import com.google.errorprone.annotations.CheckReturnValue;
|
22 | 23 | import com.palantir.logsafe.Preconditions;
|
23 | 24 | import com.palantir.tritium.metrics.registry.MetricName;
|
@@ -106,7 +107,7 @@ private static void generateConstants(
|
106 | 107 | MetricDefinition definition,
|
107 | 108 | ImplementationVisibility visibility) {
|
108 | 109 | definition.getTagDefinitions().forEach(tagDef -> {
|
109 |
| - if (tagDef.getValues().isEmpty()) { |
| 110 | + if (tagDef.getValues().size() <= 1) { |
110 | 111 | return;
|
111 | 112 | }
|
112 | 113 |
|
@@ -145,6 +146,11 @@ private static CodeBlock metricName(
|
145 | 146 | definition.getTagDefinitions().forEach(tagDef -> {
|
146 | 147 | if (tagDef.getValues().isEmpty()) {
|
147 | 148 | builder.add(".putSafeTags($S, $L)", tagDef.getName(), Custodian.sanitizeName(tagDef.getName()));
|
| 149 | + } else if (tagDef.getValues().size() == 1) { |
| 150 | + builder.add( |
| 151 | + ".putSafeTags($S, $S)", |
| 152 | + tagDef.getName(), |
| 153 | + Iterables.getOnlyElement(tagDef.getValues()).getValue()); |
148 | 154 | } else {
|
149 | 155 | builder.add(
|
150 | 156 | ".putSafeTags($S, $L.getValue())", tagDef.getName(), Custodian.sanitizeName(tagDef.getName()));
|
@@ -250,8 +256,9 @@ private static void generateMetricFactoryBuilder(
|
250 | 256 | .addModifiers(visibility.apply())
|
251 | 257 | .addMethods(abstractBuildMethods)
|
252 | 258 | .build());
|
253 |
| - ImmutableList<TagDefinition> tagList = |
254 |
| - definition.getTagDefinitions().stream().collect(ImmutableList.toImmutableList()); |
| 259 | + ImmutableList<TagDefinition> tagList = definition.getTagDefinitions().stream() |
| 260 | + .filter(tagDefinition -> tagDefinition.getValues().size() != 1) |
| 261 | + .collect(ImmutableList.toImmutableList()); |
255 | 262 | for (int i = 0; i < tagList.size(); i++) {
|
256 | 263 | boolean lastTag = i == tagList.size() - 1;
|
257 | 264 | TagDefinition tag = tagList.get(i);
|
@@ -355,7 +362,9 @@ private static void generateMetricFactoryBuilder(
|
355 | 362 | }
|
356 | 363 |
|
357 | 364 | private static int numArgs(MetricDefinition definition) {
|
358 |
| - return definition.getTagDefinitions().size() |
| 365 | + return (int) definition.getTagDefinitions().stream() |
| 366 | + .filter(tagDefinition -> tagDefinition.getValues().size() != 1) |
| 367 | + .count() |
359 | 368 | // Gauges require a gauge argument.
|
360 | 369 | + (MetricType.GAUGE.equals(definition.getType()) ? 1 : 0);
|
361 | 370 | }
|
|
0 commit comments