Skip to content

Case Study - Pdf Comparison (Java 21, Spring Boot, JUnit, Jacoco, Prometheus,Grafana, AlertManager, Docker, Kubernetes, Github Action (CI/CD), Test Container)

Notifications You must be signed in to change notification settings

Rapter1990/pdfcompare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Case Study - PDF Comparison

Main Information

📖 Information

  • This project provides a Spring Boot API for PDF Comparison, allowing users to compare two PDF documents and download a resulting comparison report in PDF format.
  • PDF Comparison API:
    • Endpoint: /api/v1/pdf/compare
    • HTTP Method: POST
    • Consumes: multipart/form-data
    • Parameters:
      • file1: First PDF file (required)
      • file2: Second PDF file (required)
      • isMultiple: Boolean flag (optional, default is false) indicating whether to perform multiple comparisons.
    • Response: Returns a PDF file (comparison.pdf) containing the comparison results.
    • Example Request:
      • POST /api/v1/pdf/compare with two PDF files and an optional isMultiple flag.
    • Implementation Details:
      • Utilizes a dedicated PDFComparisonService to process and compare the contents of the uploaded PDF files.
      • The service generates a comparison report as a PDF document, highlighting differences and similarities.
      • Errors during the comparison process are managed via exception handling, ensuring reliable API responses.
    • Downloadable Output:
      • The response sets Content-Type to application/pdf and uses Content-Disposition to prompt the download of the file named comparison.pdf.

    Explore Rest APIs

    Endpoints Summary

    Method Url Description Request Body Path Variable Response
    POST /api/v1/pdf/compare Compare two PDF files and return a comparison report
    • file1: First PDF file (required)
    • file2: Second PDF file (required)
    • isMultiple: Boolean flag (optional, default is false)
    None PDF file (comparison.pdf)

    Technologies


    • Java 21
    • Spring Boot 3.0
    • Restful API
    • Open Api (Swagger)
    • Maven
    • Junit5
    • Mockito
    • Integration Tests
    • Docker
    • Docker Compose
    • CI/CD (Github Actions)
    • Postman
    • Prometheus
    • Grafana
    • Kubernetes
    • JaCoCo (Test Report)
    • Alert Manager

    Postman

    Import postman collection under postman_collection folder
    

    Prerequisites

    Define Variable in .env file

    GF_SMTP_ENABLED=true
    GF_SMTP_HOST=smtp.gmail.com:587
    GF_SMTP_USER={your_gmail_email}
    GF_SMTP_PASSWORD={gmail_authentication_password}
    GF_SMTP_SKIP_VERIFY=true
    GF_SMTP_FROM_ADDRESS={your_gmail_email}
    
    
    ALERT_RESOLVE_TIMEOUT=5m
    SMTP_SMARTHOST=smtp.gmail.com:587
    SMTP_FROM={your_gmail_email}
    SMTP_AUTH_USERNAME={your_gmail_email}
    SMTP_AUTH_PASSWORD={gmail_authentication_password}
    SMTP_REQUIRE_TLS=true
    ALERT_EMAIL_TO={your_gmail_email}
    

    Open Api (Swagger)

    http://localhost:3333/swagger-ui/index.html
    

    JaCoCo (Test Report)

    After the command named mvn clean install completes, the JaCoCo report will be available at:

    target/site/jacoco/index.html
    

    Navigate to the target/site/jacoco/ directory.

    Open the index.html file in your browser to view the detailed coverage report.


    Maven, Docker and Kubernetes Running Process

    Maven Run

    To build and run the application with Maven, please follow the directions shown below;

    $ cd pdfcompare
    $ mvn clean install
    $ mvn spring-boot:run

    Docker Run

    The application can be built and run by the Docker engine. The Dockerfile has multistage build, so you do not need to build and run separately.

    Please follow directions shown below in order to build and run the application with Docker Compose file;

    $ cd pdfcompare
    $ docker-compose up -d

    If you change anything in the project and run it on Docker, you can also use this command shown below

    $ cd pdfcompare
    $ docker-compose up --build

    To monitor the application, you can use the following tools:

    • Prometheus:
      Open in your browser at http://localhost:9090
      Prometheus collects and stores application metrics.

      Alert is alrealdy defined in Alert tab

    • Grafana:
      Open in your browser at http://localhost:3000
      Grafana provides a dashboard for visualizing the metrics.
      Default credentials:

      • Username: admin
      • Password: admin
    • AlertManager:
      Open in your browser at http://localhost:9093

    Define prometheus data source url, use this link shown below

    http://prometheus:9090
    

    Define alertManager data source url, use this link shown below

    http://alertmanager:9093
    

    Kubernetes Run

    To build and run the application with Maven, please follow the directions shown below;

    • Start Minikube
    $ minikube start
    • Open Minikube Dashboard
    $ minikube dashboard
    • To deploy the application on Kubernetes, apply the Kubernetes configuration file underneath k8s folder
    $ kubectl apply -f k8s
    • To open Prometheus, click tunnel url link provided by the command shown below to reach out Prometheus
    minikube service prometheus-service
    • To open Grafana, click tunnel url link provided by the command shown below to reach out Prometheus
    minikube service grafana-service
    • To open AlertManager, click tunnel url link provided by the command shown below to reach out Prometheus
    minikube service alertmanager-service
    • Define prometheus data source url, use this link shown below
    http://prometheus-service.default.svc.cluster.local:9090
    
    • Define alertmanager data source url, use this link shown below
    http://alertmanager-service.default.svc.cluster.local:9093
    

    Define Alert through Grafana

    • Go to localhost:9093 for Docker and Go there through minikube service alertmanager-service for Kubernetes
    • Define Your Gmail address for Contract Point and determine if test mail is send to its email
    • After define jvm micrometer dashboard in Grafana with its id 4701, click Heap Used Panel edit and More -> New Alert Rules
    • Define Threshold as input assigning to A with IS ABOVE as 1.8
    • Create a new folder names for 3. Add folder and labels and 4. Set evaluation behaviour
    • Define Contract Points for your defined email in 5. Configure notification
    • After reaching the threshold value, it triggers to send an alert notification to your defined mail

    Alert Manager

    • Pre-configured Alert Rules:
      • The alert is pre-defined in the rule file within Prometheus, streamlining your monitoring setup
    • Threshold-based Trigger:
      • Once any metric exceeds its designated threshold, the alert is automatically activated
    • Instant Email Notifications:
      • Upon triggering, Alert Manager sends an immediate email notification to your defined email, keeping you informed in real time

    Docker Image Location

    https://hub.docker.com/repository/docker/noyandocker/pdfcompare/general
    

    Screenshots

    Click here to show the screenshots of project

    Figure 1

    Figure 2

    Figure 3

    Figure 4

    Figure 5

    Figure 6

    Figure 7

    Figure 8

    Figure 9

    Figure 10

    Figure 11

    Figure 12

    Figure 13

    Figure 14

    Figure 15

    Figure 16

    Figure 17

    Figure 18

    Figure 19

    Figure 20

    Figure 21

    Figure 22

    Figure 23

    Figure 24

    Figure 25

    Figure 26

    Figure 27

    Figure 28

    Figure 29

    Figure 30

    Figure 31

    Figure 32

    Figure 33

    Figure 34

    Figure 35

    Figure 36

    Figure 37

    Figure 38

    Figure 39

    Figure 40

    Contributors

About

Case Study - Pdf Comparison (Java 21, Spring Boot, JUnit, Jacoco, Prometheus,Grafana, AlertManager, Docker, Kubernetes, Github Action (CI/CD), Test Container)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published