rionmonster commented on a change in pull request #15165: URL: https://github.com/apache/flink/pull/15165#discussion_r593477758
########## File path: flink-metrics/flink-metrics-prometheus/src/main/java/org/apache/flink/metrics/prometheus/PrometheusPushGatewayReporter.java ########## @@ -56,43 +56,42 @@ private boolean deleteOnShutdown; private Map<String, String> groupingKey; - @Override - public void open(MetricConfig config) { - super.open(config); - - String host = config.getString(HOST.key(), HOST.defaultValue()); - int port = config.getInteger(PORT.key(), PORT.defaultValue()); - String configuredJobName = config.getString(JOB_NAME.key(), JOB_NAME.defaultValue()); - boolean randomSuffix = - config.getBoolean( - RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue()); - deleteOnShutdown = - config.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue()); - groupingKey = - parseGroupingKey(config.getString(GROUPING_KEY.key(), GROUPING_KEY.defaultValue())); - - if (host == null || host.isEmpty() || port < 1) { + PrometheusPushGatewayReporter( + @Nullable final String hostConfig, + @Nullable final int portConfig, + @Nullable final String jobNameConfig, + @Nullable final boolean randomJobSuffixConfig, + @Nullable final boolean deleteOnShutdownConfig, + @Nullable final Map<String, String> groupingKeyConfig + ) { + deleteOnShutdown = deleteOnShutdownConfig + groupingKey = parseGroupingKey(groupingKeyConfig) + + if (hostConfig == null || hostConfig.isEmpty() || portConfig < 1) { throw new IllegalArgumentException( - "Invalid host/port configuration. Host: " + host + " Port: " + port); + "Invalid host/port configuration. Host: " + hostConfig + " Port: " + portConfig); } - if (randomSuffix) { - this.jobName = configuredJobName + new AbstractID(); + if (randomJobSuffixConfig) { + this.jobName = jobNameConfig + new AbstractID(); } else { - this.jobName = configuredJobName; + this.jobName = jobNameConfig; } - pushGateway = new PushGateway(host + ':' + port); + pushGateway = new PushGateway(hostConfig + ':' + portConfig); log.info( "Configured PrometheusPushGatewayReporter with {host:{}, port:{}, jobName:{}, randomJobNameSuffix:{}, deleteOnShutdown:{}, groupingKey:{}}", - host, - port, - jobName, - randomSuffix, + hostConfig, + portConfig, + jobNameConfig, + randomJobSuffixConfig, deleteOnShutdown, groupingKey); } + @Override + public void open(MetricConfig config) { } + Map<String, String> parseGroupingKey(final String groupingKeyConfig) { Review comment: Okay, totally right. I was _way_ overthinking this. I'll probably burn this branch down and pull latest to avoid too much shuffling around. Much appreciated! ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org