tsreaper commented on code in PR #1620:
URL: https://github.com/apache/incubator-paimon/pull/1620#discussion_r1271812517


##########
paimon-core/src/main/java/org/apache/paimon/metrics/AbstractMetricGroup.java:
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.paimon.metrics;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Contains key functionality for adding metrics and carries metrics.
+ *
+ * <p>A MetricGroup can be {@link #close() closed}. Upon closing, the group 
de-register all metrics.
+ *
+ * <p>The {@link #close()} method and {@link #addMetric(String, Metric)} 
method should never be
+ * invoked by multiple threads at the same time, {@link #addMetric(String, 
Metric)} and {@link
+ * #getMetrics()} have multi-threads problems, like the reporter is reading 
the metrics map and the
+ * group is adding metrics to the map at the same time.
+ */
+public abstract class AbstractMetricGroup implements MetricGroup {
+    protected static final Logger LOG = 
LoggerFactory.getLogger(MetricGroup.class);
+
+    // ------------------------------------------------------------------------
+
+    /** The map containing all tags and their associated values, lazily 
computed. */
+    protected Map<String, String> tags;
+
+    /** Flag indicating whether this group has been closed. */
+    private boolean closed = false;
+
+    private final ConcurrentHashMap<String, Metric> metrics = new 
ConcurrentHashMap<>();
+
+    // ------------------------------------------------------------------------
+
+    public AbstractMetricGroup(@Nullable Map<String, String> tags) {

Review Comment:
   Why is it `@Nullable`? What's the difference between a `null` tag map and an 
empty tag map?



##########
paimon-core/src/test/java/org/apache/paimon/metrics/MetricGroupTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.paimon.metrics;
+
+import org.apache.paimon.metrics.groups.GenericMetricGroup;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** Tests for the {@link MetricGroup}. */
+public class MetricGroupTest {
+    @Test
+    public void groupRegisterMetrics() {
+        GenericMetricGroup group = 
GenericMetricGroup.createGenericMetricGroup("myTable", "commit");
+        assertFalse(group.isClosed());
+        // these will fail is the registration is propagated
+        group.counter("testcounter");
+        group.gauge(
+                "testgauge",
+                new Gauge<Object>() {
+                    @Override
+                    public Object getValue() {
+                        return null;
+                    }
+                });
+        assertThat(group.getGroupName()).isEqualTo("commit");
+        assertThat(group.getAllTags().size()).isEqualTo(1);
+        assertThat(group.getAllTags())
+                .containsExactlyEntriesOf(
+                        new HashMap<String, String>() {
+                            {
+                                put("table", "myTable");
+                            }
+                        });
+        assertThat(group.getMetrics().size()).isEqualTo(2);
+        group.close();
+        assertTrue(group.isClosed());
+    }
+
+    @Test
+    public void tolerateMetricNameCollisions() {

Review Comment:
   Same as above.



##########
paimon-core/src/test/java/org/apache/paimon/metrics/MetricGroupTest.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.paimon.metrics;
+
+import org.apache.paimon.metrics.groups.GenericMetricGroup;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** Tests for the {@link MetricGroup}. */
+public class MetricGroupTest {
+    @Test
+    public void groupRegisterMetrics() {

Review Comment:
   Test method names should begin with `test`. For example 
`testRegisterMetricsToGroup`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to