Skip to content

Commit

Permalink
Merge pull request #15 from covid-be-app/development
Browse files Browse the repository at this point in the history
Pre-release v1.3.2 to staging
  • Loading branch information
rik2803 authored Sep 26, 2020
2 parents bb0309f + 37f92c6 commit ce59056
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package app.coronawarn.verification.config;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand All @@ -44,6 +46,7 @@ public class VerificationApplicationConfig {
private Tan tan = new Tan();
private AppSession appsession = new AppSession();
private Entities entities = new Entities();
private Monitoring monitoring = new Monitoring();
private Jwt jwt = new Jwt();
private Request request = new Request();

Expand Down Expand Up @@ -119,6 +122,20 @@ public static class AppSession {
int tancountermax = 1;
}

/**
* Configure the Monitoring with build property values and return the configured parameters.
*/
@Getter
@Setter
public static class Monitoring {

@Min(1)
@Max(1000)
Long batchSize;

}


/**
* Configure the Entities with build property values and return the configured parameters.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import app.coronawarn.verification.model.MobileTestPollingRequest;
import app.coronawarn.verification.model.MobileTestResultRequest;
import app.coronawarn.verification.model.TestResult;
import app.coronawarn.verification.monitoring.TestRequestMonitor;
import app.coronawarn.verification.service.FakeDelayService;
import app.coronawarn.verification.service.FakeRequestService;
import app.coronawarn.verification.service.TestResultServerService;
Expand Down Expand Up @@ -50,6 +51,9 @@ public class MobileTestStateController {
@NonNull
private final FakeRequestService fakeRequestController;

@NonNull
private final TestRequestMonitor testRequestMonitor;

/**
* Returns the test status of the COVID-19 test.
*
Expand All @@ -75,13 +79,23 @@ public DeferredResult<ResponseEntity<TestResult>> getTestState(

if (mobileTestResultRequest.isFakeRequest()) {

testRequestMonitor.incrementDummyTestRequest();
return fakeRequestController.getTestState();

} else {

StopWatch stopWatch = new StopWatch();
stopWatch.start();
TestResult testResult = testResultServerService.pollTestResult(mobileTestResultRequest);

if (testResult.isDummy()) {
testRequestMonitor.incrementNonExistingTestRequest();
} else if (testResult.isPositive()) {
testRequestMonitor.incrementPositiveTestResponse();
} else {
testRequestMonitor.incrementNegativeTestResponse();
}

testResult.applyPadding();
stopWatch.stop();
fakeDelayService.updateFakeTestRequestDelay(stopWatch.getTotalTimeMillis());
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/app/coronawarn/verification/model/TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
package app.coronawarn.verification.model;

import static app.coronawarn.verification.model.LabTestResult.PENDING;
import static app.coronawarn.verification.model.LabTestResult.POSITIVE;
import static app.coronawarn.verification.model.TestResult.ResultChannel.UNKNOWN;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import javax.persistence.Transient;
Expand Down Expand Up @@ -114,6 +116,23 @@ public void applyPadding() {

private LocalDate dateTestCommunicated;

@JsonIgnore
public boolean isPositive() {
return POSITIVE.equals(getResult());
}

/**
* Mark this as a dummy result.
*/
@JsonIgnore
public boolean isDummy() {
return PENDING.equals(getResult())
&& LocalDate.now().equals(getDateTestCommunicated())
&& LocalDate.now().equals(getDateTestPerformed())
&& LocalDate.now().equals(getDatePatientInfectious())
&& LocalDate.now().equals(getDateSampleCollected());
}

@Transient
private String responsePadding;

Expand Down
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);
}
}
}
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();
}


}
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ entities:
cleanup:
days: 21
rate: 3600000
monitoring:
batch-size: 1
initialFakeDelayMilliseconds: 10
fakeDelayMovingAverageSamples: 5
request:
Expand Down

0 comments on commit ce59056

Please sign in to comment.