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

[PRDP-64] feat: Introducing agents #21

Merged
merged 4 commits into from
Aug 1, 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
13 changes: 12 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ ARG JAVA_VERSION=11
FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-build AS installer-env

COPY . /src/java-function-app
RUN echo $(ls -1 /src/java-function-app)
RUN chmod 777 /src/java-function-app/agent/config.yaml
RUN cd /src/java-function-app && \
wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.19.0/jmx_prometheus_javaagent-0.19.0.jar && \
wget https://search.maven.org/remotecontent?filepath=co/elastic/apm/elastic-apm-agent/1.36.0/elastic-apm-agent-1.36.0.jar && \
mkdir -p /home/site/wwwroot && \
mvn clean package -Dmaven.test.skip=true && \
cd ./target/azure-functions/ && \
cd $(ls -d */|head -n 1) && \
cp -a . /home/site/wwwroot
cp -a . /home/site/wwwroot && \
cp /src/java-function-app/agent/config.yaml /home/site/wwwroot/config.yaml
RUN chmod 777 /src/java-function-app/jmx_prometheus_javaagent-0.19.0.jar && \
cp /src/java-function-app/jmx_prometheus_javaagent-0.19.0.jar /home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar

RUN chmod 777 /src/java-function-app/elastic-apm-agent-1.36.0.jar && \
cp /src/java-function-app/elastic-apm-agent-1.36.0.jar /home/site/wwwroot/elastic-apm-agent-1.36.0.jar

# This image is ssh enabled
#FROM mcr.microsoft.com/azure-functions/java:3.0-java$JAVA_VERSION-appservice
Expand All @@ -19,4 +29,5 @@ ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

EXPOSE 80
EXPOSE 12345
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
2 changes: 2 additions & 0 deletions agent/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rules:
- pattern: ".*"
6 changes: 0 additions & 6 deletions helm/Chart.lock

This file was deleted.

6 changes: 3 additions & 3 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ apiVersion: v2
name: pagopa-functions-template
description: Microservice description
type: application
version: 0.25.0
appVersion: 1.4.3
version: 0.33.0
appVersion: 1.5.0-PRDP-64-feat-add-elk-apm-configurations
dependencies:
- name: microservice-chart
version: 1.21.0
version: 2.4.0
repository: "https://pagopa.github.io/aks-microservice-chart-blueprint"
25 changes: 21 additions & 4 deletions 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: ghcr.io/pagopa/pagopa-pdf-engine
tag: "1.4.3"
tag: "1.5.0-PRDP-64-feat-add-elk-apm-configurations"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand All @@ -23,14 +23,25 @@ microservice-chart:
periodSeconds: 10
deployment:
create: true
service:
serviceMonitor:
create: true
endpoints:
- interval: 10s #jmx-exporter
targetPort: 12345
path: /metrics
ports:
- 80 #http
- 12345 #jmx-exporter
service:
type: ClusterIP
port: 80
ports:
- 80 #http
- 12345 #jmx-exporter
ingress:
create: true
host: "weudev.shared.internal.dev.platform.pagopa.it"
path: /pagopa-pdf-engine/(.*)
servicePort: 80
serviceAccount:
create: false
annotations: {}
Expand Down Expand Up @@ -64,8 +75,14 @@ microservice-chart:
WEBSITE_SITE_NAME: "pagopapdfengine" # required to show cloud role name in application insights
FUNCTIONS_WORKER_RUNTIME: "java"
HTML_TEMPLATE_FILE_NAME: "template"
ELASTIC_APM_SERVICE_NAME: "pagopapdfengine"
ELASTIC_APM_APPLICATION_PACKAGES: "it.gov.pagopa.pdf.engine"
ELASTIC_APM_SERVER_URL: "http://quickstart-apm-http.elastic-system.svc:8200"
ELASTIC_APM_LOG_SENDING: 'true'
JAVA_TOOL_OPTIONS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/elastic-apm-agent-1.36.0.jar"
envSecret:
APPLICATIONINSIGHTS_CONNECTION_STRING: 'ai-d-connection-string'
ELASTIC_APM_SECRET_TOKEN: 'elastic-apm-secret-token'
keyvault:
name: "pagopa-d-shared-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
Expand Down Expand Up @@ -95,7 +112,7 @@ microservice-chart:
create: true
image:
repository: ghcr.io/pagopa/pagopa-pdf-engine
tag: "1.4.3"
tag: "1.5.0-PRDP-64-feat-add-elk-apm-configurations"
pullPolicy: Always
envConfig:
envSecret:
25 changes: 21 additions & 4 deletions 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: ghcr.io/pagopa/pagopa-pdf-engine
tag: "1.4.3"
tag: "1.5.0-PRDP-64-feat-add-elk-apm-configurations"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand All @@ -23,14 +23,25 @@ microservice-chart:
periodSeconds: 10
deployment:
create: true
service:
serviceMonitor:
create: true
endpoints:
- interval: 10s #jmx-exporter
targetPort: 12345
path: /metrics
ports:
- 80 #http
- 12345 #jmx-exporter
service:
type: ClusterIP
port: 80
ports:
- 80 #http
- 12345 #jmx-exporter
ingress:
create: true
host: "weuprod.shared.internal.platform.pagopa.it"
path: /pagopa-pdf-engine/(.*)
servicePort: 80
serviceAccount:
create: false
annotations: {}
Expand Down Expand Up @@ -64,8 +75,14 @@ microservice-chart:
WEBSITE_SITE_NAME: "pagopapdfengine" # required to show cloud role name in application insights
FUNCTIONS_WORKER_RUNTIME: "java"
HTML_TEMPLATE_FILE_NAME: "template"
ELASTIC_APM_SERVICE_NAME: "pagopapdfengine"
ELASTIC_APM_APPLICATION_PACKAGES: "it.gov.pagopa.pdf.engine"
ELASTIC_APM_SERVER_URL: "http://quickstart-apm-http.elastic-system.svc:8200"
ELASTIC_APM_LOG_SENDING: "true"
JAVA_TOOL_OPTIONS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/elastic-apm-agent-1.36.0.jar"
envSecret:
APPLICATIONINSIGHTS_CONNECTION_STRING: 'ai-p-connection-string'
ELASTIC_APM_SECRET_TOKEN: 'elastic-apm-secret-token'
keyvault:
name: "pagopa-p-shared-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
Expand Down Expand Up @@ -95,7 +112,7 @@ microservice-chart:
create: true
image:
repository: ghcr.io/pagopa/pagopa-pdf-engine
tag: "1.4.3"
tag: "1.5.0-PRDP-64-feat-add-elk-apm-configurations"
pullPolicy: Always
envConfig:
envSecret:
25 changes: 21 additions & 4 deletions 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: ghcr.io/pagopa/pagopa-pdf-engine
tag: "1.4.3"
tag: "1.5.0-PRDP-64-feat-add-elk-apm-configurations"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand All @@ -23,14 +23,25 @@ microservice-chart:
periodSeconds: 10
deployment:
create: true
service:
serviceMonitor:
create: true
endpoints:
- interval: 10s #jmx-exporter
targetPort: 12345
path: /metrics
ports:
- 80 #http
- 12345 #jmx-exporter
service:
type: ClusterIP
port: 80
ports:
- 80 #http
- 12345 #jmx-exporter
ingress:
create: true
host: "weuuat.shared.internal.uat.platform.pagopa.it"
path: /pagopa-pdf-engine/(.*)
servicePort: 80
serviceAccount:
create: false
annotations: {}
Expand Down Expand Up @@ -64,8 +75,14 @@ microservice-chart:
WEBSITE_SITE_NAME: "pagopapdfengine" # required to show cloud role name in application insights
FUNCTIONS_WORKER_RUNTIME: "java"
HTML_TEMPLATE_FILE_NAME: "template"
ELASTIC_APM_SERVICE_NAME: "pagopapdfengine"
ELASTIC_APM_APPLICATION_PACKAGES: "it.gov.pagopa.pdf.engine"
ELASTIC_APM_SERVER_URL: "http://quickstart-apm-http.elastic-system.svc:8200"
ELASTIC_APM_LOG_SENDING: "true"
JAVA_TOOL_OPTIONS: "-javaagent:/home/site/wwwroot/jmx_prometheus_javaagent-0.19.0.jar=12345:/home/site/wwwroot/config.yaml -javaagent:/home/site/wwwroot/elastic-apm-agent-1.36.0.jar"
envSecret:
APPLICATIONINSIGHTS_CONNECTION_STRING: 'ai-u-connection-string'
ELASTIC_APM_SECRET_TOKEN: 'elastic-apm-secret-token'
keyvault:
name: "pagopa-u-shared-kv"
tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d"
Expand Down Expand Up @@ -95,7 +112,7 @@ microservice-chart:
create: true
image:
repository: ghcr.io/pagopa/pagopa-pdf-engine
tag: "1.4.3"
tag: "1.5.0-PRDP-64-feat-add-elk-apm-configurations"
pullPolicy: Always
envConfig:
envSecret:
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition - PDF Engine",
"version": "1.4.3"
"version": "1.5.0-PRDP-64-feat-add-elk-apm-configurations"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>it.gov.pagopa</groupId>
<artifactId>pdf-engine</artifactId>
<version>1.4.3</version>
<version>1.5.0-PRDP-64-feat-add-elk-apm-configurations</version>
<packaging>jar</packaging>

<name>pagopa-pdf-engine</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
If not, see https://www.gnu.org/licenses/.
*/

package it.gov.pagopa.project;
package it.gov.pagopa.pdf.engine;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jknack.handlebars.Handlebars;
Expand All @@ -23,15 +23,15 @@
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
import it.gov.pagopa.project.exception.PDFEngineException;
import it.gov.pagopa.project.model.AppErrorCodeEnum;
import it.gov.pagopa.project.model.ErrorMessage;
import it.gov.pagopa.project.model.ErrorResponse;
import it.gov.pagopa.project.model.GeneratePDFInput;
import it.gov.pagopa.project.service.GeneratePDFService;
import it.gov.pagopa.project.service.ParseRequestBodyService;
import it.gov.pagopa.project.service.impl.GeneratePDFServiceImpl;
import it.gov.pagopa.project.service.impl.ParseRequestBodyServiceImpl;
import it.gov.pagopa.pdf.engine.exception.PDFEngineException;
import it.gov.pagopa.pdf.engine.model.AppErrorCodeEnum;
import it.gov.pagopa.pdf.engine.model.ErrorMessage;
import it.gov.pagopa.pdf.engine.model.ErrorResponse;
import it.gov.pagopa.pdf.engine.model.GeneratePDFInput;
import it.gov.pagopa.pdf.engine.service.GeneratePDFService;
import it.gov.pagopa.pdf.engine.service.ParseRequestBodyService;
import it.gov.pagopa.pdf.engine.service.impl.GeneratePDFServiceImpl;
import it.gov.pagopa.pdf.engine.service.impl.ParseRequestBodyServiceImpl;
import org.apache.commons.io.FileUtils;

import java.io.BufferedInputStream;
Expand All @@ -50,7 +50,6 @@

import static com.microsoft.azure.functions.HttpStatus.BAD_REQUEST;
import static com.microsoft.azure.functions.HttpStatus.INTERNAL_SERVER_ERROR;
import static it.gov.pagopa.project.model.AppErrorCodeEnum.*;

/**
* Azure Functions with HTTP Trigger.
Expand Down Expand Up @@ -98,7 +97,7 @@ public HttpResponseMessage run(
logger.severe("Invalid request the payload is null");
return request
.createResponseBuilder(BAD_REQUEST)
.body(buildResponseBody(BAD_REQUEST, PDFE_899, INVALID_REQUEST_MESSAGE))
.body(buildResponseBody(BAD_REQUEST, AppErrorCodeEnum.PDFE_899, INVALID_REQUEST_MESSAGE))
.build();
}

Expand All @@ -112,13 +111,13 @@ public HttpResponseMessage run(
.format(Instant.now())
);
} catch (IOException e) {
logger.log(Level.SEVERE, PDFE_908.getErrorMessage(), e);
logger.log(Level.SEVERE, AppErrorCodeEnum.PDFE_908.getErrorMessage(), e);
return request
.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR)
.body(
buildResponseBody(
INTERNAL_SERVER_ERROR,
PDFE_908,
AppErrorCodeEnum.PDFE_908,
"An error occurred on processing the request"))
.build();
}
Expand All @@ -140,15 +139,15 @@ public HttpResponseMessage run(
logger.severe("Invalid request, template HTML not provided");
return request
.createResponseBuilder(BAD_REQUEST)
.body(buildResponseBody(BAD_REQUEST, PDFE_897, INVALID_REQUEST_MESSAGE))
.body(buildResponseBody(BAD_REQUEST, AppErrorCodeEnum.PDFE_897, INVALID_REQUEST_MESSAGE))
.build();
}

if (generatePDFInput.getData() == null) {
logger.severe("Invalid request the PDF document input data are null");
return request
.createResponseBuilder(BAD_REQUEST)
.body(buildResponseBody(BAD_REQUEST, PDFE_898, INVALID_REQUEST_MESSAGE))
.body(buildResponseBody(BAD_REQUEST, AppErrorCodeEnum.PDFE_898, INVALID_REQUEST_MESSAGE))
.build();
}

Expand Down Expand Up @@ -178,7 +177,7 @@ public HttpResponseMessage run(
.body(
buildResponseBody(
INTERNAL_SERVER_ERROR,
PDFE_907,
AppErrorCodeEnum.PDFE_907,
ERROR_GENERATING_PDF_MESSAGE))
.build();
} finally {
Expand All @@ -190,7 +189,7 @@ public HttpResponseMessage run(

private static HttpStatus getHttpStatus(PDFEngineException e) {
HttpStatus status;
if (e.getErrorCode().equals(PDFE_703) || e.getErrorCode().equals(PDFE_704) || e.getErrorCode().equals(PDFE_705)) {
if (e.getErrorCode().equals(AppErrorCodeEnum.PDFE_703) || e.getErrorCode().equals(AppErrorCodeEnum.PDFE_704) || e.getErrorCode().equals(AppErrorCodeEnum.PDFE_705)) {
status = INTERNAL_SERVER_ERROR;
} else {
status = BAD_REQUEST;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.project;
package it.gov.pagopa.pdf.engine;

import com.microsoft.azure.functions.*;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
If not, see https://www.gnu.org/licenses/.
*/

package it.gov.pagopa.project.exception;
package it.gov.pagopa.pdf.engine.exception;

import it.gov.pagopa.project.model.AppErrorCodeEnum;
import it.gov.pagopa.pdf.engine.model.AppErrorCodeEnum;

/**
* Thrown in case of problems when compiling the HTML template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
If not, see https://www.gnu.org/licenses/.
*/

package it.gov.pagopa.project.exception;
package it.gov.pagopa.pdf.engine.exception;

import it.gov.pagopa.project.model.AppErrorCodeEnum;
import it.gov.pagopa.pdf.engine.model.AppErrorCodeEnum;

/**
* Thrown in case of problems when filling the HTML template
Expand Down
Loading