Skip to content

Commit

Permalink
Metric markdown includes missing tag docs for tags without enumerated…
Browse files Browse the repository at this point in the history
… values (#1064)

Metric markdown includes missing tag docs for tags without enumerated values
  • Loading branch information
carterkozak authored Oct 26, 2023
1 parent db33e28 commit 19213b5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-1064.v2.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -111,6 +110,12 @@ private static void renderLine(
}
}

private static boolean hasComplexTags(List<TagDefinition> tags) {
return tags.stream()
.anyMatch(definition -> definition.getDocs().isPresent()
|| !definition.getValues().isEmpty());
}

private static void renderComplexTags(List<TagDefinition> tagDefinitions, StringBuilder output) {
tagDefinitions.forEach(tagDefinition -> {
boolean hasEnumValueDocs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 19213b5

Please sign in to comment.