-
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
11
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
−77
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c0013cc
[Improvement-18039][Metrics] Add missing metrics to Master and Worker…
sanjana2505006 cb3b09d
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 be08d86
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 edeef4e
[Improvement-18039][Metrics] Fix missing metrics imports and workflow…
sanjana2505006 f0c22a0
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 7e3b71d
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 cf0e05f
Add unit tests for TaskMetrics and WorkflowInstanceMetrics to fix Son…
sanjana2505006 3e789ba
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 d689e93
Merge branch 'dev' into Improvement-Metrics
SbloodyS 21e6a03
Merge branch 'dev' into Improvement-Metrics
sanjana2505006 f5e105b
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -46,6 +46,7 @@ | |||||
| import org.apache.dolphinscheduler.server.master.engine.task.runnable.ITaskExecutionRunnable; | ||||||
| import org.apache.dolphinscheduler.server.master.engine.workflow.lifecycle.event.WorkflowTopologyLogicalTransitionWithTaskFinishLifecycleEvent; | ||||||
| import org.apache.dolphinscheduler.server.master.engine.workflow.runnable.IWorkflowExecutionRunnable; | ||||||
| import org.apache.dolphinscheduler.server.master.metrics.TaskMetrics; | ||||||
|
|
||||||
| import org.apache.commons.lang3.StringUtils; | ||||||
|
|
||||||
|
|
@@ -109,6 +110,7 @@ public void onFatalEvent(final IWorkflowExecutionRunnable workflowExecutionRunna | |||||
|
|
||||||
| if (taskExecutionRunnable.isTaskInstanceCanRetry()) { | ||||||
| taskExecutionRunnable.getWorkflowEventBus().publish(TaskRetryLifecycleEvent.of(taskExecutionRunnable)); | ||||||
| TaskMetrics.incTaskInstanceByState("retry"); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -131,6 +133,7 @@ private void persistentTaskInstanceFatalEventToDB(final ITaskExecutionRunnable t | |||||
| taskInstance.setState(TaskExecutionStatus.FAILURE); | ||||||
| taskInstance.setEndTime(taskFatalEvent.getEndTime()); | ||||||
| taskInstanceDao.updateById(taskInstance); | ||||||
| TaskMetrics.incTaskInstanceByState("fail"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -141,6 +144,7 @@ public void onDispatchedEvent(final IWorkflowExecutionRunnable workflowExecution | |||||
| taskInstance.setState(DISPATCH); | ||||||
| taskInstance.setHost(taskDispatchedEvent.getExecutorHost()); | ||||||
| taskInstanceDao.updateById(taskInstance); | ||||||
| TaskMetrics.incTaskInstanceByState("dispatch"); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -196,7 +200,7 @@ private void persistentTaskInstanceKilledEventToDB(final ITaskExecutionRunnable | |||||
| taskInstance.setState(TaskExecutionStatus.KILL); | ||||||
| taskInstance.setEndTime(taskKilledEvent.getEndTime()); | ||||||
| taskInstanceDao.updateById(taskInstance); | ||||||
|
|
||||||
| TaskMetrics.incTaskInstanceByState("kill"); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -208,6 +212,7 @@ public void onFailedEvent(final IWorkflowExecutionRunnable workflowExecutionRunn | |||||
|
|
||||||
| if (taskExecutionRunnable.isTaskInstanceCanRetry()) { | ||||||
| taskExecutionRunnable.getWorkflowEventBus().publish(TaskRetryLifecycleEvent.of(taskExecutionRunnable)); | ||||||
| TaskMetrics.incTaskInstanceByState("retry"); | ||||||
| return; | ||||||
| } | ||||||
| // If all successors are condition tasks, then the task will not be marked as failure. | ||||||
|
|
@@ -229,6 +234,7 @@ private void persistentTaskInstanceFailedEventToDB(final ITaskExecutionRunnable | |||||
| taskInstance.setState(TaskExecutionStatus.FAILURE); | ||||||
| taskInstance.setEndTime(taskFailedEvent.getEndTime()); | ||||||
| taskInstanceDao.updateById(taskInstance); | ||||||
| TaskMetrics.incTaskInstanceByState("fail"); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -259,6 +265,7 @@ protected void persistentTaskInstanceSuccessEventToDB(final ITaskExecutionRunnab | |||||
| JSONUtils.toJsonString(taskSuccessEvent.getVarPool())); | ||||||
| taskInstance.setVarPool(VarPoolUtils.serializeVarPool(finalVarPool)); | ||||||
| taskInstanceDao.updateById(taskInstance); | ||||||
| TaskMetrics.incTaskInstanceByState("success"); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
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
84 changes: 84 additions & 0 deletions
84
...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,84 @@ | ||
| /* | ||
| * 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.assertTrue; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.Metrics; | ||
|
|
||
| class TaskMetricsTest { | ||
|
|
||
| @Test | ||
| void testIncTaskInstanceByState_validStates() { | ||
| List<String> validStates = Arrays.asList( | ||
| "submit", "timeout", "finish", "failover", "retry", "dispatch", "success", "kill", "fail", "stop"); | ||
|
|
||
| for (String state : validStates) { | ||
| Counter counter = Metrics.globalRegistry.find("ds.task.instance.count") | ||
| .tag("state", state) | ||
| .counter(); | ||
| assertNotNull(counter, "Counter should exist for state: " + state); | ||
| double before = counter.count(); | ||
| TaskMetrics.incTaskInstanceByState(state); | ||
| assertEquals(before + 1, counter.count(), 0.001, | ||
| "Counter should be incremented for state: " + state); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testIncTaskInstanceByState_invalidState() { | ||
| TaskMetrics.incTaskInstanceByState("nonexistent_state"); | ||
| Counter counter = Metrics.globalRegistry.find("ds.task.instance.count") | ||
| .tag("state", "nonexistent_state") | ||
| .counter(); | ||
| assertTrue(counter == null || counter.count() == 0, | ||
| "Counter should not exist or be zero for invalid state"); | ||
| } | ||
|
|
||
| @Test | ||
| void testIncTaskInstanceByState_multipleIncrements() { | ||
| Counter counter = Metrics.globalRegistry.find("ds.task.instance.count") | ||
| .tag("state", "submit") | ||
| .counter(); | ||
| assertNotNull(counter); | ||
| double before = counter.count(); | ||
|
|
||
| TaskMetrics.incTaskInstanceByState("submit"); | ||
| TaskMetrics.incTaskInstanceByState("submit"); | ||
| TaskMetrics.incTaskInstanceByState("submit"); | ||
|
|
||
| assertEquals(before + 3, counter.count(), 0.001, | ||
| "Counter should be incremented by 3 after three calls"); | ||
| } | ||
|
|
||
| @Test | ||
| void testRegisterTaskPrepared() { | ||
| TaskMetrics.registerTaskPrepared(() -> 5); | ||
| assertNotNull(Metrics.globalRegistry.find("ds.task.prepared").gauge(), | ||
| "Task prepared gauge should be registered"); | ||
| } | ||
|
|
||
| } |
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.