Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Created by https://www.toptal.com/developers/gitignore/api/macos,gradle,java,intellij
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,gradle,java,intellij

# Excalidraw source files (export to PNG for the repo instead)
*.excalidraw

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM eclipse-temurin:17-jdk AS build
WORKDIR /app

COPY gradlew .
COPY gradle gradle
COPY build.gradle settings.gradle ./
RUN ./gradlew dependencies --no-daemon || return 0

COPY src src
RUN ./gradlew bootJar --no-daemon -x test

FROM eclipse-temurin:17-jre AS run
WORKDIR /app
COPY --from=build /app/build/libs/*.jar chalkak.jar

ENTRYPOINT ["java", "-jar", "chalkak.jar"]
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'com.querydsl:querydsl-jpa:5.1.0:jakarta'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
Expand Down
66 changes: 66 additions & 0 deletions docker-compose.monitoring.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
services:
spring:
environment:
SPRING_PROFILES_ACTIVE: loadtest
DB_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB:-chalkak}
DB_USERNAME: ${POSTGRES_USER:-chalkak}
DB_PASSWORD: ${POSTGRES_PASSWORD:-chalkak}
container_name: chalkak-application
deploy:
resources:
limits:
cpus: '1.0'
memory: 1024M
reservations:
cpus: '1.0'
memory: 1024M
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
postgres:
condition: service_healthy
prometheus:
image: prom/prometheus
container_name: chalkak-prometheus
volumes:
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
restart: always
grafana:
image: grafana/grafana
container_name: chalkak-grafana
ports:
- "3001:3000"
restart: always
depends_on:
- prometheus
k6:
image: grafana/k6:latest
container_name: chalkak-k6
deploy:
resources:
limits:
cpus: '1.0'
memory: 1024M
reservations:
cpus: '1.0'
memory: 1024M
volumes:
- ./monitoring/k6/script.js:/script.js
entrypoint: ["sh", "-c"]
command: ["sleep 5 && k6 run /script.js"]
network_mode: host
postgres-exporter:
container_name: postgres-exporter
image: prometheuscommunity/postgres-exporter
environment:
DATA_SOURCE_NAME: "postgresql://${POSTGRES_USER:-chalkak}:${POSTGRES_PASSWORD:-chalkak}@postgres:5432/${POSTGRES_DB:-chalkak}?sslmode=disable"
ports:
- "9187:9187"
depends_on:
postgres:
condition: service_healthy
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ services:
postgres:
image: postgres:16-alpine
container_name: chalkak-postgres
deploy:
resources:
limits:
cpus: '1.0'
memory: 1024M
reservations:
cpus: '1.0'
memory: 1024M
restart: unless-stopped
ports:
- "5432:5432"
Expand Down
Binary file added docs/monitoring-v1.0.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions monitoring/k6/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import http from 'k6/http';
import { check } from 'k6';

const AUCTION_ID = __ENV.AUCTION_ID || 1;

export const options = {
vus: 10,
duration: '30s',
};

export default function () {
const response = http.get(`http://localhost:8080/api/v1/auctions/${AUCTION_ID}`);

check(response, {
'is status 200': (r) => r.status === 200,
});
}
18 changes: 18 additions & 0 deletions monitoring/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]

- job_name: "postgres-exporter"
static_configs:
- targets: ["host.docker.internal:9187"]

- job_name: "chalkak_application"
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ["host.docker.internal:8080"]
3 changes: 2 additions & 1 deletion src/main/java/com/chalkak/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class SecurityConfig {

private static final String[] PERMIT_ALL_PATHS = {
"/api/v1/users",
"/api/v1/auth/login"
"/api/v1/auth/login",
"/actuator/prometheus"
};

@Value("${cors.allowed-origins}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ server:
servlet:
session:
cookie:
same-site: none
secure: true
same-site: lax
secure: false

cors:
allowed-origins: ${CORS_ALLOWED_ORIGINS}
allowed-origins: http://localhost:8080

spring:
datasource:
Expand All @@ -27,4 +27,4 @@ spring:

logging:
level:
com.chalkak: info
com.chalkak: warn
9 changes: 9 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ spring:
name: chalkak
profiles:
active: local

management:
endpoints:
web:
exposure:
include: prometheus
metrics:
tags:
application: ${spring.application.name}
Loading