Skip to content

Commit

Permalink
Synchronise modifications of metricsServlet and pendingMetricsProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Mar 15, 2022
1 parent c21738d commit d32291e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ public CompletableFuture<Void> closeAsync() {
}
}

metricsServlet = null;
synchronized (this) {
metricsServlet = null;
}

if (this.webSocketService != null) {
this.webSocketService.close();
Expand Down Expand Up @@ -697,14 +699,17 @@ public void start() throws PulsarServerException {
this.brokerAdditionalServlets = AdditionalServlets.load(config);

this.webService = new WebService(this);
this.metricsServlet = new PulsarPrometheusMetricsServlet(
this, config.isExposeTopicLevelMetricsInPrometheus(),
config.isExposeConsumerLevelMetricsInPrometheus(),
config.isExposeProducerLevelMetricsInPrometheus(),
config.isSplitTopicAndPartitionLabelInPrometheus());
if (pendingMetricsProviders != null) {
pendingMetricsProviders.forEach(provider -> metricsServlet.addRawMetricsProvider(provider));
this.pendingMetricsProviders = null;

synchronized (this) {
this.metricsServlet = new PulsarPrometheusMetricsServlet(
this, config.isExposeTopicLevelMetricsInPrometheus(),
config.isExposeConsumerLevelMetricsInPrometheus(),
config.isExposeProducerLevelMetricsInPrometheus(),
config.isSplitTopicAndPartitionLabelInPrometheus());
if (pendingMetricsProviders != null) {
pendingMetricsProviders.forEach(provider -> metricsServlet.addRawMetricsProvider(provider));
this.pendingMetricsProviders = null;
}
}

this.addWebServerHandlers(webService, metricsServlet, this.config);
Expand Down Expand Up @@ -1516,13 +1521,15 @@ public ResourceUsageTransportManager getResourceUsageTransportManager() {
}

public void addPrometheusRawMetricsProvider(PrometheusRawMetricsProvider metricsProvider) {
if (metricsServlet == null) {
if (pendingMetricsProviders == null) {
pendingMetricsProviders = new LinkedList<>();
synchronized (this) {
if (metricsServlet == null) {
if (pendingMetricsProviders == null) {
pendingMetricsProviders = new LinkedList<>();
}
pendingMetricsProviders.add(metricsProvider);
} else {
this.metricsServlet.addRawMetricsProvider(metricsProvider);
}
pendingMetricsProviders.add(metricsProvider);
} else {
this.metricsServlet.addRawMetricsProvider(metricsProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,12 @@ public void start() throws Exception {
this.serviceUrlTls = null;
}

this.metricsServlet = new PrometheusMetricsServlet(-1L, proxyConfig.getClusterName());
if (pendingMetricsProviders != null) {
pendingMetricsProviders.forEach(provider -> metricsServlet.addRawMetricsProvider(provider));
this.pendingMetricsProviders = null;
synchronized (this) {
this.metricsServlet = new PrometheusMetricsServlet(-1L, proxyConfig.getClusterName());
if (pendingMetricsProviders != null) {
pendingMetricsProviders.forEach(provider -> metricsServlet.addRawMetricsProvider(provider));
this.pendingMetricsProviders = null;
}
}

// Initialize the message protocol handlers.
Expand Down Expand Up @@ -347,7 +349,9 @@ public void close() throws IOException {
proxyAdditionalServlets = null;
}

metricsServlet = null;
synchronized (this) {
metricsServlet = null;
}

if (localMetadataStore != null) {
try {
Expand Down Expand Up @@ -429,13 +433,15 @@ public Authentication getProxyClientAuthenticationPlugin() {
}

public void addPrometheusRawMetricsProvider(PrometheusRawMetricsProvider metricsProvider) {
if (metricsServlet == null) {
if (pendingMetricsProviders == null) {
pendingMetricsProviders = new LinkedList<>();
synchronized (this) {
if (metricsServlet == null) {
if (pendingMetricsProviders == null) {
pendingMetricsProviders = new LinkedList<>();
}
pendingMetricsProviders.add(metricsProvider);
} else {
this.metricsServlet.addRawMetricsProvider(metricsProvider);
}
pendingMetricsProviders.add(metricsProvider);
} else {
this.metricsServlet.addRawMetricsProvider(metricsProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ public static void addWebServerHandlers(WebServer server,
ProxyConfiguration config,
ProxyService service,
BrokerDiscoveryProvider discoveryProvider) throws Exception {
server.addServlet("/metrics", new ServletHolder(service.getMetricsServlet()),
Collections.emptyList(), config.isAuthenticateMetricsEndpoint());
if (service != null && service.getMetricsServlet() != null) {
server.addServlet("/metrics", new ServletHolder(service.getMetricsServlet()),
Collections.emptyList(), config.isAuthenticateMetricsEndpoint());
}
server.addRestResources("/", VipStatus.class.getPackage().getName(),
VipStatus.ATTRIBUTE_STATUS_FILE_PATH, config.getStatusFilePath());
server.addRestResources("/proxy-stats", ProxyStats.class.getPackage().getName(),
Expand Down

0 comments on commit d32291e

Please sign in to comment.