Skip to content

Commit

Permalink
[FLINK-15458][conf][docs] Introduce SuffixOption annotation
Browse files Browse the repository at this point in the history
They key of a SuffixOption is only a suffix, with the prefix being determined at runtime.
In the case of reporters the prefix is "metrics.reporter." with a user-provided infix.

For these options it doesn't make sense to check whether they are clashing with other options;
in practive this is entirely dependent on the prefix.
  • Loading branch information
zentol committed Jan 18, 2020
1 parent 7be292c commit 6825dbd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public String toString() {
String value() default "";
}

/**
* Annotation used on config option fields or options class to mark them as a suffix-option; i.e., a config option
* where the key is only a suffix, with the prefix being danymically provided at runtime.
*/
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Internal
public @interface SuffixOption {
}

private Documentation(){
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.junit.Test;

import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void testFullReferenceCompleteness() throws IOException, ClassNotFoundExc

private static void assertExistingOptionsAreWellDefined(Map<String, List<ExistingOption>> allOptions) {
allOptions.values().stream()
.filter(options -> !options.stream().allMatch(option -> option.isSuffixOption))
.forEach(options -> options.stream()
.reduce((option1, option2) -> {
if (option1.equals(option2)) {
Expand Down Expand Up @@ -233,21 +235,32 @@ private static ExistingOption toExistingOption(ConfigOptionsDocGenerator.OptionW
String defaultValue = stringifyDefault(optionWithMetaInfo);
String typeValue = typeToHtml(optionWithMetaInfo);
String description = htmlFormatter.format(optionWithMetaInfo.option.description());
return new ExistingOption(key, defaultValue, typeValue, description, optionsClass);
boolean isSuffixOption = isSuffixOption(optionWithMetaInfo.field);
return new ExistingOption(key, defaultValue, typeValue, description, optionsClass, isSuffixOption);
}

private static boolean isSuffixOption(Field field) {
final Class<?> containingOptionsClass = field.getDeclaringClass();

return field.getAnnotation(Documentation.SuffixOption.class) != null ||
containingOptionsClass.getAnnotation(Documentation.SuffixOption.class) != null;
}

private static final class ExistingOption extends Option {

private final Class<?> containingClass;
private final boolean isSuffixOption;

private ExistingOption(
String key,
String defaultValue,
String typeValue,
String description,
Class<?> containingClass) {
Class<?> containingClass,
boolean isSuffixOption) {
super(key, defaultValue, typeValue, description);
this.containingClass = containingClass;
this.isSuffixOption = isSuffixOption;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.flink.metrics.prometheus;

import org.apache.flink.annotation.docs.Documentation;
import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ConfigOptions;
import org.apache.flink.configuration.description.Description;
Expand All @@ -27,6 +28,7 @@
/**
* Config options for the {@link PrometheusPushGatewayReporter}.
*/
@Documentation.SuffixOption
public class PrometheusPushGatewayReporterOptions {

public static final ConfigOption<String> HOST = ConfigOptions
Expand Down

0 comments on commit 6825dbd

Please sign in to comment.