Skip to content

Commit

Permalink
[PAGOPA-2382] fix and config
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang committed Nov 19, 2024
1 parent 03a0387 commit 674c1f3
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ microservice-chart:
POST_FILE_RETRY_AFTER: '10000'
LOG_LEVEL: "DEBUG"
GPD_API_URL: "https://api.dev.platform.pagopa.it/gpd/api/v1"
CRON_RECOVERY_RATE: "60s"
OTEL_SERVICE_NAME: "pagopa-gpd-upload"
OTEL_RESOURCE_ATTRIBUTES: "service.name=pagopa-gpd-upload,deployment.environment=dev"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317"
Expand Down
2 changes: 2 additions & 0 deletions helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ microservice-chart:
CONTAINER_NAME: "gpd_upload_status"
POST_FILE_RETRY_AFTER: '2000'
LOG_LEVEL: "INFO"
GPD_API_URL: "https://api.platform.pagopa.it/gpd/api/v1"
CRON_RECOVERY_RATE: "3600s" # 1 hour
OTEL_SERVICE_NAME: "pagopa-gpd-upload"
OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=prod"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317"
Expand Down
2 changes: 2 additions & 0 deletions helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ microservice-chart:
CONTAINER_NAME: "gpd_upload_status"
POST_FILE_RETRY_AFTER: '10000'
LOG_LEVEL: "INFO"
GPD_API_URL: "https://api.uat.platform.pagopa.it/gpd/api/v1"
CRON_RECOVERY_RATE: "900s" # 15 minutes
OTEL_SERVICE_NAME: "pagopa-gpd-upload"
OTEL_RESOURCE_ATTRIBUTES: "deployment.environment=uat"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://otel-collector.elastic-system.svc:4317"
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/it/gov/pagopa/gpd/upload/config/LogAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.reactivestreams.Publisher;
import org.slf4j.MDC;

import java.util.Map;
import java.util.UUID;


Expand Down Expand Up @@ -50,16 +49,18 @@ public Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, Server

return Flowable.fromPublisher(chain.proceed(request)).flatMap(response -> {

MDC.put(STATUS, "OK");
MDC.put(CODE, String.valueOf(response.getStatus().getCode()));
MDC.put(RESPONSE_TIME, String.valueOf(System.currentTimeMillis() - startTime));
MDC.put(RESPONSE, toJsonString(response.getBody().toString()));
log.info("Successful API operation {} - result: {}", request.getMethodName(), response);
MDC.remove(RESPONSE);
MDC.remove(STATUS);
MDC.remove(CODE);
MDC.remove(RESPONSE_TIME);
MDC.remove(START_TIME);
if(!path.equals("/info")) { // skip liveliness calls
MDC.put(STATUS, "OK");
MDC.put(CODE, String.valueOf(response.getStatus().getCode()));
MDC.put(RESPONSE_TIME, String.valueOf(System.currentTimeMillis() - startTime));
MDC.put(RESPONSE, toJsonString(response.getBody().toString()));
log.info("Successful API operation {} - result: {}", request.getMethodName(), response);
MDC.remove(RESPONSE);
MDC.remove(STATUS);
MDC.remove(CODE);
MDC.remove(RESPONSE_TIME);
MDC.remove(START_TIME);
}

return Flowable.just(response);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.gpd.upload.entity.Status;
import it.gov.pagopa.gpd.upload.model.AppInfo;
import it.gov.pagopa.gpd.upload.model.ProblemJson;
import it.gov.pagopa.gpd.upload.model.UploadReport;
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/it/gov/pagopa/gpd/upload/scheduled/CronJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,32 @@
public class CronJob {
private static final Logger LOG = LoggerFactory.getLogger(CronJob.class);

private final StatusRepository statusRepository;
private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");

private final long SLEEP_TIME_MILLIS = 100;

private final long sleepTimeMillis = 200;
private final StatusRepository statusRepository;

@Inject
public CronJob(StatusRepository statusRepository) {
this.statusRepository = statusRepository;
}

@Scheduled(cron = "0 0 * * * *") // every hour
@Scheduled(fixedRate = "${cron.recovery.rate}") // every hour
void execute() {
LOG.info("Start recovery job: {}", new SimpleDateFormat("dd-M-yyyy hh:mm:ss").format(new Date()));
List<Status> statusList = statusRepository.find("SELECT c.upload FROM c WHERE c.upload['end'] = null and c.upload.current = c.upload.total");
LOG.info("[Recovery] Start cron job: {}", DATE_FORMAT.format(new Date()));
List<Status> statusList = statusRepository.find("SELECT * FROM c WHERE c.upload['end'] = null and c.upload.current = c.upload.total");
statusList.forEach(status -> {
status.upload.setEnd(LocalDateTime.now());
LOG.info("[Recovery] Recovered status with upload-id: {} at {}", status.getId(), DATE_FORMAT.format(new Date()));
statusRepository.upsert(status);

try {
Thread.sleep(sleepTimeMillis);
Thread.sleep(SLEEP_TIME_MILLIS);
} catch (InterruptedException e) {
log.error("[Exception] Cron Job: thread sleep interrupted: {}", e.getMessage());
log.error("[Recovery][Exception] cron job: thread sleep interrupted: {}", e.getMessage());
}
});
LOG.info("Termination recovery job: {}", new SimpleDateFormat("dd-M-yyyy hh:mm:ss").format(new Date()));
LOG.info("[Recovery] End cron job: {}", DATE_FORMAT.format(new Date()));
}
}
4 changes: 4 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ log.level=${LOG_LEVEL}

## HTTP CLIENT
gpd.client.url=${GPD_API_URL}

## SCHEDULED JOB
cron.recovery.rate=${CRON_RECOVERY_RATE}

0 comments on commit 674c1f3

Please sign in to comment.