diff --git a/changelog/@unreleased/pr-1064.v2.yml b/changelog/@unreleased/pr-1064.v2.yml new file mode 100644 index 00000000..b1326601 --- /dev/null +++ b/changelog/@unreleased/pr-1064.v2.yml @@ -0,0 +1,6 @@ +type: fix +fix: + description: Metric markdown includes missing tag docs for tags without enumerated + values + links: + - https://github.com/palantir/metric-schema/pull/1064 diff --git a/metric-schema-markdown/src/main/java/com/palantir/metric/schema/markdown/MarkdownRenderer.java b/metric-schema-markdown/src/main/java/com/palantir/metric/schema/markdown/MarkdownRenderer.java index 4df02f6e..c04cab29 100644 --- a/metric-schema-markdown/src/main/java/com/palantir/metric/schema/markdown/MarkdownRenderer.java +++ b/metric-schema-markdown/src/main/java/com/palantir/metric/schema/markdown/MarkdownRenderer.java @@ -87,8 +87,7 @@ private static void renderLine( .addAll(metric.getTagDefinitions()) .build(); output.append("- `").append(namespace).append('.').append(metricName).append('`'); - boolean hasComplexTags = - allTags.stream().anyMatch(definition -> !definition.getValues().isEmpty()); + boolean hasComplexTags = hasComplexTags(allTags); if (!metric.getTags().isEmpty()) { output.append(" tagged ") .append(metric.getTags().stream() @@ -111,6 +110,12 @@ private static void renderLine( } } + private static boolean hasComplexTags(List tags) { + return tags.stream() + .anyMatch(definition -> definition.getDocs().isPresent() + || !definition.getValues().isEmpty()); + } + private static void renderComplexTags(List tagDefinitions, StringBuilder output) { tagDefinitions.forEach(tagDefinition -> { boolean hasEnumValueDocs = diff --git a/metric-schema-markdown/src/test/java/com/palantir/metric/schema/markdown/MarkdownRendererTest.java b/metric-schema-markdown/src/test/java/com/palantir/metric/schema/markdown/MarkdownRendererTest.java index 20663d32..a67b65a2 100644 --- a/metric-schema-markdown/src/test/java/com/palantir/metric/schema/markdown/MarkdownRendererTest.java +++ b/metric-schema-markdown/src/test/java/com/palantir/metric/schema/markdown/MarkdownRendererTest.java @@ -246,6 +246,37 @@ void testComplexTagged() { + " - `processing` values (`foo`,`bar`)"); } + @Test + void testTaggedWithDocsOnlyOnTag() { + MetricSchema schema = MetricSchema.builder() + .namespaces( + "namespace", + MetricNamespace.builder() + .docs(Documentation.of("namespace docs")) + .metrics( + "metric", + MetricDefinition.builder() + .type(MetricType.METER) + .tagDefinitions(TagDefinition.builder() + .name("result") + .docs(Documentation.of("This is a result tag")) + .build()) + .docs(Documentation.of("metric docs")) + .build()) + .build()) + .build(); + String markdown = MarkdownRenderer.render( + "com.palantir:test", ImmutableMap.of("com.palantir:test:1.0.0", ImmutableList.of(schema))); + assertThat(markdown) + .isEqualTo("# Metrics\n\n" + + "## Test\n\n" + + "`com.palantir:test`\n\n" + + "### namespace\n" + + "namespace docs\n" + + "- `namespace.metric` (meter): metric docs\n" + + " - `result`: This is a result tag"); + } + @Test void testEmptyNamespacesExcluded() { String markdown = MarkdownRenderer.render(