Merge changes from topic "revert-425518-ZIDDSIUFTI"
* changes:
Revert "Add numberofprojects metric"
Revert "Decouple the number of repositories metrics from the cache"
Revert "Replace project cache with GerritApi for listing projects"
Revert "Use '(state:active OR state:read-only)' when querying projects"
diff --git a/BUILD b/BUILD
index 2c38d9e..7370013 100644
--- a/BUILD
+++ b/BUILD
@@ -15,7 +15,6 @@
manifest_entries = [
"Gerrit-PluginName: git-repo-metrics",
"Gerrit-Module: com.googlesource.gerrit.plugins.gitrepometrics.Module",
- "Gerrit-ReloadMode: restart",
"Implementation-Title: git-repo-metrics plugin",
"Implementation-URL: https://review.gerrithub.io/admin/repos/GerritForge/git-repo-metrics",
"Implementation-Vendor: GerritForge",
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/Module.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/Module.java
index fa024bd..c501bb6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/Module.java
@@ -19,12 +19,10 @@
import com.google.gerrit.server.events.EventListener;
import com.google.inject.Inject;
import com.google.inject.Scopes;
-import com.google.inject.name.Names;
import com.googlesource.gerrit.plugins.gitrepometrics.collectors.FSMetricsCollector;
import com.googlesource.gerrit.plugins.gitrepometrics.collectors.GitRefsMetricsCollector;
import com.googlesource.gerrit.plugins.gitrepometrics.collectors.GitStatsMetricsCollector;
import com.googlesource.gerrit.plugins.gitrepometrics.collectors.MetricsCollector;
-import com.googlesource.gerrit.plugins.gitrepometrics.collectors.NumberOfProjectsCollector;
import java.util.concurrent.ScheduledExecutorService;
public class Module extends LifecycleModule {
@@ -54,10 +52,5 @@
DynamicSet.bind(binder(), MetricsCollector.class).to(FSMetricsCollector.class);
DynamicSet.bind(binder(), MetricsCollector.class).to(GitRefsMetricsCollector.class);
install(new UpdateGitMetricsTaskModule());
-
- bind(Long.class)
- .annotatedWith(Names.named(NumberOfProjectsCollector.NUM_PROJECTS))
- .toProvider(NumberOfProjectsCollector.class);
- listener().to(RepoCountMetricRegister.class);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/RepoCountMetricRegister.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/RepoCountMetricRegister.java
deleted file mode 100644
index 8b54fef..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/RepoCountMetricRegister.java
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (C) 2024 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.googlesource.gerrit.plugins.gitrepometrics;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.extensions.events.LifecycleListener;
-import com.google.gerrit.metrics.Description;
-import com.google.gerrit.metrics.MetricMaker;
-import com.google.inject.Provider;
-import com.google.inject.Singleton;
-import com.google.inject.name.Named;
-import com.googlesource.gerrit.plugins.gitrepometrics.collectors.NumberOfProjectsCollector;
-import javax.inject.Inject;
-
-@Singleton
-public class RepoCountMetricRegister implements LifecycleListener {
- private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- protected static final String REPO_COUNT_METRIC_NAME = "numberofprojects";
- private final MetricMaker metricMaker;
- private final Provider<Long> numberOfProjectsProvider;
-
- @VisibleForTesting
- @Inject
- RepoCountMetricRegister(
- @Named(NumberOfProjectsCollector.NUM_PROJECTS) Provider<Long> numberOfProjectsProvider,
- MetricMaker metricMaker) {
- this.metricMaker = metricMaker;
- this.numberOfProjectsProvider = numberOfProjectsProvider;
- }
-
- @Override
- public void start() {
- logger.atInfo().log("Registering metric " + REPO_COUNT_METRIC_NAME);
-
- metricMaker.newCallbackMetric(
- REPO_COUNT_METRIC_NAME,
- Long.class,
- new Description("Number of existing projects.").setGauge().setUnit("Count"),
- numberOfProjectsProvider::get);
- }
-
- @Override
- public void stop() {}
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/NumberOfProjectsCollector.java b/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/NumberOfProjectsCollector.java
deleted file mode 100644
index 8a42900..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/gitrepometrics/collectors/NumberOfProjectsCollector.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (C) 2024 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.googlesource.gerrit.plugins.gitrepometrics.collectors;
-
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import com.google.common.flogger.FluentLogger;
-import com.google.gerrit.extensions.api.GerritApi;
-import com.google.gerrit.extensions.restapi.RestApiException;
-import com.google.gerrit.server.util.ManualRequestContext;
-import com.google.gerrit.server.util.OneOffRequestContext;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.Singleton;
-import com.googlesource.gerrit.plugins.gitrepometrics.GitRepoMetricsConfig;
-import java.util.concurrent.TimeUnit;
-
-@Singleton
-public class NumberOfProjectsCollector implements Provider<Long> {
- public static final String NUM_PROJECTS = "num-projects";
- public static final long MIN_NUM_PROJECTS_GRACE_PERIOD_MS = 1000L;
-
- private static final FluentLogger logger = FluentLogger.forEnclosingClass();
- private final Supplier<Long> numberOfProjects;
-
- @Inject
- NumberOfProjectsCollector(GerritApi api, OneOffRequestContext ctx, GitRepoMetricsConfig config) {
- numberOfProjects =
- Suppliers.memoizeWithExpiration(
- () -> queryNumberOfProjects(ctx, api),
- Math.max(MIN_NUM_PROJECTS_GRACE_PERIOD_MS, config.getGracePeriodMs()),
- TimeUnit.MILLISECONDS);
- }
-
- private static long queryNumberOfProjects(OneOffRequestContext ctx, GerritApi api) {
- try (ManualRequestContext c = ctx.open()) {
- return api.projects().query("(state:active OR state:read-only)").get().size();
- } catch (RestApiException e) {
- logger.atWarning().withCause(e).log("Unable to query Gerrit projects list");
- throw new IllegalStateException(e);
- }
- }
-
- @Override
- public Long get() {
- return numberOfProjects.get();
- }
-}
diff --git a/src/resources/Documentation/config.md b/src/resources/Documentation/config.md
index 57d2acf..2c0f39c 100644
--- a/src/resources/Documentation/config.md
+++ b/src/resources/Documentation/config.md
@@ -2,14 +2,9 @@
======================
The @PLUGIN@ allows a systematic collection of repository metrics.
+Metrics are updated upon a `ref-update` receive.
-The following exposed metric is available on request with the current status:
-
-```bash
-plugins_git_repo_metrics_numberOfProjects
-```
-
-The following exposed metrics are updated upon a `ref-update` receive:
+Currently, the metrics exposed are the following:
```bash
plugins_git_repo_metrics_numberofbitmaps_<repo_name>
diff --git a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/FakeMetricMaker.java b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/FakeMetricMaker.java
index 0eb1778..6faaf99 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/FakeMetricMaker.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/FakeMetricMaker.java
@@ -14,13 +14,8 @@
package com.googlesource.gerrit.plugins.gitrepometrics;
-import java.util.HashMap;
-import java.util.Optional;
-
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
-import com.google.common.base.Supplier;
-import com.google.gerrit.extensions.registration.RegistrationHandle;
import com.google.gerrit.metrics.CallbackMetric0;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.DisabledMetricMaker;
@@ -28,19 +23,16 @@
class FakeMetricMaker extends DisabledMetricMaker {
Integer callsCounter;
private MetricRegistry metricRegistry;
- HashMap<String, Supplier<?>> actionMap;
- @SuppressWarnings({"rawtypes", "unchecked"})
FakeMetricMaker(MetricRegistry metricRegistry) {
- this.callsCounter = 0;
+ callsCounter = 0;
this.metricRegistry = metricRegistry;
- this.actionMap = new HashMap();
}
- @SuppressWarnings("unused")
@Override
public <V> CallbackMetric0<V> newCallbackMetric(
String name, Class<V> valueClass, Description desc) {
+
callsCounter += 1;
metricRegistry.register(
String.format("%s/%s/%s", "plugins", "git-repo-metrics", name), new Meter());
@@ -53,25 +45,4 @@
public void remove() {}
};
}
-
- @Override
- public <V> RegistrationHandle newCallbackMetric(
- String name, Class<V> valueClass, Description desc, Supplier<V> trigger) {
- callsCounter += 1;
-
- String metricName = String.format("%s/%s/%s", "plugins", "git-repo-metrics", name);
-
- metricRegistry.register(metricName, new Meter());
-
- actionMap.put(metricName, trigger);
-
- return null;
- }
-
- @SuppressWarnings("rawtypes")
- public Optional<Supplier> getValueForMetric(String metric) {
- if (actionMap.containsKey(metric)) return Optional.of(actionMap.get(metric));
-
- return Optional.empty();
- }
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCacheIT.java b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCacheIT.java
index b72fb9c..4eee736 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCacheIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/GitRepoMetricsCacheIT.java
@@ -37,7 +37,7 @@
sysModule = "com.googlesource.gerrit.plugins.gitrepometrics.Module")
public class GitRepoMetricsCacheIT extends LightweightPluginDaemonTest {
- private final int MAX_WAIT_TIME_FOR_METRICS_SECS = 10;
+ private final int MAX_WAIT_TIME_FOR_METRICS_SECS = 5;
@Inject MetricRegistry metricRegistry;
private FSMetricsCollector fsMetricsCollector;
@@ -77,10 +77,8 @@
+ gitRefsMetricsCollector.availableMetrics().size();
try {
- // One additional is added for the numberofprojects metric
WaitUtil.waitUntil(
- () ->
- getPluginMetricsCount() == (long) (availableProjects.size() * expectedMetricsCount) + 1,
+ () -> getPluginMetricsCount() == (long) availableProjects.size() * expectedMetricsCount,
Duration.ofSeconds(MAX_WAIT_TIME_FOR_METRICS_SECS));
} catch (InterruptedException e) {
fail(
diff --git a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/RepoCountMetricTest.java b/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/RepoCountMetricTest.java
deleted file mode 100644
index 725e8b7..0000000
--- a/src/test/java/com/googlesource/gerrit/plugins/gitrepometrics/RepoCountMetricTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (C) 2024 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.googlesource.gerrit.plugins.gitrepometrics;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import com.codahale.metrics.MetricRegistry;
-import com.google.common.base.Supplier;
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicLong;
-import org.junit.Before;
-import org.junit.Test;
-
-public class RepoCountMetricTest {
- private FakeMetricMaker fakeMetricMaker;
- private MetricRegistry metricRegistry;
- private String repoCountMetricName;
-
- @Before
- public void setup() {
- metricRegistry = new MetricRegistry();
- fakeMetricMaker = new FakeMetricMaker(metricRegistry);
- repoCountMetricName =
- String.format(
- "%s/%s/%s",
- "plugins", "git-repo-metrics", RepoCountMetricRegister.REPO_COUNT_METRIC_NAME);
- }
-
- @Test
- public void metricIsCorrectlyRegistered() {
- RepoCountMetricRegister repoCountMetricRegister =
- new RepoCountMetricRegister(() -> 1L, fakeMetricMaker);
-
- repoCountMetricRegister.start();
-
- assertTrue(metricRegistry.getMetrics().containsKey(repoCountMetricName));
-
- metricRegistry.remove(repoCountMetricName);
- }
-
- @Test
- public void metricIsUpdated() {
- AtomicLong numProjects = new AtomicLong();
- RepoCountMetricRegister repoCountMetricRegister =
- new RepoCountMetricRegister(numProjects::get, fakeMetricMaker);
-
- repoCountMetricRegister.start();
-
- assertEquals(1, fakeMetricMaker.actionMap.size());
-
- @SuppressWarnings("rawtypes")
- Optional<Supplier> obj = fakeMetricMaker.getValueForMetric(repoCountMetricName);
-
- assertTrue(!obj.isEmpty());
- assertEquals(0, ((Long) obj.get().get()).longValue());
-
- numProjects.set(2);
- assertEquals(2, ((Long) obj.get().get()).longValue());
- }
-}