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

commit f0b3c5663cb326c41993f405a24211bd997e90da
Author: Christian Schneider <cschn...@adobe.com>
AuthorDate: Fri Apr 12 08:24:33 2024 +0200

    SLING-12292 - Add support for tags
---
 .../distribution/journal/metrics/DefaultTag.java   | 58 ++++++++++++++++++++++
 .../sling/distribution/journal/metrics/Tag.java    | 36 ++++++++++++++
 .../journal/metrics/TaggedMetrics.java             | 40 +++++++++++++++
 3 files changed, 134 insertions(+)

diff --git 
a/src/main/java/org/apache/sling/distribution/journal/metrics/DefaultTag.java 
b/src/main/java/org/apache/sling/distribution/journal/metrics/DefaultTag.java
new file mode 100644
index 0000000..7fdb242
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/distribution/journal/metrics/DefaultTag.java
@@ -0,0 +1,58 @@
+/*
+ * 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 java.util.Objects;
+
+public class DefaultTag implements Tag {
+    private final String key;
+    private final String value;
+    
+    public DefaultTag(String key, String value) {
+        super();
+        this.key = key;
+        this.value = value;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(key, value);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        DefaultTag other = (DefaultTag) obj;
+        return Objects.equals(key, other.key) && Objects.equals(value, 
other.value);
+    }
+    
+}
diff --git 
a/src/main/java/org/apache/sling/distribution/journal/metrics/Tag.java 
b/src/main/java/org/apache/sling/distribution/journal/metrics/Tag.java
new file mode 100644
index 0000000..b67a1d4
--- /dev/null
+++ b/src/main/java/org/apache/sling/distribution/journal/metrics/Tag.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+public interface Tag extends Comparable<Tag> {
+
+    String getKey();
+
+    String getValue();
+
+    static Tag of(String key, String value) {
+        return new DefaultTag(key, value);
+    }
+
+    @Override
+    default int compareTo(Tag o) {
+        return getKey().compareTo(o.getKey());
+    }
+
+}
diff --git 
a/src/main/java/org/apache/sling/distribution/journal/metrics/TaggedMetrics.java
 
b/src/main/java/org/apache/sling/distribution/journal/metrics/TaggedMetrics.java
new file mode 100644
index 0000000..0c52dd7
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/distribution/journal/metrics/TaggedMetrics.java
@@ -0,0 +1,40 @@
+/*
+ * 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 java.util.List;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class TaggedMetrics {
+    private static Logger log = LoggerFactory.getLogger(TaggedMetrics.class);
+    
+    private TaggedMetrics() {
+    }
+
+    public static String getMetricName(String metricName, List<Tag> tags) {
+        String metric = tags.stream()
+                .map(tag -> ";" + tag.getKey() + "=" + tag.getValue())
+                .collect(Collectors.joining("", metricName, ""));
+        log.debug("metric={}", metric);
+        return metric;
+    }
+}

Reply via email to