This is an automated email from the ASF dual-hosted git repository.
zihanli58 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/gobblin.git
The following commit(s) were added to refs/heads/master by this push:
new 621b7c3 [GOBBLIN-1598]Fix metrics already exist issue in dag manager
(#3454)
621b7c3 is described below
commit 621b7c30616f09342d98179c94772673417e00b3
Author: Zihan Li <[email protected]>
AuthorDate: Mon Jan 24 18:58:27 2022 -0800
[GOBBLIN-1598]Fix metrics already exist issue in dag manager (#3454)
* [GOBBLIN-1598]Fix metrics already exist issue in dag manager
* fix typo
* address comments
---
.../service/modules/orchestration/DagManager.java | 10 ++++++
.../modules/orchestration/TestServiceMetrics.java | 39 ++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git
a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManager.java
b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManager.java
index 354faed..b69fb26 100644
---
a/gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManager.java
+++
b/gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManager.java
@@ -17,6 +17,7 @@
package org.apache.gobblin.service.modules.orchestration;
+import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
@@ -70,6 +71,7 @@ import org.apache.gobblin.metrics.RootMetricContext;
import org.apache.gobblin.metrics.ServiceMetricNames;
import org.apache.gobblin.metrics.event.EventSubmitter;
import org.apache.gobblin.metrics.event.TimingEvent;
+import org.apache.gobblin.metrics.metric.filter.MetricNameRegexFilter;
import org.apache.gobblin.runtime.api.FlowSpec;
import org.apache.gobblin.runtime.api.JobSpec;
import org.apache.gobblin.runtime.api.Spec;
@@ -399,6 +401,9 @@ public class DagManager extends AbstractIdleService {
} else { //Mark the DagManager inactive.
log.info("Inactivating the DagManager. Shutting down all DagManager
threads");
this.scheduledExecutorPool.shutdown();
+ // The DMThread's metrics mappings follow the lifecycle of the
DMThread itself and so are lost by DM deactivation-reactivation but the
RootMetricContext is a (persistent) singleton.
+ // To avoid IllegalArgumentException by the RMC preventing (re-)add of
a metric already known, remove all metrics that a new DMThread thread would
attempt to add (in DagManagerThread::initialize) whenever running
post-re-enablement
+
RootMetricContext.get().removeMatching(getMetricsFilterForDagManager());
try {
this.scheduledExecutorPool.awaitTermination(TERMINATION_TIMEOUT,
TimeUnit.SECONDS);
} catch (InterruptedException e) {
@@ -411,6 +416,11 @@ public class DagManager extends AbstractIdleService {
}
}
+ @VisibleForTesting
+ protected static MetricNameRegexFilter getMetricsFilterForDagManager() {
+ return new MetricNameRegexFilter(ServiceMetricNames.GOBBLIN_SERVICE_PREFIX
+ "\\..*\\." + ServiceMetricNames.RUNNING_STATUS);
+ }
+
/**
* Each {@link DagManagerThread} performs 2 actions when scheduled:
* <ol>
diff --git
a/gobblin-service/src/test/java/org/apache/gobblin/service/modules/orchestration/TestServiceMetrics.java
b/gobblin-service/src/test/java/org/apache/gobblin/service/modules/orchestration/TestServiceMetrics.java
new file mode 100644
index 0000000..4211382
--- /dev/null
+++
b/gobblin-service/src/test/java/org/apache/gobblin/service/modules/orchestration/TestServiceMetrics.java
@@ -0,0 +1,39 @@
+/*
+ * 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.gobblin.service.modules.orchestration;
+
+import com.codahale.metrics.Metric;
+import org.apache.gobblin.metrics.metric.filter.MetricNameRegexFilter;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import static org.mockito.Mockito.*;
+
+@Test
+public class TestServiceMetrics {
+ @Test
+ public void matchesTest() {
+
+ MetricNameRegexFilter metricNameRegexForDagManager =
DagManager.getMetricsFilterForDagManager();
+
Assert.assertTrue(metricNameRegexForDagManager.matches("GobblinService.testGroup.testFlow.RunningStatus",
mock(Metric.class)));
+
Assert.assertTrue(metricNameRegexForDagManager.matches("GobblinService.test..RunningStatus",
mock(Metric.class)));
+
Assert.assertFalse(metricNameRegexForDagManager.matches("test3.RunningStatus",
mock(Metric.class)));
+
Assert.assertFalse(metricNameRegexForDagManager.matches("GobblinService.test4RunningStatus",
mock(Metric.class)));
+
Assert.assertFalse(metricNameRegexForDagManager.matches("GobblinServicetest5.RunningStatus",
mock(Metric.class)));
+ }
+}