zhisheng17/flink-learning · error · IllegalArgumentException
Invalid host/port configuration. Host: ${host} Port: ${port}
Error message
Invalid host/port configuration. Host: ${host} Port: ${port} What it means
PrometheusPushGatewayReporter validates its host and port config in open(). It throws IllegalArgumentException when hostFromConfig is null/empty or the configured port is less than 1, because a Pushgateway endpoint cannot be built without them.
Source
Thrown at flink-learning-extends/flink-metrics/flink-metrics-prometheus/src/main/java/org/apache/flink/metrics/prometheus/PrometheusPushGatewayReporter.java:68
private Map<String, String> groupingKey;
private String appId;
private String taskName;
private String taskId;
@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 clusterMode = config.getString(CLUSTER_MODE.key(), CLUSTER_MODE.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) {
throw new IllegalArgumentException(
"Invalid host/port configuration. Host: " + host + " Port: " + port);
}
Properties properties = System.getProperties();
taskName = properties.getProperty("taskName", null);
taskId = properties.getProperty("taskId", null);
String jobNamePrefix = "";
if (!StringUtils.isNullOrWhitespaceOnly(clusterMode) && clusterMode
.toUpperCase()
.equals(ClusterMode.YARN.name())) {
//yarn cluster
appId = System.getenv("_APP_ID");
if (!StringUtils.isNullOrWhitespaceOnly(appId)) {
jobNamePrefix = appId + "_jobmanager";
} else {
String pwd = System.getenv("PWD");
String[] values = pwd.split(File.separator);View on GitHub (pinned to d731cee761)
Solutions
- Set metrics.reporter.<name>.host=<pushgateway-host> and metrics.reporter.<name>.port=9091 in flink-conf.yaml.
- Ensure the keys use the exact same <name> prefix as metrics.reporter.<name>.factory.class.
- Verify the Pushgateway is running and reachable at host:9091.
- Restart the Flink cluster/job so the reporter picks up new config.
Example fix
# before metrics.reporter.promgateway.factory.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterFactory # after metrics.reporter.promgateway.factory.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterFactory metrics.reporter.promgateway.host: pushgateway-host metrics.reporter.promgateway.port: 9091
Defensive patterns
Strategy: validation
Validate before calling
String host = config.getString("metrics.reporter.promgateway.host", "");
int port = config.getInteger("metrics.reporter.promgateway.port", -1);
if (host == null || host.isEmpty() || port < 1)
throw new IllegalStateException("promgateway reporter needs non-empty host and port >= 1"); Try / catch
try {
reporter.open(metrics);
} catch (IllegalArgumentException e) {
LOG.error("PushGateway reporter misconfigured: {}", e.getMessage());
throw e; // config error should fail fast
} Prevention
- Always set host and port keys with the same reporter name prefix
- Validate flink-conf.yaml reporter blocks in CI
- Use port 9091 (Pushgateway default) unless customized
- Watch for YAML indentation errors that silently drop keys
When it happens
Trigger: flink-conf.yaml metrics.reporter.<name>.host missing or empty, or .port set to 0/negative/garbage; config keys misspelled so defaults (null/0) are used.
Common situations: Misconfigured flink-conf.yaml reporter block; port typo like 'port: -1'; enabling the reporter without adding its host/port options; YAML indentation putting keys under the wrong reporter prefix.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Could not start PrometheusReporter HTTP server on any config
- invalid elasticsearch hosts format
- invalid elasticsearch hosts format
- This ${database} database does not exist!
- Unknown value for CONSUMER_OFFSET_RESET_TO.
AI-assisted analysis of zhisheng17/flink-learning@d731cee761 (2026-09-06).
Data as JSON: /api/errors/e23a9b676b43ae33.
Report an issue: GitHub.