Skip to content

Commit

Permalink
Merge pull request #9 from ADPRO-C11/deployment-monitoring
Browse files Browse the repository at this point in the history
Add deployment and monitoring settings
  • Loading branch information
asteriskzie authored May 18, 2024
2 parents d8e6f42 + eefe104 commit cc9c970
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ jobs:
./gradlew check --info --stacktrace
./gradlew test
./gradlew jacocoTestReport
env:
PRODUCTION: test
# (Optional) Add steps for generating coverage report and other post-test tasks

publish:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ jobs:
distribution: "temurin"
java-version: "21"
cache: "gradle"

- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
Expand All @@ -85,4 +87,6 @@ jobs:
./gradlew check --info --stacktrace
./gradlew test
./gradlew jacocoTestReport
# (Optional) Add steps for generating coverage report and other post-test tasks
env:
PRODUCTION: test
# (Optional) Add steps for generating coverage report and other post-test tasks
19 changes: 19 additions & 0 deletions .monitoring/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.7'

services:
prometheus:
image: prom/prometheus:v2.44.0
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml

grafana:
image: grafana/grafana:9.5.2
container_name: grafana
ports:
- "3000:3000"
restart: unless-stopped
volumes:
- ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
7 changes: 7 additions & 0 deletions .monitoring/grafana/provisioning/datasources/datasources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
8 changes: 8 additions & 0 deletions .monitoring/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
scrape_configs:
- job_name: 'MyAppMetrics'
metrics_path: '/actuator/prometheus'
scrape_interval: 3s
static_configs:
- targets: ['host.docker.internal:8080']
labels:
application: 'Snackscription Review'
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ ENV JDBC_DATABASE_URL ${JDBC_DATABASE_URL}
ENV JDBC_DATABASE_USERNAME ${JDBC_DATABASE_USERNAME}

WORKDIR /app
COPY ./review-0.0.1-SNAPSHOT.jar /app
RUN ls -la
COPY build/libs/review-0.0.1-SNAPSHOT.jar /app/review-0.0.1-SNAPSHOT.jar
EXPOSE 8080
CMD ["java","-jar","review-0.0.1-SNAPSHOT.jar"]
5 changes: 5 additions & 0 deletions application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
management:
endpoints:
web:
exposure:
include: [ "prometheus" ]
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
compileOnly("org.projectlombok:lombok")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("org.postgresql:postgresql")
runtimeOnly("io.micrometer:micrometer-registry-prometheus")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")
Expand Down
22 changes: 22 additions & 0 deletions deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: snackscription-review-deployment
spec:
replicas: 3
selector:
matchLabels:
app: snackscription-review
template:
metadata:
labels:
app: snackscription-review
spec:
containers:
- name: snackscription-review
image: asteriskzie/snackscription-review:latest
ports:
- containerPort: 8080
env:
- name: PRODUCTION
value: prod
11 changes: 11 additions & 0 deletions service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: snackscription-review-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: snackscription-review
14 changes: 14 additions & 0 deletions src/main/java/snackscription/review/ReviewAppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package snackscription.review;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ReviewAppConfig {
@Bean
public MeterRegistry getMeterRegistry() {
return new CompositeMeterRegistry();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
@RestController
@RequestMapping("/reviews")
public class ReviewController {


private ReviewService reviewService;

public ReviewController(ReviewService reviewService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import snackscription.review.exception.InvalidStateException;
Expand All @@ -13,6 +16,7 @@
import snackscription.review.repository.ReviewRepository;

@Service
@Component
public class ReviewService {
private ReviewRepository reviewRepository;

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/snackscription_review
spring.datasource.url=jdbc:postgresql://localhost:5433/snackscription_review
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=create-drop
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
spring.application.name=review
spring.profiles.active=${PRODUCTION:dev}
spring.profiles.active=${PRODUCTION:dev}
management.endpoint.info.enabled=true
management.endpoints.web.exposure.include=health,metrics,prometheus,loggers

0 comments on commit cc9c970

Please sign in to comment.