-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: dispatch timeout metrics for all priorities with staggered delay #4196
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
hengyuss
wants to merge
9
commits into
apache:master
Choose a base branch
from
hengyuss:fix/continue-metrics-on-availability-failure-with-staggered-dispatch
base: master
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.
+181
−3
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bfd4882
fix: dispatch timeout metrics for all priorities with staggered delay
hengyuss 878ae3d
Merge branch 'master' into fix/continue-metrics-on-availability-failu…
Duansg 0f5fc7c
fix: add tests
hengyuss 09d38cb
fix: add license header
hengyuss a8753a5
Merge branch 'master' into fix/continue-metrics-on-availability-failu…
Duansg 7bbfd2f
Merge branch 'master' into fix/continue-metrics-on-availability-failu…
Duansg 2108218
fix: remove delay handle and test
hengyuss d906f2e
Merge branch 'master' into fix/continue-metrics-on-availability-failu…
hengyuss c7c1955
Merge branch 'master' into fix/continue-metrics-on-availability-failu…
Duansg 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
180 changes: 180 additions & 0 deletions
180
...collector/src/test/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcherTest.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,180 @@ | ||
| /* | ||
| * 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.hertzbeat.collector.dispatch; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.doNothing; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.lang.reflect.Method; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.hertzbeat.collector.dispatch.entrance.internal.CollectJobService; | ||
| import org.apache.hertzbeat.collector.dispatch.unit.UnitConvert; | ||
| import org.apache.hertzbeat.collector.timer.TimerDispatch; | ||
| import org.apache.hertzbeat.collector.timer.WheelTimerTask; | ||
| import org.apache.hertzbeat.common.entity.job.Job; | ||
| import org.apache.hertzbeat.common.entity.job.Metrics; | ||
| import org.apache.hertzbeat.common.queue.CommonDataQueue; | ||
| import org.apache.hertzbeat.common.timer.Timeout; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| class CommonDispatcherTest { | ||
|
|
||
| @Mock | ||
| private MetricsCollectorQueue jobRequestQueue; | ||
|
|
||
| @Mock | ||
| private TimerDispatch timerDispatch; | ||
|
|
||
| @Mock | ||
| private CommonDataQueue commonDataQueue; | ||
|
|
||
| @Mock | ||
| private WorkerPool workerPool; | ||
|
|
||
| @Mock | ||
| private CollectJobService collectJobService; | ||
|
|
||
| @Mock | ||
| private Timeout timeout; | ||
|
|
||
| @Mock | ||
| private WheelTimerTask wheelTimerTask; | ||
|
|
||
| private List<UnitConvert> unitConvertList = List.of(); | ||
|
|
||
| private CommonDispatcher dispatcher; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| MockitoAnnotations.openMocks(this); | ||
| when(collectJobService.getCollectorIdentity()).thenReturn("test-collector"); | ||
| doNothing().when(workerPool).executeLongRunning(any()); | ||
| dispatcher = new CommonDispatcher(jobRequestQueue, timerDispatch, commonDataQueue, workerPool, | ||
| collectJobService, unitConvertList); | ||
| } | ||
|
|
||
| @Test | ||
| void dispatchCollectDataExecute_When_Priority0MetricsTimeout() throws Exception { | ||
| Job job = buildCycleJobWithMetrics(); | ||
| job.constructPriorMetrics(); | ||
| Metrics availabilityMetrics = job.getMetrics().get(0); | ||
|
|
||
| when(timeout.task()).thenReturn(wheelTimerTask); | ||
| when(wheelTimerTask.getJob()).thenReturn(job); | ||
| when(timeout.isCancelled()).thenReturn(false); | ||
|
|
||
| Map<String, CommonDispatcher.MetricsTime> metricsTimeoutMonitorMap = getMetricsTimeoutMonitorMap(); | ||
| CommonDispatcher.MetricsTime metricsTime = new CommonDispatcher.MetricsTime( | ||
| System.currentTimeMillis() - 300_000L, | ||
| availabilityMetrics, | ||
| timeout | ||
| ); | ||
| metricsTimeoutMonitorMap.put(job.getId() + "-" + availabilityMetrics.getName(), metricsTime); | ||
|
|
||
| invokeMonitorCollectTaskTimeout(); | ||
|
|
||
| verify(commonDataQueue).sendMetricsData(any()); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void monitorPipelineNotStall_When_Priority0MetricsTimeout() throws Exception { | ||
| Job job = buildCycleJobWithMetrics(); | ||
| job.constructPriorMetrics(); | ||
| Metrics availabilityMetrics = job.getMetrics().get(0); | ||
|
|
||
| when(timeout.task()).thenReturn(wheelTimerTask); | ||
| when(wheelTimerTask.getJob()).thenReturn(job); | ||
| when(timeout.isCancelled()).thenReturn(false); | ||
|
|
||
| Map<String, CommonDispatcher.MetricsTime> metricsTimeoutMonitorMap = getMetricsTimeoutMonitorMap(); | ||
| CommonDispatcher.MetricsTime metricsTime = new CommonDispatcher.MetricsTime( | ||
| System.currentTimeMillis() - 300_000L, | ||
| availabilityMetrics, | ||
| timeout | ||
| ); | ||
| metricsTimeoutMonitorMap.put(job.getId() + "-" + availabilityMetrics.getName(), metricsTime); | ||
|
|
||
| invokeMonitorCollectTaskTimeout(); | ||
|
|
||
| verify(timerDispatch).cyclicJob(any(WheelTimerTask.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void monitorPipelineNotStall_When_Priority_gt_0_MetricsTimeout() throws Exception { | ||
| Job job = buildCycleJobWithMetrics(); | ||
| job.constructPriorMetrics(); | ||
| Metrics availabilityMetrics = job.getMetrics().get(0); | ||
| Metrics cpu = job.getMetrics().get(1); | ||
| job.getNextCollectMetrics(availabilityMetrics, false); | ||
|
|
||
| when(timeout.task()).thenReturn(wheelTimerTask); | ||
| when(wheelTimerTask.getJob()).thenReturn(job); | ||
| when(timeout.isCancelled()).thenReturn(false); | ||
|
|
||
| Map<String, CommonDispatcher.MetricsTime> metricsTimeoutMonitorMap = getMetricsTimeoutMonitorMap(); | ||
| CommonDispatcher.MetricsTime metricsTime = new CommonDispatcher.MetricsTime( | ||
| System.currentTimeMillis() - 300_000L, | ||
| cpu, | ||
| timeout | ||
| ); | ||
| metricsTimeoutMonitorMap.put(job.getId() + "-" + cpu.getName(), metricsTime); | ||
|
|
||
| invokeMonitorCollectTaskTimeout(); | ||
|
|
||
| verify(jobRequestQueue).addJob(any(MetricsCollect.class)); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private Map<String, CommonDispatcher.MetricsTime> getMetricsTimeoutMonitorMap() throws Exception { | ||
| Field field = CommonDispatcher.class.getDeclaredField("metricsTimeoutMonitorMap"); | ||
| field.setAccessible(true); | ||
| return (Map<String, CommonDispatcher.MetricsTime>) field.get(dispatcher); | ||
| } | ||
|
|
||
| private void invokeMonitorCollectTaskTimeout() throws Exception { | ||
| Method method = CommonDispatcher.class.getDeclaredMethod("monitorCollectTaskTimeout"); | ||
| method.setAccessible(true); | ||
| method.invoke(dispatcher); | ||
| } | ||
|
|
||
| private Job buildCycleJobWithMetrics() { | ||
| return Job.builder() | ||
| .id(1L) | ||
| .monitorId(100L) | ||
| .app("linux") | ||
| .isCyclic(true) | ||
| .isSd(false) | ||
| .configmap(List.of()) | ||
| .metrics(List.of( | ||
| Metrics.builder().name("availability").priority((byte) 0).interval(60L).build(), | ||
| Metrics.builder().name("cpu").priority((byte) 1).interval(60L).build(), | ||
| Metrics.builder().name("memory").priority((byte) 2).interval(60L).build() | ||
| )) | ||
| .build(); | ||
| } | ||
|
|
||
|
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.