weicheng-07 commented on code in PR #29151: URL: https://github.com/apache/flink/pull/29151#discussion_r3994802412
########## flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusPushGatewayReporterAuthenticationTest.java: ########## @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.metrics.prometheus; + +import org.apache.flink.metrics.MetricConfig; +import org.apache.flink.metrics.reporter.MetricReporter; +import org.apache.flink.metrics.reporter.MetricReporterFactory; +import org.apache.flink.metrics.reporter.Scheduled; + +import com.sun.net.httpserver.HttpServer; +import io.prometheus.client.Collector; +import io.prometheus.client.exporter.PushGateway; +import io.prometheus.client.exporter.common.TextFormat; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import java.net.InetSocketAddress; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; + +import static org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterOptions.DELETE_ON_SHUTDOWN; +import static org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterOptions.HOST_URL; +import static org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterOptions.JOB_NAME; +import static org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterOptions.PASSWORD; +import static org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterOptions.RANDOM_JOB_NAME_SUFFIX; +import static org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporterOptions.USERNAME; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** Tests authentication on actual PushGateway requests. */ +class PrometheusPushGatewayReporterAuthenticationTest { + + @ParameterizedTest + @CsvSource({ + "user, password, Basic dXNlcjpwYXNzd29yZA==", + "user, päss:word, Basic dXNlcjpww6Rzczp3b3Jk", + "'', '', Basic Og==", + ", ,", + "user, ,", + ", password," + }) + void testAuthenticationOnPushAndDeleteWithoutJaxb( + String username, String password, String expectedAuthorization) throws Exception { + final List<String> methods = Collections.synchronizedList(new ArrayList<>()); + final List<String> authorizations = Collections.synchronizedList(new ArrayList<>()); + final HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); + server.createContext( + "/metrics/job/test-job", + exchange -> { + try { + exchange.getRequestBody().readAllBytes(); + methods.add(exchange.getRequestMethod()); + authorizations.add(exchange.getRequestHeaders().getFirst("Authorization")); + exchange.sendResponseHeaders(202, -1); + } finally { + exchange.close(); + } + }); + server.start(); + try (URLClassLoader classLoader = createClassLoaderWithoutJaxb()) { + assertThatThrownBy(() -> classLoader.loadClass("javax.xml.bind.DatatypeConverter")) Review Comment: Removed the earlier assertion and retained the check on the reporter's defining classloader. Squashed the changes into `0a074852`, leaving one commit. The module `clean verify` passes all 34 tests; the updated regression still produces the three expected JAXB errors with the unfixed reporter. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
