{"record":{"id":"e23a9b676b43ae33","repo":"zhisheng17/flink-learning","slug":"invalid-host-port-configuration-host-host-por","errorCode":null,"errorMessage":"Invalid host/port configuration. Host: ${host} Port: ${port}","messagePattern":"Invalid host/port configuration\\. Host: (.+?) Port: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-learning-extends/flink-metrics/flink-metrics-prometheus/src/main/java/org/apache/flink/metrics/prometheus/PrometheusPushGatewayReporter.java","lineNumber":68,"sourceCode":"\tprivate Map<String, String> groupingKey;\n\tprivate String appId;\n\tprivate String taskName;\n\tprivate String taskId;\n\n\t@Override\n\tpublic void open(MetricConfig config) {\n\t\tsuper.open(config);\n\n\t\tString host = config.getString(HOST.key(), HOST.defaultValue());\n\t\tint port = config.getInteger(PORT.key(), PORT.defaultValue());\n\t\tString clusterMode = config.getString(CLUSTER_MODE.key(), CLUSTER_MODE.defaultValue());\n\t\tString configuredJobName = config.getString(JOB_NAME.key(), JOB_NAME.defaultValue());\n\t\tboolean randomSuffix = config.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue());\n\t\tdeleteOnShutdown = config.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue());\n\t\tgroupingKey = parseGroupingKey(config.getString(GROUPING_KEY.key(), GROUPING_KEY.defaultValue()));\n\n\t\tif (host == null || host.isEmpty() || port < 1) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Invalid host/port configuration. Host: \" + host + \" Port: \" + port);\n\t\t}\n\n\t\tProperties properties = System.getProperties();\n\t\ttaskName = properties.getProperty(\"taskName\", null);\n\t\ttaskId = properties.getProperty(\"taskId\", null);\n\n\t\tString jobNamePrefix = \"\";\n\t\tif (!StringUtils.isNullOrWhitespaceOnly(clusterMode) && clusterMode\n\t\t\t.toUpperCase()\n\t\t\t.equals(ClusterMode.YARN.name())) {\n\t\t\t//yarn cluster\n\t\t\tappId = System.getenv(\"_APP_ID\");\n\t\t\tif (!StringUtils.isNullOrWhitespaceOnly(appId)) {\n\t\t\t\tjobNamePrefix = appId + \"_jobmanager\";\n\t\t\t} else {\n\t\t\t\tString pwd = System.getenv(\"PWD\");\n\t\t\t\tString[] values = pwd.split(File.separator);","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-extends/flink-metrics/flink-metrics-prometheus/src/main/java/org/apache/flink/metrics/prometheus/PrometheusPushGatewayReporter.java#L50-L86","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nmetrics.reporter.promgateway.factory.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterFactory\n# after\nmetrics.reporter.promgateway.factory.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterFactory\nmetrics.reporter.promgateway.host: pushgateway-host\nmetrics.reporter.promgateway.port: 9091","handlingStrategy":"validation","validationCode":"String host = config.getString(\"metrics.reporter.promgateway.host\", \"\");\nint port = config.getInteger(\"metrics.reporter.promgateway.port\", -1);\nif (host == null || host.isEmpty() || port < 1)\n    throw new IllegalStateException(\"promgateway reporter needs non-empty host and port >= 1\");","typeGuard":null,"tryCatchPattern":"try {\n    reporter.open(metrics);\n} catch (IllegalArgumentException e) {\n    LOG.error(\"PushGateway reporter misconfigured: {}\", e.getMessage());\n    throw e; // config error should fail fast\n}","preventionTips":["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"],"tags":["flink","metrics","prometheus","config"],"backgroundTag":"invalid-config-value","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}