Merge branch 'stable-3.1'
* stable-3.1:
Route cache evictions routing to CacheEvictionEventRouter
Download correct websession plugin artifact
Revert "Expose replication status metrics"
Change-Id: I07aee8120fb7a386d47914e279b5d7f7917f15c4
diff --git a/setup_local_env/setup.sh b/setup_local_env/setup.sh
index 2809209..5d4ca83 100755
--- a/setup_local_env/setup.sh
+++ b/setup_local_env/setup.sh
@@ -320,11 +320,11 @@
cp -f $MULTISITE_LIB_LOCATION $DEPLOYMENT_LOCATION/multi-site.jar >/dev/null 2>&1 || { echo >&2 "$MULTISITE_LIB_LOCATION: Not able to copy the file. Aborting"; exit 1; }
fi
if [ $DOWNLOAD_WEBSESSION_PLUGIN = "true" ];then
- echo "Downloading websession-broker plugin master"
- wget https://gerrit-ci.gerritforge.com/view/Plugins-master/job/plugin-websession-broker-gh-bazel-master/lastSuccessfulBuild/artifact/bazel-bin/plugins/websession-broker/websession-broker.jar \
+ echo "Downloading websession-broker plugin"
+ wget https://gerrit-ci.gerritforge.com/view/Plugins-master/job/plugin-websession-broker-bazel-master/lastSuccessfulBuild/artifact/bazel-bin/plugins/websession-broker/websession-broker.jar \
-O $DEPLOYMENT_LOCATION/websession-broker.jar || { echo >&2 "Cannot download websession-broker plugin: Check internet connection. Abort\
ing"; exit 1; }
- wget https://gerrit-ci.gerritforge.com/view/Plugins-master/job/plugin-healthcheck-bazel-master-master/lastSuccessfulBuild/artifact/bazel-bin/plugins/healthcheck/healthcheck.jar \
+ wget https://gerrit-ci.gerritforge.com/view/Plugins-master/job/plugin-healthcheck-bazel-master/lastSuccessfulBuild/artifact/bazel-bin/plugins/healthcheck/healthcheck.jar \
-O $DEPLOYMENT_LOCATION/healthcheck.jar || { echo >&2 "Cannot download healthcheck plugin: Check internet connection. Abort\
ing"; exit 1; }
else
@@ -336,7 +336,7 @@
-O $DEPLOYMENT_LOCATION/zookeeper.jar || { echo >&2 "Cannot download zookeeper plugin: Check internet connection. Abort\
ing"; exit 1; }
-echo "Downloading events-broker library stable 3.1"
+echo "Downloading events-broker library"
wget https://repo1.maven.org/maven2/com/gerritforge/events-broker/3.1.4/events-broker-3.1.4.jar \
-O $DEPLOYMENT_LOCATION/events-broker.jar || { echo >&2 "Cannot download events-broker library: Check internet connection. Abort\
ing"; exit 1; }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/ProjectReplicationStatus.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/ProjectReplicationStatus.java
deleted file mode 100644
index e8b92d2..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/ProjectReplicationStatus.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2020 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.multisite;
-
-/**
- * This class contains the replication status of a Gerrit project
- *
- * <p>NOTE: Currently, the status is only represented by the last replication timestamp, but it
- * could be extended (i.e.: the last replicated commit can be an interesting information to add)
- */
-public class ProjectReplicationStatus {
-
- private Long lastReplicationTimestamp;
-
- public ProjectReplicationStatus(Long lastReplicationTimestamp) {
- this.lastReplicationTimestamp = lastReplicationTimestamp;
- }
-
- public Long getLastReplicationTimestamp() {
- return this.lastReplicationTimestamp;
- }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/ReplicationStatusStore.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/ReplicationStatusStore.java
deleted file mode 100644
index 5f5d393..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/ReplicationStatusStore.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (C) 2020 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.multisite;
-
-import com.google.inject.Singleton;
-import java.util.*;
-
-/**
- * This class stores the replication status of a Gerrit instance
- *
- * <p>The status is represented per project but also globally. The global replication status is, for
- * example, the max replication timestamp of all the projects. The replication Status of a project
- * is represented by {@see com.googlesource.gerrit.plugins.multisite.ProjectReplicationStatus}
- */
-@Singleton
-public class ReplicationStatusStore {
-
- private Map<String, ProjectReplicationStatus> statusPerProject;
- private Long globalLastReplicationTime = 0L;
-
- public ReplicationStatusStore() {
- this.statusPerProject = new HashMap<String, ProjectReplicationStatus>();
- }
-
- public void updateLastReplicationTime(String projectName, Long timestamp) {
- ProjectReplicationStatus projectReplicationStatus = new ProjectReplicationStatus(timestamp);
- this.statusPerProject.put(projectName, projectReplicationStatus);
- this.globalLastReplicationTime = timestamp;
- }
-
- public Optional<Long> getLastReplicationTime(String projectName) {
- Optional<ProjectReplicationStatus> maybeProjectReplicationStatus =
- Optional.ofNullable(this.statusPerProject.get(projectName));
- return maybeProjectReplicationStatus.map(ProjectReplicationStatus::getLastReplicationTimestamp);
- }
-
- public Long getGlobalLastReplicationTime() {
- return this.globalLastReplicationTime;
- }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/AbstractSubcriber.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/AbstractSubcriber.java
index 816edc9..ec6072c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/AbstractSubcriber.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/AbstractSubcriber.java
@@ -74,7 +74,6 @@
msgLog.log(Direction.CONSUME, topic, event);
eventRouter.route(event.getEvent());
subscriberMetrics.incrementSubscriberConsumedMessage();
- subscriberMetrics.updateReplicationStatusMetrics(event);
} catch (IOException e) {
logger.atSevere().withCause(e).log(
"Malformed event '%s': [Exception: %s]", event.getHeader());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/CacheEvictionEventSubscriber.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/CacheEvictionEventSubscriber.java
index 6c67c46..eae66b4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/CacheEvictionEventSubscriber.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/CacheEvictionEventSubscriber.java
@@ -21,14 +21,14 @@
import com.googlesource.gerrit.plugins.multisite.InstanceId;
import com.googlesource.gerrit.plugins.multisite.MessageLogger;
import com.googlesource.gerrit.plugins.multisite.forwarder.events.EventTopic;
-import com.googlesource.gerrit.plugins.multisite.forwarder.router.StreamEventRouter;
+import com.googlesource.gerrit.plugins.multisite.forwarder.router.CacheEvictionEventRouter;
import java.util.UUID;
@Singleton
public class CacheEvictionEventSubscriber extends AbstractSubcriber {
@Inject
public CacheEvictionEventSubscriber(
- StreamEventRouter eventRouter,
+ CacheEvictionEventRouter eventRouter,
DynamicSet<DroppedEventListener> droppedEventListeners,
@InstanceId UUID instanceId,
MessageLogger msgLog,
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetrics.java
index 96221e1..36f618e 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetrics.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/consumer/SubscriberMetrics.java
@@ -14,47 +14,24 @@
package com.googlesource.gerrit.plugins.multisite.consumer;
-import com.codahale.metrics.MetricFilter;
-import com.codahale.metrics.MetricRegistry;
-import com.gerritforge.gerrit.eventbroker.EventMessage;
-import com.google.common.flogger.FluentLogger;
import com.google.gerrit.metrics.Counter1;
import com.google.gerrit.metrics.Description;
import com.google.gerrit.metrics.MetricMaker;
-import com.google.gerrit.server.events.Event;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.googlesource.gerrit.plugins.multisite.MultiSiteMetrics;
-import com.googlesource.gerrit.plugins.multisite.ReplicationStatusStore;
-import com.googlesource.gerrit.plugins.replication.RefReplicatedEvent;
@Singleton
public class SubscriberMetrics extends MultiSiteMetrics {
- private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String SUBSCRIBER_SUCCESS_COUNTER = "subscriber_msg_consumer_counter";
private static final String SUBSCRIBER_FAILURE_COUNTER =
"subscriber_msg_consumer_failure_counter";
- private static final String INSTANCE_LATEST_REPLICATION_TIME_METRIC =
- "multi_site/subscriber/subscriber_replication_status/instance_latest_replication_epochtime_secs";
- private static final String PROJECT_LATEST_REPLICATION_TIME_METRIC_PREFIX =
- "multi_site/subscriber/subscriber_replication_status/latest_replication_epochtime_secs_";
-
- private ReplicationStatusStore replicationStatusStore;
- private MetricMaker metricMaker;
- private MetricRegistry metricRegistry;
private final Counter1<String> subscriberSuccessCounter;
private final Counter1<String> subscriberFailureCounter;
@Inject
- public SubscriberMetrics(
- MetricMaker metricMaker,
- MetricRegistry metricRegistry,
- ReplicationStatusStore replicationStatusStore) {
-
- this.replicationStatusStore = replicationStatusStore;
- this.metricMaker = metricMaker;
- this.metricRegistry = metricRegistry;
+ public SubscriberMetrics(MetricMaker metricMaker) {
this.subscriberSuccessCounter =
metricMaker.newCounter(
@@ -70,16 +47,6 @@
.setRate()
.setUnit("errors"),
stringField(SUBSCRIBER_FAILURE_COUNTER, "Subscriber failed to consume messages count"));
-
- metricMaker.newCallbackMetric(
- INSTANCE_LATEST_REPLICATION_TIME_METRIC,
- Long.class,
- new Description(
- String.format(
- "%s last replication timestamp (ms)", INSTANCE_LATEST_REPLICATION_TIME_METRIC))
- .setGauge()
- .setUnit(Description.Units.MILLISECONDS),
- () -> replicationStatusStore.getGlobalLastReplicationTime());
}
public void incrementSubscriberConsumedMessage() {
@@ -89,33 +56,4 @@
public void incrementSubscriberFailedToConsumeMessage() {
subscriberFailureCounter.increment(SUBSCRIBER_FAILURE_COUNTER);
}
-
- public void updateReplicationStatusMetrics(EventMessage eventMessage) {
- Event event = eventMessage.getEvent();
- if (event instanceof RefReplicatedEvent) {
- RefReplicatedEvent refReplicatedEvent = (RefReplicatedEvent) event;
- String projectName = refReplicatedEvent.getProjectNameKey().get();
- logger.atInfo().log("Updating last replication time for %s", projectName);
- replicationStatusStore.updateLastReplicationTime(projectName, event.eventCreatedOn);
- upsertMetricsForProject(projectName);
- } else {
- logger.atInfo().log("Not a ref-replicated-event event [%s], skipping", event.type);
- }
- }
-
- private void upsertMetricsForProject(String projectName) {
- String metricName = PROJECT_LATEST_REPLICATION_TIME_METRIC_PREFIX + projectName;
- if (metricRegistry.getGauges(MetricFilter.contains(metricName)).isEmpty()) {
- metricMaker.newCallbackMetric(
- metricName,
- Long.class,
- new Description(String.format("%s last replication timestamp (ms)", metricName))
- .setGauge()
- .setUnit(Description.Units.MILLISECONDS),
- () -> replicationStatusStore.getLastReplicationTime(projectName).orElse(0L));
- logger.atInfo().log("Added last replication timestamp callback metric for " + projectName);
- } else {
- logger.atInfo().log("Don't add metric since it already exists for project " + projectName);
- }
- }
}
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index e82133c..42249b1 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -99,4 +99,4 @@
* Subscriber replication status (latest replication Epoch time in seconds) per project
-`metric=plugins/multi-site/multi_site/subscriber/subscriber_replication_status/latest_replication_epochtime_secs_<projectName>, type=com.google.gerrit.metrics.dropwizard.CallbackMetricImpl`
\ No newline at end of file
+`metric=plugins/multi-site/multi_site/subscriber/subscriber_replication_status/latest_replication_epochtime_secs_<projectName>, type=com.google.gerrit.metrics.dropwizard.CallbackMetricImpl`
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/ReplicationStatusStoreTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/ReplicationStatusStoreTest.java
deleted file mode 100644
index 314e4b4..0000000
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/ReplicationStatusStoreTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (C) 2020 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.multisite;
-
-import static com.google.common.truth.Truth.assertThat;
-import static java.util.Optional.empty;
-import static java.util.Optional.of;
-
-import java.time.Instant;
-import org.junit.Test;
-
-public class ReplicationStatusStoreTest {
-
- @Test
- public void shouldUpdateGlobalStatus() {
- Instant instant = Instant.now();
- Long nowish = instant.toEpochMilli();
- ReplicationStatusStore replicationStatusStore = new ReplicationStatusStore();
-
- replicationStatusStore.updateLastReplicationTime("myProject", nowish);
-
- assertThat(replicationStatusStore.getGlobalLastReplicationTime()).isEqualTo(nowish);
- }
-
- @Test
- public void shouldUpdateProjectStatus() {
- String projectName = "myProject";
- Instant instant = Instant.now();
- Long nowish = instant.toEpochMilli();
- ReplicationStatusStore replicationStatusStore = new ReplicationStatusStore();
-
- replicationStatusStore.updateLastReplicationTime(projectName, nowish);
-
- assertThat(replicationStatusStore.getLastReplicationTime(projectName)).isEqualTo(of(nowish));
- }
-
- @Test
- public void shouldNotReturnProjectStatus() {
- ReplicationStatusStore replicationStatusStore = new ReplicationStatusStore();
-
- assertThat(replicationStatusStore.getLastReplicationTime("nonExistentProject"))
- .isEqualTo(empty());
- }
-}