From b801a367757397cfb9d5da3706d266d66aea3e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Ar=C3=A8s?= Date: Wed, 16 May 2018 18:39:55 +0000 Subject: [PATCH] Revert "WorkQueue: Add metrics" Some plugins are creating a work queue on load which will create the metrics for that queue. If plugin is reloaded, the work queue is created again and it will try to create metrics again which will fail because metrics already exists thus causing the plugin to not load. This reverts commit fe270ddd54c0f4c2d20edc74fa1e890080bd0630. This reverts commit 4e97e35b7c3423ff4a85a02d4b03722f903d6348. This reverts commit fccd70ed65fd1003060b505070f5a48b93356b92. This reverts commit eb2f45c84ebb650cf653e40c3926e9fe953646f0. Change-Id: I0cef3831470d919c8efea4c019943af69a85281e --- Documentation/metrics.txt | 11 -- .../google/gerrit/server/git/WorkQueue.java | 102 +----------------- 2 files changed, 3 insertions(+), 110 deletions(-) diff --git a/Documentation/metrics.txt b/Documentation/metrics.txt index 9f315b8fdd..091dbb3a5f 100644 --- a/Documentation/metrics.txt +++ b/Documentation/metrics.txt @@ -53,17 +53,6 @@ objects needing finalization. * `query/query_latency`: Successful query latency, accumulated over the life of the process. -=== Queue - -The metrics below are per queue. - -* `queue//pool_size`: Current number of threads in the pool -* `queue//max_pool_size`: Maximum allowed number of threads in the pool -* `queue//active_threads`: Number of threads that are actively executing tasks -* `queue//scheduled_tasks`: Number of scheduled tasks in the queue -* `queue//total_scheduled_tasks_count`: Total number of tasks that have been scheduled -* `queue//total_completed_tasks_count`: Total number of tasks that have completed execution - === SSH sessions * `sshd/sessions/connected`: Number of currently connected SSH sessions. diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java index 3b8e4c441d..40ebc6661e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/WorkQueue.java @@ -14,14 +14,8 @@ package com.google.gerrit.server.git; -import static com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker.sanitizeMetricName; - -import com.google.common.base.CaseFormat; -import com.google.common.base.Supplier; import com.google.gerrit.extensions.events.LifecycleListener; import com.google.gerrit.lifecycle.LifecycleModule; -import com.google.gerrit.metrics.Description; -import com.google.gerrit.metrics.MetricMaker; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.server.config.GerritServerConfig; import com.google.gerrit.server.util.IdGenerator; @@ -88,19 +82,17 @@ public class WorkQueue { } }; - private final MetricMaker metrics; private final Executor defaultQueue; private final IdGenerator idGenerator; private final CopyOnWriteArrayList queues; @Inject - WorkQueue(MetricMaker metrics, IdGenerator idGenerator, @GerritServerConfig Config cfg) { - this(metrics, idGenerator, cfg.getInt("execution", "defaultThreadPoolSize", 1)); + WorkQueue(IdGenerator idGenerator, @GerritServerConfig Config cfg) { + this(idGenerator, cfg.getInt("execution", "defaultThreadPoolSize", 1)); } /** Constructor to allow binding the WorkQueue more explicitly in a vhost setup. */ - public WorkQueue(MetricMaker metrics, IdGenerator idGenerator, int defaultThreadPoolSize) { - this.metrics = metrics; + public WorkQueue(IdGenerator idGenerator, int defaultThreadPoolSize) { this.idGenerator = idGenerator; this.queues = new CopyOnWriteArrayList<>(); this.defaultQueue = createQueue(defaultThreadPoolSize, "WorkQueue"); @@ -207,94 +199,6 @@ public class WorkQueue { corePoolSize + 4 // concurrency level ); queueName = prefix; - try { - buildMetrics(queueName); - } catch (IllegalArgumentException e) { - if (e.getMessage().contains("already")) { - log.warn("Not creating metrics for queue '{}': already exists", queueName); - } else { - throw e; - } - } - } - - private void buildMetrics(String queueName) { - metrics.newCallbackMetric( - getMetricName(queueName, "max_pool_size"), - Long.class, - new Description("Maximum allowed number of threads in the pool") - .setGauge() - .setUnit("threads"), - new Supplier() { - @Override - public Long get() { - return (long) getMaximumPoolSize(); - } - }); - metrics.newCallbackMetric( - getMetricName(queueName, "pool_size"), - Long.class, - new Description("Current number of threads in the pool").setGauge().setUnit("threads"), - new Supplier() { - @Override - public Long get() { - return (long) getPoolSize(); - } - }); - metrics.newCallbackMetric( - getMetricName(queueName, "active_threads"), - Long.class, - new Description("Number number of threads that are actively executing tasks") - .setGauge() - .setUnit("threads"), - new Supplier() { - @Override - public Long get() { - return (long) getActiveCount(); - } - }); - metrics.newCallbackMetric( - getMetricName(queueName, "scheduled_tasks"), - Integer.class, - new Description("Number of scheduled tasks in the queue").setGauge().setUnit("tasks"), - new Supplier() { - @Override - public Integer get() { - return getQueue().size(); - } - }); - metrics.newCallbackMetric( - getMetricName(queueName, "total_scheduled_tasks_count"), - Long.class, - new Description("Total number of tasks that have been scheduled for execution") - .setCumulative() - .setUnit("tasks"), - new Supplier() { - @Override - public Long get() { - return (long) getTaskCount(); - } - }); - metrics.newCallbackMetric( - getMetricName(queueName, "total_completed_tasks_count"), - Long.class, - new Description("Total number of tasks that have completed execution") - .setCumulative() - .setUnit("tasks"), - new Supplier() { - @Override - public Long get() { - return (long) getCompletedTaskCount(); - } - }); - } - - private String getMetricName(String queueName, String metricName) { - String name = - CaseFormat.UPPER_CAMEL.to( - CaseFormat.LOWER_UNDERSCORE, - queueName.replaceFirst("SSH", "Ssh").replaceAll("-", "")); - return sanitizeMetricName(String.format("queue/%s/%s", name, metricName)); } public void unregisterWorkQueue() {