Skip to content
Open
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 @@ -155,26 +155,7 @@ public BaseHttpServer(MutableConfigurationSource conf, String name)
conf.getBoolean(HddsConfigKeys.HDDS_PROFILER_ENABLED, false);

if (prometheusSupport) {
prometheusMetricsSink = new PrometheusMetricsSink(name);
httpServer.getWebAppContext().getServletContext()
.setAttribute(PROMETHEUS_SINK, prometheusMetricsSink);
HddsPrometheusConfig prometheusConfig =
conf.getObject(HddsPrometheusConfig.class);
String token = prometheusConfig.getPrometheusEndpointToken();
if (StringUtils.isNotEmpty(token)) {
httpServer.getWebAppContext().getServletContext()
.setAttribute(PrometheusServlet.SECURITY_TOKEN, token);
// Adding as internal servlet since we want to have token based
// auth and hence SPNEGO should be disabled if security is enabled.
httpServer.addInternalServlet("prometheus", "/prom",
PrometheusServlet.class);
} else {
// If token is not configured, keeping as regular servlet and not
// internal servlet since we do not want to expose /prom endpoint
// without authentication in a secure cluster.
httpServer.addServlet("prometheus", "/prom",
PrometheusServlet.class);
}
prometheusMetricsSink = addPrometheusEndpoint(httpServer, conf, name);
}

if (profilerSupport) {
Expand Down Expand Up @@ -243,6 +224,27 @@ public static HttpServer2.Builder newHttpServer2BuilderForOzone(
return builder;
}

/**
* Add the Prometheus endpoint at {@code /prom} to an existing {@link HttpServer2} instance.
* Returns the registered sink for use in start/stop lifecycle calls.
*/
public static PrometheusMetricsSink addPrometheusEndpoint(
HttpServer2 httpServer, ConfigurationSource conf, String name) {
PrometheusMetricsSink sink = new PrometheusMetricsSink(name);
httpServer.getWebAppContext().getServletContext().setAttribute(PROMETHEUS_SINK, sink);
String token = conf.getObject(HddsPrometheusConfig.class).getPrometheusEndpointToken();
if (StringUtils.isNotEmpty(token)) {
httpServer.getWebAppContext().getServletContext()
.setAttribute(PrometheusServlet.SECURITY_TOKEN, token);
// Token-based auth: use internal servlet so SPNEGO is bypassed.
httpServer.addInternalServlet("prometheus", "/prom", PrometheusServlet.class);
} else {
// No token: regular servlet, protected by the server's auth filter in secure mode.
httpServer.addServlet("prometheus", "/prom", PrometheusServlet.class);
}
return sink;
}

/**
* Add a servlet to BaseHttpServer.
*
Expand Down
2 changes: 2 additions & 0 deletions hadoop-ozone/dist/src/main/compose/ozone/monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ services:
<<: *monitoring-config
recon:
<<: *monitoring-config
httpfs:
<<: *monitoring-config
9 changes: 9 additions & 0 deletions hadoop-ozone/dist/src/main/compose/ozone/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ scrape_configs:
- "recon:9888"
labels:
component: recon
- job_name: ozone-httpfs
metrics_path: /prom
params:
user.name: [hadoop]
static_configs:
- targets:
- "httpfs:14000"
labels:
component: httpfs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
import java.util.LinkedHashSet;
import java.util.Set;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.server.http.BaseHttpServer;
import org.apache.hadoop.hdds.server.http.HttpServer2;
import org.apache.hadoop.hdds.server.http.PrometheusMetricsSink;
import org.apache.hadoop.hdds.utils.LegacyHadoopConfigurationSource;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.security.AuthenticationFilterInitializer;
import org.apache.hadoop.security.authentication.server.ProxyUserAuthenticationFilterInitializer;
import org.apache.hadoop.security.authorize.AccessControlList;
Expand Down Expand Up @@ -72,6 +76,7 @@ public class HttpFSServerWebServer {

private final HttpServer2 httpServer;
private final String scheme;
private PrometheusMetricsSink prometheusMetricsSink;

HttpFSServerWebServer(OzoneConfiguration conf, Configuration sslConf) throws
Exception {
Expand Down Expand Up @@ -129,6 +134,10 @@ public class HttpFSServerWebServer {
.setACL(new AccessControlList(conf.get(HTTP_ADMINS_KEY, " ")))
.addEndpoint(endpoint)
.build();

if (conf.getBoolean(HddsConfigKeys.HDDS_PROMETHEUS_ENABLED, true)) {
prometheusMetricsSink = BaseHttpServer.addPrometheusEndpoint(httpServer, conf, NAME);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that with hdds.prometheus.endpoint.token set, httpfs rejects the bearer-token request that s3g accepts. Same token:

curl -H 'Authorization: Bearer testtoken' http://httpfs:14000/prom  -> 401
curl -H 'Authorization: Bearer testtoken' http://s3g:19878/prom     -> 200

Is this difference intentional, or should HttpFS be updated for consistency?

}
}

/**
Expand All @@ -153,6 +162,10 @@ private static void deprecateEnv(String varName, Configuration conf,

public void start() throws IOException {
httpServer.start();
if (prometheusMetricsSink != null) {
DefaultMetricsSystem.instance()
.register("prometheus", "Hadoop metrics prometheus exporter", prometheusMetricsSink);
}
}

public void join() throws InterruptedException {
Expand Down