This is an automated email from the ASF dual-hosted git repository.

cschneider pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git


The following commit(s) were added to refs/heads/master by this push:
     new 7cd97dc  SLING-12292 - Add pub_name for subscriber
7cd97dc is described below

commit 7cd97dc8a0de1458fe25b5bad50bfacd7100f987
Author: Christian Schneider <[email protected]>
AuthorDate: Wed Apr 24 14:46:29 2024 +0200

    SLING-12292 - Add pub_name for subscriber
---
 .../journal/bookkeeper/SubscriberMetrics.java      | 11 +++++-
 .../impl/subscriber/DistributionSubscriber.java    |  7 +++-
 .../journal/bookkeeper/BookKeeperTest.java         |  2 +-
 .../journal/metrics/TaggedMetricsTest.java         | 43 ++++++++++++++++++++++
 .../journal/shared/SubscriberMetricsTest.java      |  2 +-
 5 files changed, 59 insertions(+), 6 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/SubscriberMetrics.java
 
b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/SubscriberMetrics.java
index 5846cfc..9566107 100644
--- 
a/src/main/java/org/apache/sling/distribution/journal/bookkeeper/SubscriberMetrics.java
+++ 
b/src/main/java/org/apache/sling/distribution/journal/bookkeeper/SubscriberMetrics.java
@@ -41,7 +41,10 @@ public class SubscriberMetrics {
     // Name of the subscriber agent
     private static final String TAG_SUB_NAME = "sub_name";
     
-    // Status of a package : 
+    // Name of the subscribed publish agent (first only if more than one)
+    private static final String TAG_PUB_NAME = "pub_name";
+    
+    // Status of a package see 
org.apache.sling.distribution.journal.messages.PackageStatusMessage.Status
     private static final String TAG_STATUS = "status";
     
     // Is the queue editable (true, false)
@@ -85,17 +88,21 @@ public class SubscriberMetrics {
     private static final String IMPORT_POST_PROCESS_DURATION = SUB_COMPONENT + 
"import_post_process_duration";
     private static final String INVALIDATION_PROCESS_DURATION = SUB_COMPONENT 
+ "invalidation_process_duration";
 
+
     private final MetricsService metricsService;
     private final Tag tagSubName;
+    private final Tag tagPubName;
     private final Tag tagEditable;
     private final List<Tag> tags;
 
-    public SubscriberMetrics(MetricsService metricsService, String 
subAgentName, boolean editable) {
+    public SubscriberMetrics(MetricsService metricsService, String 
subAgentName, String pubAgentName, boolean editable) {
         this.metricsService = metricsService;
         tagSubName = Tag.of(TAG_SUB_NAME, subAgentName);
         tagEditable = Tag.of(TAG_EDITABLE, Boolean.toString(editable));
+        tagPubName = Tag.of(TAG_PUB_NAME, pubAgentName);
         tags = Arrays.asList(
                 tagSubName, 
+                tagPubName,
                 tagEditable);
     }
 
diff --git 
a/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/DistributionSubscriber.java
 
b/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/DistributionSubscriber.java
index ff33c6f..ffe639b 100644
--- 
a/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/DistributionSubscriber.java
+++ 
b/src/main/java/org/apache/sling/distribution/journal/impl/subscriber/DistributionSubscriber.java
@@ -172,8 +172,7 @@ public class DistributionSubscriber {
         requireNonNull(topics);
         requireNonNull(precondition);
         requireNonNull(bookKeeperFactory);
-        
-        this.subscriberMetrics = new SubscriberMetrics(metricsService, 
subAgentName, config.editable());
+        this.subscriberMetrics = new SubscriberMetrics(metricsService, 
subAgentName, getFirst(config.agentNames()), config.editable());
 
         if (config.editable()) {
             commandPoller = new CommandPoller(messagingProvider, topics, 
subSlingId, subAgentName, delay::signal);
@@ -222,6 +221,10 @@ public class DistributionSubscriber {
         LOG.info("Started Subscriber agent={} at offset={}, subscribed to 
agent names {}, readyCheck={}", subAgentName, startOffset,
                 queueNames, config.subscriberIdleCheck());
     }
+    
+    private String getFirst(String[] agentNames) {
+        return agentNames != null && agentNames.length > 0 ? agentNames[0] : 
"";
+    }
 
     public static String escapeTopicName(URI messagingUri, String topicName) {
         return String.format("%s%s_%s",
diff --git 
a/src/test/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeperTest.java
 
b/src/test/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeperTest.java
index 2663457..3da5b17 100644
--- 
a/src/test/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeperTest.java
+++ 
b/src/test/java/org/apache/sling/distribution/journal/bookkeeper/BookKeeperTest.java
@@ -89,7 +89,7 @@ public class BookKeeperTest {
     @Before
     public void before() {
         BookKeeperConfig bkConfig = new BookKeeperConfig("subAgentName", 
"subSlingId", true, 10, PackageHandling.Extract, "package", true);
-        subscriberMetrics = new SubscriberMetrics(MetricsService.NOOP, 
bkConfig.getSubAgentName(), bkConfig.isEditable());
+        subscriberMetrics = new SubscriberMetrics(MetricsService.NOOP, 
bkConfig.getSubAgentName(), "publish", bkConfig.isEditable());
         bookKeeper = new BookKeeper(resolverFactory, subscriberMetrics, 
packageHandler, eventAdmin, sender, logSender, bkConfig,
                 importPreProcessor, importPostProcessor, 
invalidationProcessor);
     }
diff --git 
a/src/test/java/org/apache/sling/distribution/journal/metrics/TaggedMetricsTest.java
 
b/src/test/java/org/apache/sling/distribution/journal/metrics/TaggedMetricsTest.java
new file mode 100644
index 0000000..16d62a1
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/distribution/journal/metrics/TaggedMetricsTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.sling.distribution.journal.metrics;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import org.junit.Test;
+
+public class TaggedMetricsTest {
+    @Test
+    public void testNoTags() {
+        String metricName = TaggedMetrics.getMetricName("metric", 
Collections.emptyList());
+        assertThat(metricName, equalTo("metric"));
+    }
+
+    @Test
+    public void testTags() {
+        Tag tag1 = Tag.of("key1", "value1");
+        Tag tag2 = Tag.of("key2", "value2");
+        String metricName = TaggedMetrics.getMetricName("metric", 
Arrays.asList(tag1, tag2));
+        assertThat(metricName, equalTo("metric;key1=value1;key2=value2"));
+    }
+}
diff --git 
a/src/test/java/org/apache/sling/distribution/journal/shared/SubscriberMetricsTest.java
 
b/src/test/java/org/apache/sling/distribution/journal/shared/SubscriberMetricsTest.java
index a3f0878..9b6c007 100644
--- 
a/src/test/java/org/apache/sling/distribution/journal/shared/SubscriberMetricsTest.java
+++ 
b/src/test/java/org/apache/sling/distribution/journal/shared/SubscriberMetricsTest.java
@@ -42,7 +42,7 @@ public class SubscriberMetricsTest {
     @Before
     public void before() {
         MetricsService metricsService = MetricsService.NOOP;
-        metrics = new SubscriberMetrics(metricsService, "subAgentName", true);
+        metrics = new SubscriberMetrics(metricsService, "publishSubscriber", 
"publish", true);
     }
 
     public static void mockBehaviour(MetricsService metricsService) {

Reply via email to