Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -456,7 +457,7 @@ private boolean getPrometheusTimestampsInMs() {

private Scheme getScheme(@Nullable ExporterPushgatewayProperties properties) {
if (properties != null && properties.getScheme() != null) {
return Scheme.valueOf(properties.getScheme());
return Scheme.fromString(properties.getScheme().toLowerCase(Locale.ROOT));
} else if (this.scheme != null) {
return this.scheme;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static org.mockserver.model.HttpResponse.response;

import io.prometheus.metrics.config.EscapingScheme;
import io.prometheus.metrics.config.ExporterPushgatewayProperties;
import io.prometheus.metrics.config.PrometheusProperties;
import io.prometheus.metrics.config.PrometheusPropertiesException;
import io.prometheus.metrics.core.metrics.Gauge;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
Expand Down Expand Up @@ -66,6 +68,32 @@ void testMultipleSlashesAreStrippedFromURL() throws NoSuchFieldException, Illega
.hasToString("http://example.com:1234/context/path/metrics/job/test");
}

@Test
void testSchemeFromProperties() throws NoSuchFieldException, IllegalAccessException {
PrometheusProperties properties =
PrometheusProperties.builder()
.pushgatewayProperties(ExporterPushgatewayProperties.builder().scheme("https").build())
.build();

PushGateway pushGateway =
PushGateway.builder(properties).address("example.com:1234").job("test").build();

assertThat(getUrl(pushGateway)).hasToString("https://example.com:1234/metrics/job/test");
}

@Test
void testUpperCaseSchemeFromProperties() throws NoSuchFieldException, IllegalAccessException {
PrometheusProperties properties =
PrometheusProperties.builder()
.pushgatewayProperties(ExporterPushgatewayProperties.builder().scheme("HTTPS").build())
.build();

PushGateway pushGateway =
PushGateway.builder(properties).address("example.com:1234").job("test").build();

assertThat(getUrl(pushGateway)).hasToString("https://example.com:1234/metrics/job/test");
}

private URL getUrl(PushGateway pushGateway) throws IllegalAccessException, NoSuchFieldException {
Field field = pushGateway.getClass().getDeclaredField("url");
field.setAccessible(true);
Expand Down
Loading