-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from covid-be-app/development
Pre-release v1.3.2 to staging
- Loading branch information
Showing
6 changed files
with
199 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
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
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
58 changes: 58 additions & 0 deletions
58
src/main/java/app/coronawarn/verification/monitoring/BatchCounter.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,58 @@ | ||
/*- | ||
* ---license-start | ||
* Corona-Warn-App | ||
* --- | ||
* Copyright (C) 2020 SAP SE and all other contributors | ||
* --- | ||
* Licensed 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. | ||
* ---license-end | ||
*/ | ||
|
||
package app.coronawarn.verification.monitoring; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* Batch counter for counting requests for monitoring. Counts up in batches, given batch size. This way, single requests | ||
* cannot be traced to semantics of the counter by comparing time stamps. | ||
*/ | ||
public class BatchCounter { | ||
|
||
private static final String SUBMISSION_CONTROLLER_REQUESTS_COUNTER_NAME = "verification_controller.test_requests"; | ||
private static final String SUBMISSION_CONTROLLER_REQUESTS_COUNTER_DESCRIPTION | ||
= "Requests to the test request Controller."; | ||
|
||
private final long batchSize; | ||
private final Counter counter; | ||
private final AtomicLong count = new AtomicLong(0L); | ||
|
||
BatchCounter(MeterRegistry meterRegistry, long batchSize, String type) { | ||
this.batchSize = batchSize; | ||
counter = Counter.builder(SUBMISSION_CONTROLLER_REQUESTS_COUNTER_NAME) | ||
.tag("type", type) | ||
.description(SUBMISSION_CONTROLLER_REQUESTS_COUNTER_DESCRIPTION) | ||
.register(meterRegistry); | ||
} | ||
|
||
/** | ||
* Increments the {@link BatchCounter}. If the batch size is reached, it is provided to monitoring, else, the internal | ||
* counter is incremented. | ||
*/ | ||
public void increment() { | ||
if (0 == count.incrementAndGet() % batchSize) { | ||
counter.increment(batchSize); | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/app/coronawarn/verification/monitoring/TestRequestMonitor.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,89 @@ | ||
/*- | ||
* ---license-start | ||
* Corona-Warn-App | ||
* --- | ||
* Copyright (C) 2020 SAP SE and all other contributors | ||
* All modifications are copyright (c) 2020 Devside SRL. | ||
* --- | ||
* Licensed 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. | ||
* ---license-end | ||
*/ | ||
|
||
package app.coronawarn.verification.monitoring; | ||
|
||
import app.coronawarn.verification.config.VerificationApplicationConfig; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Provides functionality for monitoring the diagnosis key submission handling logic. | ||
*/ | ||
@Component | ||
@ConfigurationProperties(prefix = "services.submission.monitoring") | ||
public class TestRequestMonitor { | ||
|
||
private final MeterRegistry meterRegistry; | ||
private final long batchSize; | ||
|
||
private BatchCounter nonExistingTestRequests; | ||
private BatchCounter dummyTestRequests; | ||
private BatchCounter positiveResponses; | ||
private BatchCounter negativeResponses; | ||
|
||
/** | ||
* Constructor for {@link TestRequestMonitor}. Initializes all counters to 0 upon being called. | ||
* | ||
* @param meterRegistry the meterRegistry | ||
*/ | ||
protected TestRequestMonitor( | ||
MeterRegistry meterRegistry, VerificationApplicationConfig verificationApplicationConfig) { | ||
this.meterRegistry = meterRegistry; | ||
this.batchSize = verificationApplicationConfig.getMonitoring().getBatchSize(); | ||
initializeCounters(); | ||
} | ||
|
||
/** | ||
* We count the following values. | ||
* <ul> | ||
* <li> the number of nonexisting test requests. | ||
* <li> the number of dummy test requests. | ||
* <li> the number of negative test responses | ||
* <li> the number of positive test responses | ||
* </ul> | ||
*/ | ||
private void initializeCounters() { | ||
nonExistingTestRequests = new BatchCounter(meterRegistry, batchSize, "nonexisting"); | ||
dummyTestRequests = new BatchCounter(meterRegistry, batchSize, "dummy"); | ||
positiveResponses = new BatchCounter(meterRegistry, batchSize, "positive"); | ||
negativeResponses = new BatchCounter(meterRegistry, batchSize, "negative"); | ||
} | ||
|
||
public void incrementNonExistingTestRequest() { | ||
nonExistingTestRequests.increment(); | ||
} | ||
|
||
public void incrementDummyTestRequest() { | ||
dummyTestRequests.increment(); | ||
} | ||
|
||
public void incrementPositiveTestResponse() { | ||
positiveResponses.increment(); | ||
} | ||
|
||
public void incrementNegativeTestResponse() { | ||
negativeResponses.increment(); | ||
} | ||
|
||
|
||
} |
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