Skip to content

Commit dc4225d

Browse files
committed
Merge branch '1.9.x' into 1.10.x
2 parents 1f7a059 + c5c6ed2 commit dc4225d

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

implementations/micrometer-registry-wavefront/src/main/java/io/micrometer/wavefront/WavefrontConfig.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
package io.micrometer.wavefront;
1717

1818
import io.micrometer.common.lang.Nullable;
19+
import io.micrometer.core.instrument.config.MeterRegistryConfig;
1920
import io.micrometer.core.instrument.config.validate.InvalidReason;
2021
import io.micrometer.core.instrument.config.validate.Validated;
2122
import io.micrometer.core.instrument.push.PushRegistryConfig;
2223

2324
import java.net.InetAddress;
25+
import java.net.URI;
2426
import java.net.UnknownHostException;
2527

2628
import static io.micrometer.core.instrument.config.MeterRegistryConfigValidator.*;
@@ -82,7 +84,7 @@ default String prefix() {
8284
* proxy://HOST:PORT format.
8385
*/
8486
default String uri() {
85-
return getUrlString(this, "uri").required().get();
87+
return getUriString(this, "uri").required().get();
8688
}
8789

8890
/**
@@ -174,4 +176,17 @@ default Validated<?> validateSenderConfiguration() {
174176
"must be set whenever publishing directly to the Wavefront API", InvalidReason.MISSING)));
175177
}
176178

179+
// different from getUrlString for gh-3903
180+
static Validated<String> getUriString(MeterRegistryConfig config, String property) {
181+
String prefixedProperty = config.prefix() + '.' + property;
182+
String value = config.get(prefixedProperty);
183+
184+
try {
185+
return Validated.valid(prefixedProperty, value == null ? null : URI.create(value)).map(url -> value);
186+
}
187+
catch (IllegalArgumentException ex) {
188+
return Validated.invalid(prefixedProperty, value, "must be a valid URI", InvalidReason.MALFORMED, ex);
189+
}
190+
}
191+
177192
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2023 VMware, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micrometer.wavefront;
17+
18+
import io.micrometer.core.Issue;
19+
import io.micrometer.core.instrument.config.validate.ValidationException;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.io.IOException;
23+
import java.util.Properties;
24+
25+
import static org.assertj.core.api.Assertions.assertThatCode;
26+
27+
class WavefrontConfigTest {
28+
29+
@Issue("#3903")
30+
@Test
31+
void defaultUriImplementationWorksWithProxyUri() throws IOException {
32+
Properties wavefrontProps = new Properties();
33+
wavefrontProps.load(this.getClass().getResourceAsStream("/valid.properties"));
34+
WavefrontConfig config = wavefrontProps::getProperty;
35+
assertThatCode(config::uri).doesNotThrowAnyException();
36+
}
37+
38+
@Test
39+
void defaultUriImplementationThrowsForInvalidUri() throws IOException {
40+
Properties wavefrontProps = new Properties();
41+
wavefrontProps.load(this.getClass().getResourceAsStream("/invalid.properties"));
42+
WavefrontConfig config = wavefrontProps::getProperty;
43+
assertThatCode(config::uri).isExactlyInstanceOf(ValidationException.class)
44+
.hasMessageContaining("it must be a valid URI");
45+
}
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright 2023 VMware, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
wavefront.uri=:not-a-uri
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright 2023 VMware, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
wavefront.uri=proxy://example.com:2878

0 commit comments

Comments
 (0)