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 @@ -69,6 +69,12 @@
<artifactId>jetty-servlet</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.prometheus.client.exporter.MetricsServlet;
import io.prometheus.client.hotspot.DefaultExports;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Enumeration;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -170,35 +169,45 @@ public void configure(Properties configuration) throws MetricsProviderLifeCycleE
public void start() throws MetricsProviderLifeCycleException {
this.executorOptional = createExecutor();
try {
LOG.info("Starting /metrics {} endpoint at HTTP port: {}, HTTPS port: {}, exportJvmInfo: {}",
httpPort > 0 ? httpPort : "disabled",
httpsPort > 0 ? httpsPort : "disabled",
LOG.info("Starting /metrics endpoint at HTTP port: {}, HTTPS port: {}, exportJvmInfo: {}",
httpPort >= 0 ? httpPort : "disabled",
httpsPort >= 0 ? httpsPort : "disabled",
exportJvmInfo);
if (exportJvmInfo) {
DefaultExports.initialize();
}
if (httpPort == -1) {
server = new Server();
} else {
server = new Server(new InetSocketAddress(host, httpPort));
server = new Server();
ServerConnector httpConnector = null;
ServerConnector httpsConnector = null;
if (httpPort >= 0) {
httpConnector = new ServerConnector(server);
httpConnector.setHost(host);
httpConnector.setPort(httpPort);
server.addConnector(httpConnector);
}
if (httpsPort != -1) {
if (httpsPort >= 0) {
SslContextFactory sslServerContextFactory = new SslContextFactory.Server();
configureSslContextFactory(sslServerContextFactory);
KeyStoreScanner keystoreScanner = new KeyStoreScanner(sslServerContextFactory);
keystoreScanner.setScanInterval(SCAN_INTERVAL);
server.addBean(keystoreScanner);
ServerConnector connector = new ServerConnector(server, sslServerContextFactory);
connector.setPort(httpsPort);
connector.setHost(host);
server.addConnector(connector);
httpsConnector = new ServerConnector(server, sslServerContextFactory);
httpsConnector.setHost(host);
httpsConnector.setPort(httpsPort);
server.addConnector(httpsConnector);
}
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
constrainTraceMethod(context);
server.setHandler(context);
context.addServlet(new ServletHolder(servlet), "/metrics");
server.start();
if (httpPort == 0) {
LOG.info("Bound /metrics endpoint to HTTP port: {}", httpConnector.getLocalPort());
}
if (httpsPort == 0) {
LOG.info("Bound /metrics endpoint to HTTPS port: {}", httpsConnector.getLocalPort());
}
} catch (Exception err) {
LOG.error("Cannot start /metrics server", err);
if (server != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testValidSslConfig() throws MetricsProviderLifeCycleException {
Properties configuration = new Properties();
String testDataPath = System.getProperty("test.data.dir", "src/test/resources/data");
configuration.setProperty("httpHost", "127.0.0.1");
configuration.setProperty("httpsPort", "50511");
configuration.setProperty("httpsPort", "0");
configuration.setProperty("ssl.keyStore.location", testDataPath + "/ssl/server_keystore.jks");
configuration.setProperty("ssl.keyStore.password", "testpass");
configuration.setProperty("ssl.trustStore.location", testDataPath + "/ssl/server_truststore.jks");
Expand All @@ -78,8 +78,8 @@ public void testValidHttpsAndHttpConfig() throws MetricsProviderLifeCycleExcepti
PrometheusMetricsProvider provider = new PrometheusMetricsProvider();
Properties configuration = new Properties();
String testDataPath = System.getProperty("test.data.dir", "src/test/resources/data");
configuration.setProperty("httpPort", "50512");
configuration.setProperty("httpsPort", "50513");
configuration.setProperty("httpPort", "0");
configuration.setProperty("httpsPort", "0");
configuration.setProperty("ssl.keyStore.location", testDataPath + "/ssl/server_keystore.jks");
configuration.setProperty("ssl.keyStore.password", "testpass");
configuration.setProperty("ssl.trustStore.location", testDataPath + "/ssl/server_truststore.jks");
Expand All @@ -95,7 +95,7 @@ public void testInvalidSslConfig() throws MetricsProviderLifeCycleException {
PrometheusMetricsProvider provider = new PrometheusMetricsProvider();
Properties configuration = new Properties();
String testDataPath = System.getProperty("test.data.dir", "src/test/resources/data");
configuration.setProperty("httpsPort", "50514");
configuration.setProperty("httpsPort", "0");
//keystore missing
configuration.setProperty("ssl.keyStore.password", "testpass");
configuration.setProperty("ssl.trustStore.location", testDataPath + "/ssl/server_truststore.jks");
Expand Down