-
Notifications
You must be signed in to change notification settings - Fork 5k
[Improvement-18039][Metrics] Add missing metrics for workflow and task state transitions #18038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sanjana2505006
wants to merge
6
commits into
apache:dev
Choose a base branch
from
sanjana2505006:Improvement-Metrics
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+337
−45
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e30a3d3
[Improvement-18039][Metrics] Add missing metrics for workflow and tas…
sanjana2505006 78dd6ad
Fix maintainer feedback: revert unnecessary change and improve enum u…
sanjana2505006 7469149
revert changes and improve enum usage
sanjana2505006 b0aac25
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 09825af
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 c572344
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ster/src/test/java/org/apache/dolphinscheduler/server/master/metrics/TaskMetricsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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.dolphinscheduler.server.master.metrics; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| import org.apache.dolphinscheduler.server.master.engine.task.lifecycle.TaskLifecycleEventType; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import io.micrometer.core.instrument.Metrics; | ||
|
|
||
| class TaskMetricsTest { | ||
|
|
||
| @Test | ||
| void testRegisterTaskPrepared() { | ||
| TaskMetrics.registerTaskPrepared(() -> 5); | ||
| assertNotNull(Metrics.globalRegistry.find("ds.task.prepared").gauge(), | ||
| "Task prepared gauge should be registered"); | ||
| } | ||
|
|
||
| @Test | ||
| void testIncTaskInstanceByLifecycleEvent() { | ||
| // Test that the new method doesn't throw exceptions | ||
| TaskMetrics.incTaskInstanceByLifecycleEvent(TaskLifecycleEventType.DISPATCHED); | ||
| TaskMetrics.incTaskInstanceByLifecycleEvent(TaskLifecycleEventType.SUCCEEDED); | ||
| TaskMetrics.incTaskInstanceByLifecycleEvent(TaskLifecycleEventType.FAILED); | ||
| TaskMetrics.incTaskInstanceByLifecycleEvent(TaskLifecycleEventType.KILLED); | ||
| TaskMetrics.incTaskInstanceByLifecycleEvent(TaskLifecycleEventType.RETRY); | ||
| TaskMetrics.incTaskInstanceByLifecycleEvent(TaskLifecycleEventType.TIMEOUT); | ||
| TaskMetrics.incTaskInstanceByLifecycleEvent(TaskLifecycleEventType.FATAL); | ||
| TaskMetrics.incTaskInstanceByLifecycleEvent(null); | ||
| // Should not throw any exceptions | ||
| } | ||
|
|
||
| } |
175 changes: 175 additions & 0 deletions
175
...t/java/org/apache/dolphinscheduler/server/master/metrics/WorkflowInstanceMetricsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| /* | ||
| * 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.dolphinscheduler.server.master.metrics; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.Metrics; | ||
| import io.micrometer.core.instrument.Timer; | ||
|
|
||
| class WorkflowInstanceMetricsTest { | ||
|
|
||
| @Test | ||
| void testIncWorkflowInstanceByStateAndWorkflowDefinitionCode_submitState() { | ||
| String defCode = "test_submit_1"; | ||
| WorkflowInstanceMetrics.incWorkflowInstanceByStateAndWorkflowDefinitionCode( | ||
| WorkflowExecutionStatus.SUBMITTED_SUCCESS, defCode); | ||
| Counter counter = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "submit") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNotNull(counter, "Counter should be registered for submit state"); | ||
| assertEquals(1, counter.count(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| void testIncWorkflowInstanceByStateAndWorkflowDefinitionCode_failureState() { | ||
| String defCode = "test_failure_1"; | ||
| WorkflowInstanceMetrics.incWorkflowInstanceByStateAndWorkflowDefinitionCode( | ||
| WorkflowExecutionStatus.FAILURE, defCode); | ||
| Counter counter = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "fail") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNotNull(counter, "Counter should be registered for fail state"); | ||
| assertEquals(1, counter.count(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| void testIncWorkflowInstanceByStateAndWorkflowDefinitionCode_successState() { | ||
| String defCode = "test_success_1"; | ||
| WorkflowInstanceMetrics.incWorkflowInstanceByStateAndWorkflowDefinitionCode( | ||
| WorkflowExecutionStatus.SUCCESS, defCode); | ||
| Counter counter = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "success") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNotNull(counter, "Counter should be registered for success state"); | ||
| assertEquals(1, counter.count(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| void testIncWorkflowInstanceByStateAndWorkflowDefinitionCode_stopState() { | ||
| String defCode = "test_stop_1"; | ||
| WorkflowInstanceMetrics.incWorkflowInstanceByStateAndWorkflowDefinitionCode( | ||
| WorkflowExecutionStatus.STOP, defCode); | ||
| Counter counter = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "stop") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNotNull(counter, "Counter should be registered for stop state"); | ||
| assertEquals(1, counter.count(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| void testIncWorkflowInstanceByStateAndWorkflowDefinitionCode_pauseState() { | ||
| String defCode = "test_pause_1"; | ||
| WorkflowInstanceMetrics.incWorkflowInstanceByStateAndWorkflowDefinitionCode( | ||
| WorkflowExecutionStatus.PAUSE, defCode); | ||
| Counter counter = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "pause") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNotNull(counter, "Counter should be registered for pause state"); | ||
| assertEquals(1, counter.count(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| void testIncWorkflowInstanceByStateAndWorkflowDefinitionCode_failoverState() { | ||
| String defCode = "test_failover_1"; | ||
| WorkflowInstanceMetrics.incWorkflowInstanceByStateAndWorkflowDefinitionCode( | ||
| WorkflowExecutionStatus.FAILOVER, defCode); | ||
| Counter counter = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "failover") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNotNull(counter, "Counter should be registered for failover state"); | ||
| assertEquals(1, counter.count(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| void testIncWorkflowInstanceByStateAndWorkflowDefinitionCode_defaultMapping() { | ||
| String defCode = "test_running_1"; | ||
| WorkflowInstanceMetrics.incWorkflowInstanceByStateAndWorkflowDefinitionCode( | ||
| WorkflowExecutionStatus.RUNNING_EXECUTION, defCode); | ||
| Counter counter = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "running_execution") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNotNull(counter, "Counter should be registered for default-mapped state"); | ||
| assertEquals(1, counter.count(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| void testRecordCommandQueryTime() { | ||
| WorkflowInstanceMetrics.recordCommandQueryTime(100L); | ||
| Timer timer = Metrics.globalRegistry.find("ds.workflow.command.query.duration").timer(); | ||
| assertNotNull(timer, "Command query timer should be registered"); | ||
| assertEquals(1, timer.count(), "Timer should have recorded one event"); | ||
| } | ||
|
|
||
| @Test | ||
| void testRecordWorkflowInstanceGenerateTime() { | ||
| WorkflowInstanceMetrics.recordWorkflowInstanceGenerateTime(200L); | ||
| Timer timer = Metrics.globalRegistry.find("ds.workflow.instance.generate.duration").timer(); | ||
| assertNotNull(timer, "Workflow instance generate timer should be registered"); | ||
| assertEquals(1, timer.count(), "Timer should have recorded one event"); | ||
| } | ||
|
|
||
| @Test | ||
| void testRegisterWorkflowInstanceRunningGauge() { | ||
| WorkflowInstanceMetrics.registerWorkflowInstanceRunningGauge(() -> 10); | ||
| assertNotNull(Metrics.globalRegistry.find("ds.workflow.instance.running").gauge(), | ||
| "Running gauge should be registered"); | ||
| } | ||
|
|
||
| @Test | ||
| void testRegisterWorkflowInstanceResubmitGauge() { | ||
| WorkflowInstanceMetrics.registerWorkflowInstanceResubmitGauge(() -> 3); | ||
| assertNotNull(Metrics.globalRegistry.find("ds.workflow.instance.resubmit").gauge(), | ||
| "Resubmit gauge should be registered"); | ||
| } | ||
|
|
||
| @Test | ||
| void testCleanUpWorkflowInstanceCountMetricsByDefinitionCode() { | ||
| String defCode = "99999"; | ||
| WorkflowInstanceMetrics.incWorkflowInstanceByStateAndWorkflowDefinitionCode( | ||
| WorkflowExecutionStatus.SUCCESS, defCode); | ||
| Counter counterBefore = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "success") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNotNull(counterBefore, "Counter should exist before cleanup"); | ||
|
|
||
| WorkflowInstanceMetrics.cleanUpWorkflowInstanceCountMetricsByDefinitionCode(99999L); | ||
|
|
||
| Counter counterAfter = Metrics.globalRegistry.find("ds.workflow.instance.count") | ||
| .tag("state", "success") | ||
| .tag("workflow.definition.code", defCode) | ||
| .counter(); | ||
| assertNull(counterAfter, "Counter should be removed after cleanup"); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to store
TaskLifecycleEventTypedirectly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have addressed your suggestion. Thank you for the feedback!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still unaddressed.