-
Notifications
You must be signed in to change notification settings - Fork 66
control-service: add MeterRegistry counters for DataJobsSynchronizer #2844
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
65 changes: 65 additions & 0 deletions
65
...ervice/src/main/java/com/vmware/taurus/service/monitoring/DataJobSynchronizerMonitor.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,65 @@ | ||
| /* | ||
| * Copyright 2021-2023 VMware, Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package com.vmware.taurus.service.monitoring; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @Slf4j | ||
| public class DataJobSynchronizerMonitor { | ||
|
|
||
| public static final String DATAJOBS_SUCCESSFUL_SYNCHRONIZER_INVOCATIONS_COUNTER = | ||
| "vdk.deploy.datajob.synchronizer.successful.invocations.counter"; | ||
| public static final String DATAJOBS_FAILED_SYNCHRONIZER_INVOCATIONS_COUNTER = | ||
| "vdk.deploy.datajob.synchronizer.failed.invocations.counter"; | ||
|
|
||
| private final Counter successfulInvocationsCounter; | ||
| private final Counter failedInvocationsCounter; | ||
|
|
||
| @Autowired(required = true) | ||
| public DataJobSynchronizerMonitor(MeterRegistry meterRegistry) { | ||
| successfulInvocationsCounter = | ||
| Counter.builder(DATAJOBS_SUCCESSFUL_SYNCHRONIZER_INVOCATIONS_COUNTER) | ||
| .description( | ||
| "Counts the number of times the synchronizeDataJobs() method is called and" | ||
| + " completes.") | ||
| .register(meterRegistry); | ||
|
|
||
| failedInvocationsCounter = | ||
| Counter.builder(DATAJOBS_FAILED_SYNCHRONIZER_INVOCATIONS_COUNTER) | ||
| .description( | ||
| "Counts the number of times the synchronizeDataJobs() method failed to finish.") | ||
| .register(meterRegistry); | ||
| } | ||
|
|
||
| /** | ||
| * Counts the number of times the DataJobSynchronizer's synchronize method was invoked and | ||
| * completed. | ||
| */ | ||
| public void countSuccessfulSynchronizerInvocation() { | ||
| incrementCounter(successfulInvocationsCounter); | ||
| } | ||
|
|
||
| /** | ||
| * Counts the number of failed data job deployment synchronizations invocations by the | ||
| * DataJobsSynchronizer due to K8S issues. | ||
| */ | ||
| public void countSynchronizerFailures() { | ||
| incrementCounter(failedInvocationsCounter); | ||
| } | ||
|
|
||
| private void incrementCounter(Counter counter) { | ||
| try { | ||
| counter.increment(); | ||
| } catch (Exception e) { | ||
| log.warn("Error while trying to increment counter.", e); | ||
| } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
...ce/src/test/java/com/vmware/taurus/service/monitoring/DataJobSynchronizerMonitorTest.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,43 @@ | ||
| /* | ||
| * Copyright 2021-2023 VMware, Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package com.vmware.taurus.service.monitoring; | ||
|
|
||
| import com.vmware.taurus.ControlplaneApplication; | ||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
|
|
||
| @SpringBootTest(classes = ControlplaneApplication.class) | ||
| public class DataJobSynchronizerMonitorTest { | ||
|
|
||
| @Autowired DataJobSynchronizerMonitor dataJobSynchronizerMonitor; | ||
|
|
||
| @Autowired private MeterRegistry meterRegistry; | ||
|
|
||
| @Test | ||
| public void testIncrementSuccessfulInvocations() { | ||
| var counter = | ||
| meterRegistry.counter( | ||
| DataJobSynchronizerMonitor.DATAJOBS_SUCCESSFUL_SYNCHRONIZER_INVOCATIONS_COUNTER); | ||
| Assertions.assertEquals(0.0, counter.count(), 0.001); | ||
| dataJobSynchronizerMonitor.countSuccessfulSynchronizerInvocation(); | ||
|
|
||
| Assertions.assertEquals(1, counter.count(), 0.001); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIncrementFailedInvocations() { | ||
| var counter = | ||
| meterRegistry.counter( | ||
| DataJobSynchronizerMonitor.DATAJOBS_FAILED_SYNCHRONIZER_INVOCATIONS_COUNTER); | ||
| Assertions.assertEquals(0.0, counter.count(), 0.001); | ||
| dataJobSynchronizerMonitor.countSynchronizerFailures(); | ||
|
|
||
| Assertions.assertEquals(1, counter.count(), 0.001); | ||
| } | ||
| } |
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.