Skip to content

Commit b732f2e

Browse files
authored
Allow documenting optional keys (micrometer-metrics#3454)
There is no distinction between required and optional keys currently when using ObservationDocumentation. This introduces a new method `isRequired` that will default to true. Optional keys may be documented by overriding this method. Future use of this can be in the docs-generator marking whether a key is required or not in the generated documentation. Also, testing the instrumentation with our TCKs can check that required keys are always present, and that undocumented keys are not present but optional keys may or may not be present.
1 parent e2b660e commit b732f2e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

micrometer-commons/src/main/java/io/micrometer/common/docs/KeyName.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,13 @@ default KeyValue withValue(String value, Predicate<Object> validator) {
6262
*/
6363
String asString();
6464

65+
/**
66+
* Whether this key is required to be present in the instrumentation. This can be
67+
* checked in a test of the instrumentation.
68+
* @return whether this key is required
69+
*/
70+
default boolean isRequired() {
71+
return true;
72+
}
73+
6574
}

micrometer-observation-test/src/test/java/io/micrometer/observation/tck/TestObservationRegistryAssertTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,19 @@ enum MyKeyName implements KeyName {
356356
public String asString() {
357357
return "foo";
358358
}
359+
},
360+
361+
MAYBE_SOMETHING {
362+
363+
@Override
364+
public String asString() {
365+
return "maybe.something";
366+
}
367+
368+
@Override
369+
public boolean isRequired() {
370+
return false;
371+
}
359372
}
360373

361374
}

0 commit comments

Comments
 (0)