Skip to content
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

[NOD-378] Out-of-memory #30

Merged
merged 11 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# see https://help.github.com/en/articles/about-code-owners#example-of-a-codeowners-file

* @pagopa/pagopa-team-core @pagopa/pagopa-team-core-associates
* @pagopa/pagopa-team-core @cesarecaccuri @ignaziobricco @marcomeretta
4 changes: 2 additions & 2 deletions helm/weu-dev/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ oracle:
!!merge <<: *basecache
image:
repository: pagopadcommonacr.azurecr.io/pagopaapiconfigcache
tag: "0.6.0"
tag: "0.6.0-2-NOD-378-out-of-memory"
ingress:
!!merge <<: *ingress
path: /api-config-cache/o(/|$)(.*)
Expand All @@ -94,7 +94,7 @@ oracledev:
!!merge <<: *basecache
image:
repository: pagopadcommonacr.azurecr.io/pagopaapiconfigcache
tag: "0.6.0"
tag: "0.6.0-2-NOD-378-out-of-memory"
ingress:
!!merge <<: *ingress
path: /api-config-cachedev/o(/|$)(.*)
Expand Down
2 changes: 1 addition & 1 deletion helm/weu-it/values-it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ oracle:
!!merge <<: *basecache
image:
repository: pagopadcommonacr.azurecr.io/pagopaapiconfigcache
tag: "0.2.1"
tag: "0.6.0-2-NOD-378-out-of-memory"
ingress:
!!merge <<: *ingress
path: /api-config-cache/or(/|$)(.*)
Expand Down
2 changes: 1 addition & 1 deletion helm/weu-prf/values-prf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ oracle:
!!merge <<: *basecache
image:
repository: pagopaucommonacr.azurecr.io/pagopaapiconfigcache
tag: "0.6.0"
tag: "0.6.0-2-NOD-378-out-of-memory"
ingress:
!!merge <<: *ingress
path: /api-config-cache/or(/|$)(.*)
Expand Down
5 changes: 3 additions & 2 deletions helm/weu-prod/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ oracle:
!!merge <<: *basecache
image:
repository: pagopapcommonacr.azurecr.io/pagopaapiconfigcache
tag: "0.6.0"
tag: "0.6.0-2-NOD-378-out-of-memory"
ingress:
!!merge <<: *ingress
path: /api-config-cache/o(/|$)(.*)
Expand All @@ -79,11 +79,12 @@ oracle:
DB_CONFIG_URL: "jdbc:oracle:thin:@db-nodo-pagamenti.p.db-nodo-pagamenti.com:1521/NDPSPCP_NODO4_CFG"
DB_CONFIG_USER: "NODO4_CFG"
DB_CONFIG_DRIVER: "oracle.jdbc.OracleDriver"
JAVA_OPTS: "-Dspring.jpa.show-sql=false"
JAVA_OPTS: "-Dspring.jpa.show-sql=false -XX:MaxHeapSize=4g"
DATABASE_ID: "o"
IN_PROGRESS_TTL: "20"
HEALTHCHECK_QUERY: "select 1 from dual"
SAVE_DB: "true"
DEFAULT_LOGGING_LEVEL: "info" # TODO remove
secretProvider:
!!merge <<: *azureSecretProvider
envSecrets:
Expand Down
2 changes: 1 addition & 1 deletion helm/weu-uat/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ oracle:
!!merge <<: *basecache
image:
repository: pagopaucommonacr.azurecr.io/pagopaapiconfigcache
tag: "0.6.0"
tag: "0.6.0-2-NOD-378-out-of-memory"
ingress:
!!merge <<: *ingress
path: /api-config-cache/o(/|$)(.*)
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "API-Config Cacher",
"description": "Generate cache for regarding Nodo dei Pagamenti configuration",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "0.6.0"
"version": "0.6.0-2-NOD-378-out-of-memory"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi_fdrv1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "API-Config Cacher",
"description": "Generate cache for regarding Nodo dei Pagamenti configuration",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "0.6.0"
"version": "0.6.0-2-NOD-378-out-of-memory"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi_nodev1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "API-Config Cacher",
"description": "Generate cache for regarding Nodo dei Pagamenti configuration",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "0.6.0"
"version": "0.6.0-2-NOD-378-out-of-memory"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi_verifierv1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "API-Config Cacher",
"description": "Generate cache for regarding Nodo dei Pagamenti configuration",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "0.6.0"
"version": "0.6.0-2-NOD-378-out-of-memory"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>it.gov.pagopa.api-config</groupId>
<artifactId>cache</artifactId>
<version>0.6.0</version>
<version>0.6.0-2-NOD-378-out-of-memory</version>
<name>API-Config Cacher</name>
<description>Generate cache for regarding Nodo dei Pagamenti configuration</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,23 +450,27 @@ public ConfigDataV1 newCacheV1(String stakeholder, Optional<NodeCacheKey[]> keys
String actualKey = getKeyV1(stakeholder);
String actualKeyV1 = getKeyV1Id(stakeholder);

log.info(String.format("saving on Redis %s %s", actualKey, actualKeyV1));
redisRepository.pushToRedisAsync(actualKey, actualKeyV1, configData);

if (saveDB) {
log.info("saving on CACHE table " + configData.getVersion());
try {
// to prevent error caused by version string too long (e.g. appVersion containing branch
// name)
// it is cut the version string to 32 chars.
cacheRepository.save(
Cache.builder()
.id(configData.getVersion())
.cache(jsonSerializer.serialize(configData))
.time(ZonedDateTime.now())
.version(Constants.GZIP_JSON_V1 + "-" + appVersion)
.version((Constants.GZIP_JSON_V1 + "-" + appVersion).substring(0, 32))
.build());
log.info("saved on CACHE table " + configData.getVersion());
} catch (Exception e) {
log.error("[ALERT] could not save on db", e);
}
}

redisRepository.pushToRedisAsync(actualKey, actualKeyV1, configData);
} catch (Exception e) {
log.error("[ALERT] problem to generate cache", e);
removeCacheV1InProgress(stakeholder);
Expand Down Expand Up @@ -613,7 +617,9 @@ public List<Station> findAllStazioni() {

public List<StationCreditorInstitution> findAllPaStazioniPa() {
log.info("loading PaStations");
return paStazioniRepository.findAllFetching().stream()
return paStazioniRepository
.findAllFetching()
.stream()
.map(
s ->
new StationCreditorInstitution(
Expand Down Expand Up @@ -647,7 +653,9 @@ public List<Channel> getAllCanali() {

public List<PspChannelPaymentType> getPaymentServiceProvidersChannels() {
log.info("loading PspChannels");
return pspCanaleTipoVersamentoCanaleRepository.findAllFetching().stream()
return pspCanaleTipoVersamentoCanaleRepository
.findAllFetching()
.stream()
.map(
p ->
new PspChannelPaymentType(
Expand Down Expand Up @@ -761,7 +769,8 @@ public List<PspInformation> getInformativePsp(
log.info("loading InformativePsp");

List<CtListaInformativePSP> informativePspSingle =
masters.stream()
masters
.stream()
.filter(
m -> details.stream().anyMatch(d -> d.getFkCdiMaster().getId().equals(m.getId())))
.map(
Expand Down Expand Up @@ -799,7 +808,8 @@ public List<PspInformation> getInformativePsp(
ctInformativaPSP.setIdentificativoFlusso(cdiMaster.getIdInformativaPsp());

List<CtInformativaDetail> masterdetails =
details.stream()
details
.stream()
.filter(d -> d.getFkCdiMaster().getId().equals(cdiMaster.getId()))
.filter(
d ->
Expand All @@ -820,7 +830,8 @@ public List<PspInformation> getInformativePsp(
"".getBytes(StandardCharsets.UTF_8));

List<CdiInformazioniServizio> it =
allInformazioni.stream()
allInformazioni
.stream()
.filter(
ii ->
ii.getFkCdiDetail()
Expand All @@ -847,7 +858,8 @@ public List<PspInformation> getInformativePsp(
}

List<CtFasciaCostoServizio> fasce =
allFasce.stream()
allFasce
.stream()
.filter(
fas ->
fas.getFkCdiDetail()
Expand All @@ -874,15 +886,17 @@ public List<PspInformation> getInformativePsp(
ctListaFasceCostoServizio.getFasciaCostoServizio().addAll(fasce);

List<CdiPreference> cdiPreferenceStream =
preferences.stream()
preferences
.stream()
.filter(
pref ->
pref.getCdiDetail()
.getId()
.equals(cdiDetail.getId()))
.collect(Collectors.toList());
List<String> buyers =
cdiPreferenceStream.stream()
cdiPreferenceStream
.stream()
.map(p -> p.getBuyer())
.collect(Collectors.toList());
CtListaConvenzioni listaConvenzioni = new CtListaConvenzioni();
Expand All @@ -895,7 +909,8 @@ public List<PspInformation> getInformativePsp(
pspCanaleTipoVersamento.getCanale().getIdCanale());

List<Double> costiConvenzione =
cdiPreferenceStream.stream()
cdiPreferenceStream
.stream()
.map(p -> p.getCostoConvenzione() / costoConvenzioneFormat)
.collect(Collectors.toList());

Expand Down Expand Up @@ -958,7 +973,8 @@ public List<PspInformation> getInformativePsp(
CtListaInformativePSP informativaEmpty = new CtListaInformativePSP();

List<PspInformation> informativePspSingleCache =
informativePspSingle.stream()
informativePspSingle
.stream()
.map(
i ->
PspInformation.builder()
Expand Down Expand Up @@ -987,7 +1003,8 @@ public List<PspInformation> getTemplateInformativePsp(List<CdiMasterValid> allMa
psp -> {
try {
Optional<CdiMasterValid> masters =
allMasters.stream()
allMasters
.stream()
.filter(m -> m.getFkPsp().getObjId().equals(psp.getObjId()))
.findFirst();
TplInformativaPSP tplInformativaPSP = new TplInformativaPSP();
Expand Down Expand Up @@ -1120,7 +1137,8 @@ private TplInformativaDetail makeTplInformativaDetail(
}

private List<CtContoAccredito> manageContiAccredito(List<IbanValidiPerPa> ibans) {
return ibans.stream()
return ibans
.stream()
.map(
iban -> {
String idNegozio = null;
Expand Down Expand Up @@ -1176,14 +1194,16 @@ public List<CreditorInstitutionInformation> getInformativePa() {
Boolean.TRUE.equals(pa.getPagamentoPressoPsp()) ? 1 : 0);

List<IbanValidiPerPa> ibans =
allIbans.stream()
allIbans
.stream()
.filter(i -> i.getFkPa().equals(pa.getObjId()))
.collect(Collectors.toList());
List<CtContoAccredito> contiaccredito = manageContiAccredito(ibans);
ctInformativaControparte.getInformativaContoAccredito().addAll(contiaccredito);

List<InformativePaMaster> masters =
allMasters.stream()
allMasters
.stream()
.filter(m -> m.getFkPa().getObjId().equals(pa.getObjId()))
.collect(Collectors.toList());
InformativePaMaster master = null;
Expand All @@ -1200,12 +1220,14 @@ public List<CreditorInstitutionInformation> getInformativePa() {
List<InformativePaDetail> infodetails = master.getDetails();

List<CtErogazione> disponibilita =
infodetails.stream()
infodetails
.stream()
.filter(d -> d.getFlagDisponibilita())
.map(d -> infoDetailToCtErogazione(allFasce, d))
.collect(Collectors.toList());
List<CtErogazione> indisponibilita =
infodetails.stream()
infodetails
.stream()
.filter(d -> !d.getFlagDisponibilita())
.map(d -> infoDetailToCtErogazione(allFasce, d))
.collect(Collectors.toList());
Expand Down Expand Up @@ -1251,7 +1273,8 @@ private CtErogazione infoDetailToCtErogazione(
List<CtFasciaOraria> fasce = new ArrayList<>();
try {
fasce =
allFasce.stream()
allFasce
.stream()
.filter(f -> f.getFkInformativaPaDetail().getId().equals(det.getId()))
.map(
f -> {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ spring.datasource.username=${DB_CONFIG_USER}
spring.datasource.password=${DB_CONFIG_PASSWORD}
spring.datasource.driver-class-name=${DB_CONFIG_DRIVER}
spring.datasource.hikari.maxLifetime=30000
spring.datasource.hikari.keepaliveTime=5000
spring.jpa.show-sql=false
spring.jpa.open-in-view=false
spring.database.id=${DATABASE_ID}
Expand Down Expand Up @@ -57,4 +58,4 @@ cors.configuration=${CORS_CONFIGURATION:{"origins": ["*"], "methods": ["*"]}}
spring.data.redis.repositories.enabled=false
saveDB:${SAVE_DB:false}
canary=${CANARY:false}
in_progress.ttl=${IN_PROGRESS_TTL:15}
in_progress.ttl=${IN_PROGRESS_TTL:15}