|
33 | 33 | import java.util.concurrent.ConcurrentMap; |
34 | 34 | import java.util.concurrent.ExecutorService; |
35 | 35 | import java.util.concurrent.LinkedBlockingQueue; |
36 | | -import java.util.concurrent.RejectedExecutionException; |
| 36 | +import java.util.concurrent.RejectedExecutionHandler; |
37 | 37 | import java.util.concurrent.ThreadFactory; |
38 | 38 | import java.util.concurrent.ThreadPoolExecutor; |
39 | 39 | import java.util.concurrent.TimeUnit; |
|
51 | 51 | import org.apache.zookeeper.metrics.MetricsProviderLifeCycleException; |
52 | 52 | import org.apache.zookeeper.metrics.Summary; |
53 | 53 | import org.apache.zookeeper.metrics.SummarySet; |
54 | | -import org.apache.zookeeper.server.RateLogger; |
55 | 54 | import org.eclipse.jetty.security.ConstraintMapping; |
56 | 55 | import org.eclipse.jetty.security.ConstraintSecurityHandler; |
57 | 56 | import org.eclipse.jetty.server.Server; |
@@ -102,7 +101,6 @@ public class PrometheusMetricsProvider implements MetricsProvider { |
102 | 101 | * </p> |
103 | 102 | */ |
104 | 103 | private final CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry; |
105 | | - private final RateLogger rateLogger = new RateLogger(LOG, 60 * 1000); |
106 | 104 | private String host = "0.0.0.0"; |
107 | 105 | private int httpPort = -1; |
108 | 106 | private int httpsPort = -1; |
@@ -677,7 +675,9 @@ private Optional<ExecutorService> createExecutor() { |
677 | 675 | numWorkerThreads, |
678 | 676 | 0L, |
679 | 677 | TimeUnit.MILLISECONDS, |
680 | | - queue, new PrometheusWorkerThreadFactory()); |
| 678 | + queue, |
| 679 | + new PrometheusWorkerThreadFactory(), |
| 680 | + new PrometheusRejectedExecutionHandler()); |
681 | 681 | LOG.info("Executor service was created with numWorkerThreads {} and maxQueueSize {}", |
682 | 682 | numWorkerThreads, |
683 | 683 | maxQueueSize); |
@@ -714,14 +714,21 @@ public Thread newThread(final Runnable runnable) { |
714 | 714 | } |
715 | 715 | } |
716 | 716 |
|
| 717 | + private static class PrometheusRejectedExecutionHandler implements RejectedExecutionHandler { |
| 718 | + private static boolean maxQueueSizeExceeded = false; |
| 719 | + |
| 720 | + @Override |
| 721 | + public void rejectedExecution(final Runnable r, final ThreadPoolExecutor e) { |
| 722 | + if (!maxQueueSizeExceeded) { |
| 723 | + maxQueueSizeExceeded = true; |
| 724 | + LOG.warn("Prometheus metrics queue size exceeded the max"); |
| 725 | + } |
| 726 | + } |
| 727 | + } |
| 728 | + |
717 | 729 | private void reportMetrics(final Runnable task) { |
718 | 730 | if (executorOptional.isPresent()) { |
719 | | - try { |
720 | | - executorOptional.get().submit(task); |
721 | | - } catch (final RejectedExecutionException e) { |
722 | | - rateLogger.rateLimitLog("Prometheus metrics reporting task queue size exceeded the max", |
723 | | - String.valueOf(maxQueueSize)); |
724 | | - } |
| 731 | + executorOptional.get().submit(task); |
725 | 732 | } else { |
726 | 733 | task.run(); |
727 | 734 | } |
|
0 commit comments