-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
control-service: add MeterRegistry counters for DataJobsSynchronizer (#…
…2844) what: added telemetry counters for the DataJobsSynchronizer why: The counters can be used to monitor if the synchronizeDataJobs method is executing as expected. testing: added unit test --------- Signed-off-by: mrMoZ1 <[email protected]> Co-authored-by: github-actions <>
- Loading branch information
Momchil Z
authored
Oct 30, 2023
1 parent
895ee29
commit 21da2df
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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); | ||
} | ||
} |