Skip to content

Commit

Permalink
Merge pull request #25594 from geoand/#25237
Browse files Browse the repository at this point in the history
Activate request context when prometheus scraping is invoked
  • Loading branch information
geoand authored May 16, 2022
2 parents df5b690 + 0029c06 commit 0d7f364
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.exporter.common.TextFormat;
import io.quarkus.arc.Arc;
import io.quarkus.arc.ManagedContext;
import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerResponse;
Expand All @@ -31,11 +33,25 @@ public void handle(RoutingContext routingContext) {
response.setStatusCode(500)
.setStatusMessage("Unable to resolve Prometheus registry instance");
} else {
response.putHeader("Content-Type", TextFormat.CONTENT_TYPE_004)
.end(Buffer.buffer(registry.scrape()));
ManagedContext requestContext = Arc.container().requestContext();
if (requestContext.isActive()) {
doHandle(response);
} else {
requestContext.activate();
try {
doHandle(response);
} finally {
requestContext.terminate();
}
}
}
}

private void doHandle(HttpServerResponse response) {
response.putHeader("Content-Type", TextFormat.CONTENT_TYPE_004)
.end(Buffer.buffer(registry.scrape()));
}

private void setup() {
Instance<PrometheusMeterRegistry> registries = CDI.current().select(PrometheusMeterRegistry.class,
Default.Literal.INSTANCE);
Expand Down

0 comments on commit 0d7f364

Please sign in to comment.