Skip to content

Commit

Permalink
[FLINK-9792] Added custom Description class for ConfigOptions to enab…
Browse files Browse the repository at this point in the history
…le rich formatting.

This closes apache#6312
  • Loading branch information
dawidwys committed Jul 18, 2018
1 parent 64feb4e commit a457a35
Show file tree
Hide file tree
Showing 19 changed files with 774 additions and 28 deletions.
6 changes: 3 additions & 3 deletions docs/_includes/generated/akka_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@
<tr>
<td><h5>akka.watch.heartbeat.interval</h5></td>
<td style="word-wrap: break-word;">"10 s"</td>
<td>Heartbeat interval for Akka’s DeathWatch mechanism to detect dead TaskManagers. If TaskManagers are wrongly marked dead because of lost or delayed heartbeat messages, then you should decrease this value or increase akka.watch.heartbeat.pause. A thorough description of Akka’s DeathWatch can be found &#60;a href="https://doc.akka.io/docs/akka/snapshot/scala/remoting.html#failure-detector"&#62;here&#60;/a&#62;.</td>
<td>Heartbeat interval for Akka’s DeathWatch mechanism to detect dead TaskManagers. If TaskManagers are wrongly marked dead because of lost or delayed heartbeat messages, then you should decrease this value or increase akka.watch.heartbeat.pause. A thorough description of Akka’s DeathWatch can be found &lt;a href="https://doc.akka.io/docs/akka/snapshot/scala/remoting.html#failure-detector"&gt;here&lt;/a&gt;.</td>
</tr>
<tr>
<td><h5>akka.watch.heartbeat.pause</h5></td>
<td style="word-wrap: break-word;">"60 s"</td>
<td>Acceptable heartbeat pause for Akka’s DeathWatch mechanism. A low value does not allow an irregular heartbeat. If TaskManagers are wrongly marked dead because of lost or delayed heartbeat messages, then you should increase this value or decrease akka.watch.heartbeat.interval. Higher value increases the time to detect a dead TaskManager. A thorough description of Akka’s DeathWatch can be found &#60;a href="https://doc.akka.io/docs/akka/snapshot/scala/remoting.html#failure-detector"&#62;here&#60;/a&#62;.</td>
<td>Acceptable heartbeat pause for Akka’s DeathWatch mechanism. A low value does not allow an irregular heartbeat. If TaskManagers are wrongly marked dead because of lost or delayed heartbeat messages, then you should increase this value or decrease akka.watch.heartbeat.interval. Higher value increases the time to detect a dead TaskManager. A thorough description of Akka’s DeathWatch can be found &lt;a href="https://doc.akka.io/docs/akka/snapshot/scala/remoting.html#failure-detector"&gt;here&lt;/a&gt;.</td>
</tr>
<tr>
<td><h5>akka.watch.threshold</h5></td>
<td style="word-wrap: break-word;">12</td>
<td>Threshold for the DeathWatch failure detector. A low value is prone to false positives whereas a high value increases the time to detect a dead TaskManager. A thorough description of Akka’s DeathWatch can be found &#60;a href="https://doc.akka.io/docs/akka/snapshot/scala/remoting.html#failure-detector"&#62;here&#60;/a&#62;.</td>
<td>Threshold for the DeathWatch failure detector. A low value is prone to false positives whereas a high value increases the time to detect a dead TaskManager. A thorough description of Akka’s DeathWatch can be found &lt;a href="https://doc.akka.io/docs/akka/snapshot/scala/remoting.html#failure-detector"&gt;here&lt;/a&gt;.</td>
</tr>
</tbody>
</table>
24 changes: 12 additions & 12 deletions docs/_includes/generated/metric_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
<td>Defines the number of measured latencies to maintain at each operator.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&#60;name&#62;.&#60;parameter&#62;</h5></td>
<td><h5>metrics.reporter.&lt;name&gt;.&lt;parameter&gt;</h5></td>
<td style="word-wrap: break-word;">(none)</td>
<td>Configures the parameter &#60;parameter&#62; for the reporter named &#60;name&#62;.</td>
<td>Configures the parameter &lt;parameter&gt; for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&#60;name&#62;.class</h5></td>
<td><h5>metrics.reporter.&lt;name&gt;.class</h5></td>
<td style="word-wrap: break-word;">(none)</td>
<td>The reporter class to use for the reporter named &#60;name&#62;.</td>
<td>The reporter class to use for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&#60;name&#62;.interval</h5></td>
<td><h5>metrics.reporter.&lt;name&gt;.interval</h5></td>
<td style="word-wrap: break-word;">(none)</td>
<td>The reporter interval to use for the reporter named &#60;name&#62;.</td>
<td>The reporter interval to use for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporters</h5></td>
Expand All @@ -39,32 +39,32 @@
</tr>
<tr>
<td><h5>metrics.scope.jm</h5></td>
<td style="word-wrap: break-word;">"&#60;host&#62;.jobmanager"</td>
<td style="word-wrap: break-word;">"&lt;host&gt;.jobmanager"</td>
<td>Defines the scope format string that is applied to all metrics scoped to a JobManager.</td>
</tr>
<tr>
<td><h5>metrics.scope.jm.job</h5></td>
<td style="word-wrap: break-word;">"&#60;host&#62;.jobmanager.&#60;job_name&#62;"</td>
<td style="word-wrap: break-word;">"&lt;host&gt;.jobmanager.&lt;job_name&gt;"</td>
<td>Defines the scope format string that is applied to all metrics scoped to a job on a JobManager.</td>
</tr>
<tr>
<td><h5>metrics.scope.operator</h5></td>
<td style="word-wrap: break-word;">"&#60;host&#62;.taskmanager.&#60;tm_id&#62;.&#60;job_name&#62;.&#60;operator_name&#62;.&#60;subtask_index&#62;"</td>
<td style="word-wrap: break-word;">"&lt;host&gt;.taskmanager.&lt;tm_id&gt;.&lt;job_name&gt;.&lt;operator_name&gt;.&lt;subtask_index&gt;"</td>
<td>Defines the scope format string that is applied to all metrics scoped to an operator.</td>
</tr>
<tr>
<td><h5>metrics.scope.task</h5></td>
<td style="word-wrap: break-word;">"&#60;host&#62;.taskmanager.&#60;tm_id&#62;.&#60;job_name&#62;.&#60;task_name&#62;.&#60;subtask_index&#62;"</td>
<td style="word-wrap: break-word;">"&lt;host&gt;.taskmanager.&lt;tm_id&gt;.&lt;job_name&gt;.&lt;task_name&gt;.&lt;subtask_index&gt;"</td>
<td>Defines the scope format string that is applied to all metrics scoped to a task.</td>
</tr>
<tr>
<td><h5>metrics.scope.tm</h5></td>
<td style="word-wrap: break-word;">"&#60;host&#62;.taskmanager.&#60;tm_id&#62;"</td>
<td style="word-wrap: break-word;">"&lt;host&gt;.taskmanager.&lt;tm_id&gt;"</td>
<td>Defines the scope format string that is applied to all metrics scoped to a TaskManager.</td>
</tr>
<tr>
<td><h5>metrics.scope.tm.job</h5></td>
<td style="word-wrap: break-word;">"&#60;host&#62;.taskmanager.&#60;tm_id&#62;.&#60;job_name&#62;"</td>
<td style="word-wrap: break-word;">"&lt;host&gt;.taskmanager.&lt;tm_id&gt;.&lt;job_name&gt;"</td>
<td>Defines the scope format string that is applied to all metrics scoped to a job on a TaskManager.</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/generated/security_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<tr>
<td><h5>security.ssl.algorithms</h5></td>
<td style="word-wrap: break-word;">"TLS_RSA_WITH_AES_128_CBC_SHA"</td>
<td>The comma separated list of standard SSL algorithms to be supported. Read more &#60;a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#ciphersuites"&#62;here&#60;/a&#62;.</td>
<td>The comma separated list of standard SSL algorithms to be supported. Read more &lt;a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#ciphersuites"&gt;here&lt;/a&gt;.</td>
</tr>
<tr>
<td><h5>security.ssl.internal.enabled</h5></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.flink.configuration;

import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.configuration.description.Description;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class ConfigOption<T> {
private final T defaultValue;

/** The description for this option. */
private final String description;
private final Description description;

// ------------------------------------------------------------------------

Expand All @@ -64,7 +65,7 @@ public class ConfigOption<T> {
*/
ConfigOption(String key, T defaultValue) {
this.key = checkNotNull(key);
this.description = "";
this.description = Description.builder().text("").build();
this.defaultValue = defaultValue;
this.deprecatedKeys = EMPTY;
}
Expand All @@ -73,10 +74,28 @@ public class ConfigOption<T> {
* Creates a new config option with deprecated keys.
*
* @param key The current key for that config option
* @param description Description for that option
* @param defaultValue The default value for this option
* @param deprecatedKeys The list of deprecated keys, in the order to be checked
* @deprecated use version with {@link Description} instead
*/
@Deprecated
ConfigOption(String key, String description, T defaultValue, String... deprecatedKeys) {
this.key = checkNotNull(key);
this.description = Description.builder().text(description).build();
this.defaultValue = defaultValue;
this.deprecatedKeys = deprecatedKeys == null || deprecatedKeys.length == 0 ? EMPTY : deprecatedKeys;
}

/**
* Creates a new config option with deprecated keys.
*
* @param key The current key for that config option
* @param description Description for that option
* @param defaultValue The default value for this option
* @param deprecatedKeys The list of deprecated keys, in the order to be checked
*/
ConfigOption(String key, Description description, T defaultValue, String... deprecatedKeys) {
this.key = checkNotNull(key);
this.description = description;
this.defaultValue = defaultValue;
Expand Down Expand Up @@ -104,15 +123,26 @@ public ConfigOption<T> withDeprecatedKeys(String... deprecatedKeys) {
* Creates a new config option, using this option's key and default value, and
* adding the given description. The given description is used when generation the configuration documention.
*
* <p><b>NOTE:</b> You can use html to format the output of the generated cell.
*
* @param description The description for this option.
* @return A new config option, with given description.
* @deprecated use version with {@link Description}
*/
@Deprecated
public ConfigOption<T> withDescription(final String description) {
return new ConfigOption<>(key, description, defaultValue, deprecatedKeys);
}

/**
* Creates a new config option, using this option's key and default value, and
* adding the given description. The given description is used when generation the configuration documention.
*
* @param description The description for this option.
* @return A new config option, with given description.
*/
public ConfigOption<T> withDescription(final Description description) {
return new ConfigOption<>(key, description, defaultValue, deprecatedKeys);
}

// ------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -159,7 +189,7 @@ public Iterable<String> deprecatedKeys() {
* Returns the description of this option.
* @return The option's description.
*/
public String description() {
public Description description() {
return description;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.flink.configuration.description;

/**
* Part of description that represents a block e.g. some text, linebreak or a list.
*/
public interface BlockElement extends DescriptionElement {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.flink.configuration.description;

import java.util.ArrayList;
import java.util.List;

/**
* Description for {@link org.apache.flink.configuration.ConfigOption}. Allows providing multiple rich formats.
*/
public class Description {

private final List<BlockElement> blocks;

public static DescriptionBuilder builder() {
return new DescriptionBuilder();
}

public List<BlockElement> getBlocks() {
return blocks;
}

/**
* Builder for {@link Description}. Allows adding a rich formatting like lists, links, linebreaks etc.
* For example:
* <pre>{@code
* Description description = Description.builder()
* .text("This is some list: ")
* .list(
* text("this is first element of list"),
* text("this is second element of list with a %s", link("https://link")))
* .build();
* }</pre>
*/
public static class DescriptionBuilder {

private final List<BlockElement> blocks = new ArrayList<>();

/**
* Adds a block of text with placeholders ("%s") that will be replaced with proper string representation of
* given {@link InlineElement}. For example:
*
* <p>{@code text("This is a text with a link %s", link("https://somepage", "to here"))}
*
* @param format text with placeholders for elements
* @param elements elements to be put in the text
* @return description with added block of text
*/
public DescriptionBuilder text(String format, InlineElement... elements) {
blocks.add(TextElement.text(format, elements));
return this;
}

/**
* Creates a simple block of text.
*
* @param text a simple block of text
* @return block of text
*/
public DescriptionBuilder text(String text) {
blocks.add(TextElement.text(text));
return this;
}

/**
* Creates a line break in the description.
*/
public DescriptionBuilder linebreak() {
blocks.add(LineBreakElement.linebreak());
return this;
}

/**
* Adds a bulleted list to the description.
*/
public DescriptionBuilder list(InlineElement... elements) {
blocks.add(ListElement.list(elements));
return this;
}

/**
* Creates description representation.
*/
public Description build() {
return new Description(blocks);
}

}

private Description(List<BlockElement> blocks) {
this.blocks = blocks;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.flink.configuration.description;

/**
* Part of a {@link Description} that can be converted into String representation.
*/
interface DescriptionElement {
/**
* Transforms itself into String representation using given format.
*
* @param formatter formatter to use.
*/
void format(Formatter formatter);
}
Loading

0 comments on commit a457a35

Please sign in to comment.