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

update for check performance #36

Merged
merged 49 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5fc2b1d
update for check performance
Oct 11, 2022
82d8be4
Bump version [skip ci]
Oct 11, 2022
b23dac3
fix docker file
pasqualespica Oct 11, 2022
efa7cc3
Bump version [skip ci]
Oct 11, 2022
c0c2f20
fix docker file cfg
pasqualespica Oct 11, 2022
7b4ae80
Bump version [skip ci]
Oct 11, 2022
c7723cc
increase connections for request
Oct 11, 2022
0115f7c
Merge branch 'fix_performance' of https://github.com/pagopa/pagopa-sp…
Oct 11, 2022
4f5ef4a
Bump version [skip ci]
Oct 11, 2022
5e51b0c
Merge branch 'fix_performance' of
Oct 11, 2022
5fbdaf5
Merge branch 'fix_performance' of https://github.com/pagopa/pagopa-sp…
Oct 11, 2022
2b13dc4
Bump version [skip ci]
Oct 11, 2022
8426012
Bump version [skip ci]
Oct 11, 2022
8c613bc
Merge branch 'fix_performance' of
Oct 11, 2022
b596913
Merge branch 'fix_performance' of https://github.com/pagopa/pagopa-sp…
Oct 11, 2022
a830a03
Bump version [skip ci]
Oct 11, 2022
04c6b51
Merge branch 'fix_performance' of
Oct 11, 2022
f05e715
Bump version [skip ci]
Oct 11, 2022
e79a517
removed iuv gen call
Oct 11, 2022
4b988f4
Bump version [skip ci]
Oct 11, 2022
8ecf5ea
Bump version [skip ci]
Oct 11, 2022
06a8127
fix#1
pasqualespica Oct 11, 2022
fc5247a
Bump version [skip ci]
Oct 11, 2022
b3ea5f7
fix#2
pasqualespica Oct 11, 2022
e135444
Bump version [skip ci]
Oct 11, 2022
0d016a6
fix#3
pasqualespica Oct 11, 2022
ca0af90
Bump version [skip ci]
Oct 11, 2022
6c540a6
fix#4
pasqualespica Oct 11, 2022
96a361d
Bump version [skip ci]
Oct 11, 2022
3fe9313
fix#7
pasqualespica Oct 11, 2022
a13c98d
Bump version [skip ci]
Oct 11, 2022
453da87
fix#8
pasqualespica Oct 11, 2022
b8cd193
Bump version [skip ci]
Oct 11, 2022
5af76d1
fix#9
pasqualespica Oct 12, 2022
eadcc89
Bump version [skip ci]
Oct 12, 2022
b2fa57e
fix#10
pasqualespica Oct 12, 2022
6e69789
Bump version [skip ci]
Oct 12, 2022
7debdbb
fix#11
pasqualespica Oct 12, 2022
8e072f2
Bump version [skip ci]
Oct 12, 2022
4d93a47
fix10
pasqualespica Oct 12, 2022
c796935
Bump version [skip ci]
Oct 12, 2022
ccb3eed
fix11
pasqualespica Oct 12, 2022
0dbb37a
Bump version [skip ci]
Oct 12, 2022
437db43
fix
Oct 14, 2022
c23f99b
fix
Oct 14, 2022
d0e8983
Merge branch 'fix_performance' of https://github.com/pagopa/pagopa-sp…
Oct 14, 2022
a4b2c6d
Bump version [skip ci]
Oct 14, 2022
3a9c6c6
fix helm dev prod
pasqualespica Oct 16, 2022
387cc4c
Bump version [skip ci]
Oct 16, 2022
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
24 changes: 11 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
FROM adoptopenjdk/openjdk11:alpine-jre as builder

ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract
#
# Build
#
FROM maven:3.8.4-jdk-11-slim as buildtime
WORKDIR /build
COPY . .
RUN mvn clean package -Dmaven.test.skip=true

FROM adoptopenjdk/openjdk11:alpine-jre

RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
FROM adoptopenjdk/openjdk11:alpine-jre as builder
COPY --from=buildtime /build/target/*.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

ADD --chown=spring:spring https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.1.1/applicationinsights-agent-3.1.1.jar /applicationinsights-agent.jar
COPY --chown=spring:spring docker/applicationinsights.json ./applicationinsights.json

FROM ghcr.io/pagopa/docker-base-springboot-openjdk11:v1.0.1@sha256:bbbe948e91efa0a3e66d8f308047ec255f64898e7f9250bdb63985efd3a95dbf
COPY --chown=spring:spring --from=builder dependencies/ ./
COPY --chown=spring:spring --from=builder snapshot-dependencies/ ./
# https://github.com/moby/moby/issues/37965#issuecomment-426853382
Expand All @@ -20,6 +21,3 @@ COPY --chown=spring:spring --from=builder spring-boot-loader/ ./
COPY --chown=spring:spring --from=builder application/ ./

EXPOSE 8080

COPY --chown=spring:spring docker/run.sh ./run.sh
ENTRYPOINT ["./run.sh"]
10 changes: 5 additions & 5 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ apiVersion: v2
name: pagopa-spontaneous-payments
description: Microservice that handles spontaneous payments for pagoPA
type: application
version: 1.0.0
appVersion: 1.0.0
version: 0.1.0-22
appVersion: 0.1.0-22
dependencies:
- name: microservice-chart
version: 1.21.0
repository: "https://pagopa.github.io/aks-microservice-chart-blueprint"
- name: microservice-chart
version: 1.21.0
repository: "https://pagopa.github.io/aks-microservice-chart-blueprint"
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: pagopadcommonacr.azurecr.io/pagopaspontaneouspayments
tag: "0.1.0" #improve
tag: "0.1.0-22" #improve
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: pagopapcommonacr.azurecr.io/pagopaspontaneouspayments
tag: "0.1.0" #improve
tag: "0.1.0-22" #improve
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: pagopaucommonacr.azurecr.io/pagopaspontaneouspayments
tag: "0.1.0" #improve
tag: "0.1.0-22" #improve
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
82 changes: 41 additions & 41 deletions load-test/src/create_spontaneous_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SharedArray } from 'k6/data';

import { generateFakeFiscalCode, randomString } from './modules/helpers.js';

import { createCreditorInstitutionEnrollment, getCiCode} from "./modules/gps_client.js";
import { createCreditorInstitutionEnrollment } from "./modules/gps_client.js";

export let options = JSON.parse(open(__ENV.TEST_TYPE));

Expand All @@ -22,48 +22,48 @@ const gpdUrlBasePath = `${vars.gpdBaseUrl}`;

const creditor_institution_code = `organizationNew`;

//export function setup() {
// // 2. setup code (once)
// // The setup code runs, setting up the test environment (optional) and generating data
// // used to reuse code for the same VU
// const params = {
// headers: {
// 'Content-Type': 'application/json'
// },
// };
// const response = createCreditorInstitutionEnrollment(rootUrl, params, creditor_institution_code);
//
// console.log(`setup ... ${response.status}`);
//
//// check(response, {
//// "status is 201 or 409": (response) => (response.status === 201 || response.status === 409),
//// });
//
// // precondition is moved to default fn because in this stage
// // __VU is always 0 and cannot be used to create env properly
//}
export function setup() {
// 2. setup code (once)
// The setup code runs, setting up the test environment (optional) and generating data
// used to reuse code for the same VU
const params = {
headers: {
'Content-Type': 'application/json'
},
};
const response = createCreditorInstitutionEnrollment(rootUrl, params, creditor_institution_code);

console.log(`setup ... ${response.status}`);

check(response, {
"status is 201 or 409": (res) => (res.status === 201 || res.status === 409),
});

// precondition is moved to default fn because in this stage
// __VU is always 0 and cannot be used to create env properly
}

function precondition() {
// no pre conditions
}

//function postcondition(iupd, params) {
//
// // Delete the newly created debt position.
// let tag = {
// gpdMethod: "DeleteDebtPosition",
// };
//
// let url = `${gpdUrlBasePath}/organizations/${creditor_institution_code}/debtpositions/${iupd}`;
//
// let r = http.del(url, params);
//
// console.log("DeleteDebtPosition call - creditor_institution_code " + creditor_institution_code + ", iupd " + iupd + ", Status " + r.status);
//
// check(r, {
// "DeleteDebtPosition status is 200": (_r) => r.status === 200,
// }, tag);
//}
function postcondition(iupd, params) {

// Delete the newly created debt position.
let tag = {
gpdMethod: "DeleteDebtPosition",
};

let url = `${gpdUrlBasePath}/organizations/${creditor_institution_code}/debtpositions/${iupd}`;

let r = http.del(url, params);

console.log("DeleteDebtPosition call - creditor_institution_code " + creditor_institution_code + ", iupd " + iupd + ", Status " + r.status);

check(r, {
"DeleteDebtPosition status is 200": (_r) => r.status === 200,
}, tag);
}

export default function() {

Expand Down Expand Up @@ -125,9 +125,9 @@ export default function() {
}, tag);

// If flag delete_debt_position is set to true the debit position is deleted after being created
// if (r.status === 201 && delete_debt_position === "true") {
// postcondition(r.json().iupd, params);
// }
if (r.status === 201 && delete_debt_position === "true") {
postcondition(r.json().iupd, params);
}


}
2 changes: 1 addition & 1 deletion load-test/src/local.environment.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"environment": [
{
"env": "local",
"host": "http://localhost:55397",
"host": "https://api.dev.platform.pagopa.it/gps/spontaneous-payments-service/v1",
"basePath": "organizations",
"gpdBaseUrl": "https://api.dev.platform.pagopa.it/gpd/api/v1",
"deleteDebtPosition": true
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": "PagoPA API Spontaneous Payment",
"description": "Progetto Gestione Pagamenti Spontanei",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "0.1.0-1"
"version": "0.1.0-22"
},
"servers": [
{
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>it.gov.pagopa</groupId>
<artifactId>spontaneouspayment</artifactId>
<version>0.1.0-1</version>
<version>0.1.0-22</version>
<name>Gestione Pagamenti Spontanei</name>
<description>Progetto Gestione Pagamenti Spontanei</description>

Expand All @@ -22,7 +22,7 @@
<testcontainers.version>1.17.2</testcontainers.version>
<springfox-version>3.0.0</springfox-version>
<springdoc-version>1.6.9</springdoc-version>
<cosmos-data-version>3.21.0</cosmos-data-version>
<cosmos-data-version>3.28.1</cosmos-data-version>
<openfeign-version>3.1.3</openfeign-version>
<modelmapper-version>3.1.0</modelmapper-version>
<json.version>20220320</json.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.azure.core.credential.AzureKeyCredential;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.cosmos.DirectConnectionConfig;
import com.azure.cosmos.GatewayConnectionConfig;
import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration;
import com.azure.spring.data.cosmos.config.CosmosConfig;
import com.azure.spring.data.cosmos.core.ResponseDiagnostics;
Expand Down Expand Up @@ -42,11 +41,10 @@ public class CosmosDBConfiguration extends AbstractCosmosConfiguration {
CosmosClientBuilder getCosmosClientBuilder() {
AzureKeyCredential azureKeyCredential = new AzureKeyCredential(key);
DirectConnectionConfig directConnectionConfig = new DirectConnectionConfig();
GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
return new CosmosClientBuilder()
.endpoint(uri)
.credential(azureKeyCredential)
.directMode(directConnectionConfig, gatewayConnectionConfig);
.directMode(directConnectionConfig);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
Object result = joinPoint.proceed();
long endTime = System.currentTimeMillis();
log.trace("Time taken for Execution of {} is: {}ms", joinPoint.getSignature().toShortString(), (endTime - startTime));
log.info("Time taken for Execution of {} is: {}ms", joinPoint.getSignature().toShortString(), (endTime - startTime));
return result;
}

@Around(value = "repository() || service()")
public Object logTrace(ProceedingJoinPoint joinPoint) throws Throwable {
log.debug("Call method {} - args: {}", joinPoint.getSignature().toShortString(), joinPoint.getArgs());
log.info("Call method {} - args: {}", joinPoint.getSignature().toShortString(), joinPoint.getArgs());
Object result = joinPoint.proceed();
log.debug("Return method {} - result: {}", joinPoint.getSignature().toShortString(), result);
log.info("Return method {} - result: {}", joinPoint.getSignature().toShortString(), result);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.time.LocalDateTime;
import java.util.List;

@Container(containerName = "${azure.cosmos.ec-container-name}", autoCreateContainer = false)
@Container(containerName = "${azure.cosmos.ec-container-name}", autoCreateContainer = false, ru="1000")
@Getter
@Setter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.time.LocalDateTime;
import java.util.List;

@Container(containerName = "${azure.cosmos.service-container-name}", autoCreateContainer = false)
@Container(containerName = "${azure.cosmos.service-container-name}", autoCreateContainer = false, ru="1000")
@Getter
@Setter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import it.gov.pagopa.spontaneouspayment.model.ServicePropertyModel;
import it.gov.pagopa.spontaneouspayment.model.SpontaneousPaymentModel;
import it.gov.pagopa.spontaneouspayment.model.enumeration.PropertyType;
import it.gov.pagopa.spontaneouspayment.model.enumeration.Status;
import it.gov.pagopa.spontaneouspayment.model.response.PaymentOptionModel;
import it.gov.pagopa.spontaneouspayment.model.response.PaymentPositionModel;
import it.gov.pagopa.spontaneouspayment.model.response.TransferModel;
Expand All @@ -35,7 +36,6 @@
import it.gov.pagopa.spontaneouspayment.service.client.ExternalServiceClient;
import it.gov.pagopa.spontaneouspayment.service.client.GpdClient;
import it.gov.pagopa.spontaneouspayment.service.client.IuvGeneratorClient;
import it.gov.pagopa.spontaneouspayment.model.enumeration.Status;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -79,14 +79,16 @@ public PaymentPositionModel createSpontaneousPayment(@NotBlank String organizati
var serviceConfiguration = getServiceDetails(spontaneousPayment.getService());

// check if the relationship between organization and enrollment to service exists
checkServiceOrganization(organizationFiscalCode, serviceConfiguration);
checkServiceOrganization(orgConfiguration, serviceConfiguration);

// checks if the service is in suitable state and the request contains the properties required by the configured service
checkServiceConfiguration(spontaneousPayment, serviceConfiguration);

return createDebtPosition(organizationFiscalCode, orgConfiguration, serviceConfiguration, spontaneousPayment);

}


/**
* check if the credit institution's status is ENABLED
*
Expand Down Expand Up @@ -143,10 +145,10 @@ private PaymentPositionModel createDebtPosition(String organizationFiscalCode,
.filter(e -> e.getServiceId().equals(serviceConfiguration.getId()))
.findAny()
.orElseThrow(() -> new AppException(AppError.ENROLLMENT_TO_SERVICE_NOT_FOUND, serviceConfiguration.getId(), organizationFiscalCode));

// call the external service to get the PO
PaymentOptionModel po = this.callExternalService(spontaneousPayment, serviceConfiguration);

// generate IUV
String iuv = this.callIuvGeneratorService(organizationFiscalCode, enrollment);

Expand All @@ -158,14 +160,13 @@ private PaymentPositionModel createDebtPosition(String organizationFiscalCode,
transfer.setCategory(serviceConfiguration.getTransferCategory());
transfer.setIban(enrollment.getIban());
transfer.setPostalIban(enrollment.getPostalIban());

// Payment Position to create
PaymentPositionModel pp = modelMapper.map(spontaneousPayment.getDebtor(), PaymentPositionModel.class);
pp.setIupd(iupdPrefix + iuv);
pp.setCompanyName(orgConfiguration.getCompanyName());
pp.addPaymentOptions(po);



return gpdClient.createDebtPosition(organizationFiscalCode, pp);
}

Expand Down Expand Up @@ -199,12 +200,13 @@ private String callIuvGeneratorService(String organizationFiscalCode, ServiceRef
return Optional.ofNullable(iuvObj).orElseThrow(() -> new AppException(AppError.IUV_ACQUISITION_ERROR, organizationFiscalCode, auxDigit, segregationCode)).getIuv();
}

private void checkServiceOrganization(@NotBlank String organizationFiscalCode,
@NotNull it.gov.pagopa.spontaneouspayment.entity.Service service) {
var org = orgRepository.getCreditInstitutionByOrgFiscCodeAndServiceId(organizationFiscalCode, service.getId());
if (org.isEmpty()) {
throw new AppException(AppError.ORGANIZATION_SERVICE_NOT_FOUND, organizationFiscalCode, service.getId());
}

private void checkServiceOrganization(@NotNull Organization organization,
@NotNull it.gov.pagopa.spontaneouspayment.entity.Service service) {
Optional<ServiceRef> enrollment = organization.getEnrollments().stream().filter(e -> e.getServiceId().equals(service.getId())).findAny();
if (enrollment.isEmpty()) {
throw new AppException(AppError.ORGANIZATION_SERVICE_NOT_FOUND, organization.getFiscalCode(), service.getId());
}
}

private it.gov.pagopa.spontaneouspayment.entity.Service getServiceDetails(@NotNull ServiceModel service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import feign.FeignException;
Expand All @@ -18,7 +18,7 @@ public interface IuvGeneratorClient {

@Retryable(exclude = FeignException.FeignClientException.class, maxAttemptsExpression = "${retry.iuv-generator.maxAttempts}",
backoff = @Backoff(delayExpression = "${retry.iuv-generator.maxDelay}"))
@GetMapping(value = "/organizations/{organizationfiscalcode}/iuv")
@PostMapping(value = "/organizations/{organizationfiscalcode}/iuv")
IuvGenerationModelResponse generateIUV(@PathVariable("organizationfiscalcode") String organizationFiscalCode,
@RequestBody IuvGenerationModel paymentPositionModel);

Expand Down