Skip to content

Commit

Permalink
[FLINK-26851][metrics] Migrate reporter options to proper ConfigOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
zentol committed Mar 28, 2022
1 parent ebca624 commit e640840
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 107 deletions.
12 changes: 3 additions & 9 deletions docs/content.zh/docs/deployment/metric_reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ For more information about Flink's metric system go to the [metric system docume
Metrics can be exposed to an external system by configuring one or several reporters in `conf/flink-conf.yaml`. These
reporters will be instantiated on each job and task manager when they are started.

- `metrics.reporter.<name>.<config>`: Generic setting `<config>` for the reporter named `<name>`.
- `metrics.reporter.<name>.class`: The reporter class to use for the reporter named `<name>`.
- `metrics.reporter.<name>.factory.class`: The reporter factory class to use for the reporter named `<name>`.
- `metrics.reporter.<name>.interval`: The reporter interval to use for the reporter named `<name>`.
- `metrics.reporter.<name>.scope.delimiter`: The delimiter to use for the identifier (default value use `metrics.scope.delimiter`) for the reporter named `<name>`.
- `metrics.reporter.<name>.scope.variables.excludes`: (optional) A semi-colon (;) separate list of variables that should be ignored by tag-based reporters (e.g., Prometheus, InfluxDB).
- `metrics.reporters`: (optional) A comma-separated include list of reporter names. By default all configured reporters will be used.
- `metrics.reporter.<name>.scope.variables.additional`: (optional) A comma separated map of variables and their values, which are separated by a colon (:). These mappings are added to the variable map by tag-based reporters (e.g. Prometheux, InfluxDB).
Below is a list of parameters that are generally applicable to all reporters. All properties are configured by setting `metrics.reporter.<reporter_name>.<property>` in the configuration. Reporters may additionally offer implementation-specific parameters, which are documented in the respective reporter's section.

{{< include_reporter_config "layouts/shortcodes/generated/metric_reporters_section.html" >}}

All reporters must at least have either the `class` or `factory.class` property. Which property may/should be used depends on the reporter implementation. See the individual reporter configuration sections for more information.
Some reporters (referred to as `Scheduled`) allow specifying a reporting `interval`.
Below more settings specific to each reporter will be listed.

Example reporter configuration that specifies multiple reporters:

Expand Down
12 changes: 3 additions & 9 deletions docs/content/docs/deployment/metric_reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ For more information about Flink's metric system go to the [metric system docume
Metrics can be exposed to an external system by configuring one or several reporters in `conf/flink-conf.yaml`. These
reporters will be instantiated on each job and task manager when they are started.

- `metrics.reporter.<name>.<config>`: Generic setting `<config>` for the reporter named `<name>`.
- `metrics.reporter.<name>.class`: The reporter class to use for the reporter named `<name>`.
- `metrics.reporter.<name>.factory.class`: The reporter factory class to use for the reporter named `<name>`.
- `metrics.reporter.<name>.interval`: The reporter interval to use for the reporter named `<name>`.
- `metrics.reporter.<name>.scope.delimiter`: The delimiter to use for the identifier (default value use `metrics.scope.delimiter`) for the reporter named `<name>`.
- `metrics.reporter.<name>.scope.variables.excludes`: (optional) A semi-colon (;) separate list of variables that should be ignored by tag-based reporters (e.g., Prometheus, InfluxDB).
- `metrics.reporter.<name>.scope.variables.additional`: (optional) A comma separated map of variables and their values, which are separated by a colon (:). These mappings are added to the variable map by tag-based reporters (e.g. Prometheux, InfluxDB).
- `metrics.reporters`: (optional) A comma-separated include list of reporter names. By default all configured reporters will be used.
Below is a list of parameters that are generally applicable to all reporters. All properties are configured by setting `metrics.reporter.<reporter_name>.<property>` in the configuration. Reporters may additionally offer implementation-specific parameters, which are documented in the respective reporter's section.

{{< include_reporter_config "layouts/shortcodes/generated/metric_reporters_section.html" >}}

All reporters must at least have either the `class` or `factory.class` property. Which property may/should be used depends on the reporter implementation. See the individual reporter configuration sections for more information.
Some reporters (referred to as `Scheduled`) allow specifying a reporting `interval`.
Below more settings specific to each reporter will be listed.

Example reporter configuration that specifies multiple reporters:

Expand Down
24 changes: 24 additions & 0 deletions docs/layouts/shortcodes/generated/metric_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,36 @@
<td>String</td>
<td>The reporter class to use for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.factory.class</h5></td>
<td style="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>The reporter factory class to use for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.interval</h5></td>
<td style="word-wrap: break-word;">10 s</td>
<td>Duration</td>
<td>The reporter interval to use for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.scope.delimiter</h5></td>
<td style="word-wrap: break-word;">"."</td>
<td>String</td>
<td>The delimiter used to assemble the metric identifier for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.scope.variables.additional</h5></td>
<td style="word-wrap: break-word;"></td>
<td>Map</td>
<td>The map of additional variables that should be included for the reporter named &lt;name&gt;. Only applicable to tag-based reporters (e.g., PRometheus, InfluxDB).</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.scope.variables.excludes</h5></td>
<td style="word-wrap: break-word;">"."</td>
<td>String</td>
<td>The set of variables that should be excluded for the reporter named &lt;name&gt;. Only applicable to tag-based reporters (e.g., PRometheus, InfluxDB).</td>
</tr>
<tr>
<td><h5>metrics.reporters</h5></td>
<td style="word-wrap: break-word;">(none)</td>
Expand Down
54 changes: 54 additions & 0 deletions docs/layouts/shortcodes/generated/metric_reporters_section.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<table class="configuration table table-bordered">
<thead>
<tr>
<th class="text-left" style="width: 20%">Key</th>
<th class="text-left" style="width: 15%">Default</th>
<th class="text-left" style="width: 10%">Type</th>
<th class="text-left" style="width: 55%">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.class</h5></td>
<td style="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>The reporter class to use for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.factory.class</h5></td>
<td style="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>The reporter factory class to use for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.interval</h5></td>
<td style="word-wrap: break-word;">10 s</td>
<td>Duration</td>
<td>The reporter interval to use for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.scope.delimiter</h5></td>
<td style="word-wrap: break-word;">"."</td>
<td>String</td>
<td>The delimiter used to assemble the metric identifier for the reporter named &lt;name&gt;.</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.scope.variables.additional</h5></td>
<td style="word-wrap: break-word;"></td>
<td>Map</td>
<td>The map of additional variables that should be included for the reporter named &lt;name&gt;. Only applicable to tag-based reporters (e.g., PRometheus, InfluxDB).</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.scope.variables.excludes</h5></td>
<td style="word-wrap: break-word;">"."</td>
<td>String</td>
<td>The set of variables that should be excluded for the reporter named &lt;name&gt;. Only applicable to tag-based reporters (e.g., PRometheus, InfluxDB).</td>
</tr>
<tr>
<td><h5>metrics.reporter.&lt;name&gt;.&lt;parameter&gt;</h5></td>
<td style="word-wrap: break-word;">(none)</td>
<td>String</td>
<td>Configures the parameter &lt;parameter&gt; for the reporter named &lt;name&gt;.</td>
</tr>
</tbody>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public static final class Sections {

public static final String DEPRECATED_FILE_SINKS = "deprecated_file_sinks";

public static final String METRIC_REPORTERS = "metric_reporters";

private Sections() {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.flink.configuration.ConfigConstants;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.configuration.MetricOptions;
import org.apache.flink.configuration.TaskManagerOptions;
import org.apache.flink.metrics.jmx.JMXReporter;
import org.apache.flink.runtime.client.JobExecutionException;
Expand Down Expand Up @@ -133,7 +134,7 @@ public static Configuration getFlinkConfiguration() {
flinkConfig.setString(
ConfigConstants.METRICS_REPORTER_PREFIX
+ "my_reporter."
+ ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX,
+ MetricOptions.REPORTER_CLASS.key(),
JMXReporter.class.getName());
return flinkConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1113,28 +1113,24 @@ public final class ConfigConstants {
*/
public static final String METRICS_REPORTER_PREFIX = "metrics.reporter.";

/** The class of the reporter to use. This is used as a suffix in an actual reporter config */
public static final String METRICS_REPORTER_CLASS_SUFFIX = "class";
/** @deprecated use {@link MetricOptions#REPORTER_CLASS} */
@Deprecated public static final String METRICS_REPORTER_CLASS_SUFFIX = "class";

/**
* The class of the reporter factory to use. This is used as a suffix in an actual reporter
* config
*/
public static final String METRICS_REPORTER_FACTORY_CLASS_SUFFIX = "factory.class";
/** @deprecated use {@link MetricOptions#REPORTER_FACTORY_CLASS} */
@Deprecated public static final String METRICS_REPORTER_FACTORY_CLASS_SUFFIX = "factory.class";

/** The interval between reports. This is used as a suffix in an actual reporter config */
public static final String METRICS_REPORTER_INTERVAL_SUFFIX = "interval";
/** @deprecated use {@link MetricOptions#REPORTER_INTERVAL} */
@Deprecated public static final String METRICS_REPORTER_INTERVAL_SUFFIX = "interval";

/**
* The delimiter used to assemble the metric identifier. This is used as a suffix in an actual
* reporter config.
*/
public static final String METRICS_REPORTER_SCOPE_DELIMITER = "scope.delimiter";
/** @deprecated use {@link MetricOptions#REPORTER_SCOPE_DELIMITER} */
@Deprecated public static final String METRICS_REPORTER_SCOPE_DELIMITER = "scope.delimiter";

/** The set of variables that should be excluded. */
/** @deprecated use {@link MetricOptions#REPORTER_EXCLUDED_VARIABLES} */
@Deprecated
public static final String METRICS_REPORTER_EXCLUDED_VARIABLES = "scope.variables.excludes";

/** The map of additional variables that should be included. */
/** @deprecated use {@link MetricOptions#REPORTER_ADDITIONAL_VARIABLES} */
@Deprecated
public static final String METRICS_REPORTER_ADDITIONAL_VARIABLES = "scope.variables.additional";

/** @deprecated Use {@link MetricOptions#SCOPE_DELIMITER} instead. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import org.apache.flink.configuration.description.TextElement;

import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.apache.flink.configuration.ConfigOptions.key;
import static org.apache.flink.configuration.description.TextElement.text;
Expand All @@ -34,6 +36,9 @@
@PublicEvolving
public class MetricOptions {

private static final String NAMED_REPORTER_CONFIG_PREFIX =
ConfigConstants.METRICS_REPORTER_PREFIX + "<name>";

/**
* An optional list of reporter names. If configured, only reporters whose name matches any of
* the names in the list will be started. Otherwise, all reporters that could be found in the
Expand All @@ -60,20 +65,62 @@ public class MetricOptions {
+ " any of the names in the list will be started. Otherwise, all reporters that could be found in"
+ " the configuration will be started.");

@Documentation.SuffixOption(NAMED_REPORTER_CONFIG_PREFIX)
@Documentation.Section(value = Documentation.Sections.METRIC_REPORTERS, position = 1)
public static final ConfigOption<String> REPORTER_CLASS =
key("metrics.reporter.<name>.class")
key("class")
.stringType()
.noDefaultValue()
.withDescription("The reporter class to use for the reporter named <name>.");

@Documentation.SuffixOption(NAMED_REPORTER_CONFIG_PREFIX)
@Documentation.Section(value = Documentation.Sections.METRIC_REPORTERS, position = 1)
public static final ConfigOption<String> REPORTER_FACTORY_CLASS =
key("factory.class")
.stringType()
.noDefaultValue()
.withDescription(
"The reporter factory class to use for the reporter named <name>.");

@Documentation.SuffixOption(NAMED_REPORTER_CONFIG_PREFIX)
@Documentation.Section(value = Documentation.Sections.METRIC_REPORTERS, position = 2)
public static final ConfigOption<Duration> REPORTER_INTERVAL =
key("metrics.reporter.<name>.interval")
key("interval")
.durationType()
.defaultValue(Duration.ofSeconds(10))
.withDescription("The reporter interval to use for the reporter named <name>.");

@Documentation.SuffixOption(NAMED_REPORTER_CONFIG_PREFIX)
@Documentation.Section(value = Documentation.Sections.METRIC_REPORTERS, position = 2)
public static final ConfigOption<String> REPORTER_SCOPE_DELIMITER =
key("scope.delimiter")
.stringType()
.defaultValue(".")
.withDescription(
"The delimiter used to assemble the metric identifier for the reporter named <name>.");

@Documentation.SuffixOption(NAMED_REPORTER_CONFIG_PREFIX)
@Documentation.Section(value = Documentation.Sections.METRIC_REPORTERS, position = 3)
public static final ConfigOption<Map<String, String>> REPORTER_ADDITIONAL_VARIABLES =
key("scope.variables.additional")
.mapType()
.defaultValue(Collections.emptyMap())
.withDescription(
"The map of additional variables that should be included for the reporter named <name>. Only applicable to tag-based reporters (e.g., PRometheus, InfluxDB).");

@Documentation.SuffixOption(NAMED_REPORTER_CONFIG_PREFIX)
@Documentation.Section(value = Documentation.Sections.METRIC_REPORTERS, position = 3)
public static final ConfigOption<String> REPORTER_EXCLUDED_VARIABLES =
key("scope.variables.excludes")
.stringType()
.defaultValue(".")
.withDescription(
"The set of variables that should be excluded for the reporter named <name>. Only applicable to tag-based reporters (e.g., PRometheus, InfluxDB).");

@Documentation.SuffixOption(NAMED_REPORTER_CONFIG_PREFIX)
@Documentation.Section(value = Documentation.Sections.METRIC_REPORTERS, position = 4)
public static final ConfigOption<String> REPORTER_CONFIG_PARAMETER =
key("metrics.reporter.<name>.<parameter>")
key("<parameter>")
.stringType()
.noDefaultValue()
.withDescription(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.flink.configuration.ConfigConstants;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.MetricOptions;
import org.apache.flink.metrics.prometheus.PrometheusReporter;
import org.apache.flink.metrics.prometheus.PrometheusReporterFactory;
import org.apache.flink.tests.util.AutoClosableProcess;
Expand Down Expand Up @@ -179,14 +180,14 @@ private static Configuration getFlinkConfig(TestParams.InstantiationType instant
config.setString(
ConfigConstants.METRICS_REPORTER_PREFIX
+ "prom."
+ ConfigConstants.METRICS_REPORTER_FACTORY_CLASS_SUFFIX,
+ MetricOptions.REPORTER_FACTORY_CLASS.key(),
PrometheusReporterFactory.class.getName());
break;
case REFLECTION:
config.setString(
ConfigConstants.METRICS_REPORTER_PREFIX
+ "prom."
+ ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX,
+ MetricOptions.REPORTER_CLASS.key(),
PrometheusReporter.class.getCanonicalName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static Configuration getConfiguration() {
flinkConfiguration.setString(
ConfigConstants.METRICS_REPORTER_PREFIX
+ "test."
+ ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX,
+ MetricOptions.REPORTER_CLASS.key(),
JMXReporter.class.getName());
flinkConfiguration.setString(MetricOptions.SCOPE_NAMING_JM_JOB, "jobmanager.<job_name>");

Expand Down
Loading

0 comments on commit e640840

Please sign in to comment.