Repository: apache/flink
File: flink-metrics/flink-metrics-prometheus/src/main/java/org/apache/flink/metrics/prometheus/PrometheusPushGatewayReporterFactory.java (Java)

Code before:
    @Override
    public PrometheusPushGatewayReporter createMetricReporter(Properties properties) {
        MetricConfig metricConfig = (MetricConfig) properties;
        String configuredJobName = metricConfig.getString(JOB_NAME.key(), JOB_NAME.defaultValue());
        boolean randomSuffix =
                metricConfig.getBoolean(
                        RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue());
        boolean deleteOnShutdown =
                metricConfig.getBoolean(
                        DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue());
        Map<String, String> groupingKey =
                parseGroupingKey(
                        metricConfig.getString(GROUPING_KEY.key(), GROUPING_KEY.defaultValue()));

        String hostUrl = metricConfig.getString(HOST_URL.key(), HOST_URL.defaultValue());

        if (StringUtils.isNullOrWhitespaceOnly(hostUrl)) {
            throw new IllegalArgumentException("hostUrl must not be null or empty");
        }

        String jobName = configuredJobName;
        if (randomSuffix) {
            jobName = configuredJobName + new AbstractID();
        }

        String username = metricConfig.getString(USERNAME.key(), null);
        String password = metricConfig.getString(PASSWORD.key(), null);

        if ((username != null && password == null) || (username == null && password != null)) {
            LOG.warn(
                    "Both username and password must be configured to enable HTTP Basic Authentication. "
                            + "Currently only {} is configured, Basic Auth will be disabled.",
                    username != null ? "username" : "password");
        }

        LOG.info(
                "Configured PrometheusPushGatewayReporter with {hostUrl:{}, jobName:{}, randomJobNameSuffix:{}, deleteOnShutdown:{}, groupingKey:{}, basicAuth:{}}",
                hostUrl,
                jobName,
                randomSuffix,
                deleteOnShutdown,
                groupingKey,
                username != null && password != null);

        try {
            return new PrometheusPushGatewayReporter(
                    new URL(hostUrl), jobName, groupingKey, deleteOnShutdown, username, password);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

Review comment (suggestion):
Minor consistency nit: for consistency, we may want to use  `defaultValue()` instead of `null` here as those would both functionally identical (null) but would follow the same pattern as the other available configuration options.

For example, `HOST_URL`:
```
String hostUrl = metricConfig.getString(HOST_URL.key(), HOST_URL.defaultValue());
```

Code after:
    @Override
    public PrometheusPushGatewayReporter createMetricReporter(Properties properties) {
        MetricConfig metricConfig = (MetricConfig) properties;
        String configuredJobName = metricConfig.getString(JOB_NAME.key(), JOB_NAME.defaultValue());
        boolean randomSuffix =
                metricConfig.getBoolean(
                        RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue());
        boolean deleteOnShutdown =
                metricConfig.getBoolean(
                        DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue());
        Map<String, String> groupingKey =
                parseGroupingKey(
                        metricConfig.getString(GROUPING_KEY.key(), GROUPING_KEY.defaultValue()));

        String hostUrl = metricConfig.getString(HOST_URL.key(), HOST_URL.defaultValue());

        if (StringUtils.isNullOrWhitespaceOnly(hostUrl)) {
            throw new IllegalArgumentException("hostUrl must not be null or empty");
        }

        String jobName = configuredJobName;
        if (randomSuffix) {
            jobName = configuredJobName + new AbstractID();
        }

        String username = metricConfig.getString(USERNAME.key(), USERNAME.defaultValue());
        String password = metricConfig.getString(PASSWORD.key(), PASSWORD.defaultValue());

        if ((username != null && password == null) || (username == null && password != null)) {
            LOG.warn(
                    "Both username and password must be configured to enable HTTP Basic Authentication. "
                            + "Currently only {} is configured, Basic Auth will be disabled.",
                    username != null ? "username" : "password");
        }

        try {
            PrometheusPushGatewayReporter reporter =
                    new PrometheusPushGatewayReporter(
                            new URL(hostUrl),
                            jobName,
                            groupingKey,
                            deleteOnShutdown,
                            username,
                            password);

            LOG.info(
                    "Configured PrometheusPushGatewayReporter with {hostUrl:{}, jobName:{}, randomJobNameSuffix:{}, deleteOnShutdown:{}, groupingKey:{}, basicAuth:{}}",
                    hostUrl,
                    jobName,
                    randomSuffix,
                    deleteOnShutdown,