1818import java .util .concurrent .ExecutorService ;
1919import java .util .concurrent .Executors ;
2020import java .util .function .Predicate ;
21+ import java .util .logging .Logger ;
2122import javax .annotation .Nullable ;
2223
2324/** A builder for {@link PrometheusHttpServer}. */
@@ -26,8 +27,12 @@ public final class PrometheusHttpServerBuilder {
2627 static final int DEFAULT_PORT = 9464 ;
2728 private static final String DEFAULT_HOST = "localhost" ;
2829 private static final MemoryMode DEFAULT_MEMORY_MODE = MemoryMode .REUSABLE_DATA ;
30+ private static final Logger LOGGER =
31+ Logger .getLogger (PrometheusHttpServerBuilder .class .getName ());
2932
30- private String host = DEFAULT_HOST ;
33+ // Temporarily nullable to detect when it's not set and log warning about 0.0.0.0 -> localhost
34+ // change
35+ @ Nullable private String host ;
3136 private int port = DEFAULT_PORT ;
3237 private PrometheusRegistry prometheusRegistry = new PrometheusRegistry ();
3338 private PrometheusMetricReaderBuilder metricReaderBuilder = PrometheusMetricReader .builder ();
@@ -178,9 +183,17 @@ public PrometheusHttpServer build() {
178183 "MemoryMode REUSEABLE_DATA cannot be used with custom executor, "
179184 + "since data may be corrupted if reading metrics concurrently" );
180185 }
186+ String resolvedHost = host ;
187+ if (resolvedHost == null ) {
188+ // TODO (jack-berg): Remove log after 1.64.0 release
189+ LOGGER .info (
190+ "PrometheusHttpServer host not set, defaulting to localhost. Previously defaulted to 0.0.0.0. "
191+ + "If you depend on the old behavior, set host to 0.0.0.0 explicitly." );
192+ resolvedHost = DEFAULT_HOST ;
193+ }
181194 return new PrometheusHttpServer (
182195 new PrometheusHttpServerBuilder (this ), // copy to prevent modification
183- host ,
196+ resolvedHost ,
184197 port ,
185198 executor ,
186199 prometheusRegistry ,
0 commit comments