1
1
package io .prometheus .client .exporter ;
2
2
3
+ import com .sun .net .httpserver .HttpsConfigurator ;
4
+ import com .sun .net .httpserver .HttpsServer ;
3
5
import io .prometheus .client .CollectorRegistry ;
4
6
import io .prometheus .client .SampleNameFilter ;
5
7
import io .prometheus .client .Predicate ;
@@ -200,6 +202,7 @@ public static class Builder {
200
202
private Predicate <String > sampleNameFilter ;
201
203
private Supplier <Predicate <String >> sampleNameFilterSupplier ;
202
204
private Authenticator authenticator ;
205
+ private HttpsConfigurator httpsConfigurator ;
203
206
204
207
/**
205
208
* Port to bind to. Must not be called together with {@link #withInetSocketAddress(InetSocketAddress)}
@@ -299,6 +302,14 @@ public Builder withAuthenticator(Authenticator authenticator) {
299
302
return this ;
300
303
}
301
304
305
+ /**
306
+ * Optional: {@link HttpsConfigurator} to use to support TLS/SSL
307
+ */
308
+ public Builder withHttpsConfigurator (HttpsConfigurator configurator ) {
309
+ this .httpsConfigurator = configurator ;
310
+ return this ;
311
+ }
312
+
302
313
/**
303
314
* Build the HTTPServer
304
315
* @throws IOException
@@ -308,11 +319,13 @@ public HTTPServer build() throws IOException {
308
319
assertNull (sampleNameFilterSupplier , "cannot configure 'sampleNameFilter' and 'sampleNameFilterSupplier' at the same time" );
309
320
sampleNameFilterSupplier = SampleNameFilterSupplier .of (sampleNameFilter );
310
321
}
322
+
311
323
if (httpServer != null ) {
312
324
assertZero (port , "cannot configure 'httpServer' and 'port' at the same time" );
313
325
assertNull (hostname , "cannot configure 'httpServer' and 'hostname' at the same time" );
314
326
assertNull (inetAddress , "cannot configure 'httpServer' and 'inetAddress' at the same time" );
315
327
assertNull (inetSocketAddress , "cannot configure 'httpServer' and 'inetSocketAddress' at the same time" );
328
+ assertNull (httpsConfigurator , "cannot configure 'httpServer' and 'httpsConfigurator' at the same time" );
316
329
return new HTTPServer (httpServer , registry , daemon , sampleNameFilterSupplier , authenticator );
317
330
} else if (inetSocketAddress != null ) {
318
331
assertZero (port , "cannot configure 'inetSocketAddress' and 'port' at the same time" );
@@ -326,7 +339,16 @@ public HTTPServer build() throws IOException {
326
339
} else {
327
340
inetSocketAddress = new InetSocketAddress (port );
328
341
}
329
- return new HTTPServer (HttpServer .create (inetSocketAddress , 3 ), registry , daemon , sampleNameFilterSupplier , authenticator );
342
+
343
+ HttpServer httpServer = null ;
344
+ if (httpsConfigurator != null ) {
345
+ httpServer = HttpsServer .create (inetSocketAddress , 3 );
346
+ ((HttpsServer )httpServer ).setHttpsConfigurator (httpsConfigurator );
347
+ } else {
348
+ httpServer = HttpServer .create (inetSocketAddress , 3 );
349
+ }
350
+
351
+ return new HTTPServer (httpServer , registry , daemon , sampleNameFilterSupplier , authenticator );
330
352
}
331
353
332
354
private void assertNull (Object o , String msg ) {
0 commit comments