Skip to content

Commit

Permalink
Merge pull request #47 from Lukinhasssss/feature/gradle-kotlin-update
Browse files Browse the repository at this point in the history
atualizado java/gradle/kotlin
  • Loading branch information
Lukinhasssss authored Feb 5, 2024
2 parents 6bb44dc + 95d8263 commit c8698ae
Show file tree
Hide file tree
Showing 41 changed files with 1,107 additions and 38 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sandbox/.docker
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ bin/
.env
/logs/
/infrastructure/src/main/resources/logs/
sandbox/.docker
sandbox/app/.env
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# To build and run:

# build stage
FROM gradle:8.0.2-jdk17-alpine AS builder
FROM gradle:8.5-jdk21-alpine AS builder

WORKDIR /app

Expand All @@ -10,29 +10,32 @@ COPY . .
RUN gradle bootJar

# build runtime
FROM eclipse-temurin:17.0.6_10-jre-alpine
FROM eclipse-temurin:21-jre-alpine

ARG JAR_FILE=/app/build/libs/app*.jar

COPY --from=builder $JAR_FILE /app.jar
COPY --from=docker.elastic.co/observability/apm-agent-java:1.38.0 /usr/agent/elastic-apm-agent.jar /apm-agent.jar
COPY opentelemetry-javaagent.jar /opentelemetry-javaagent.jar

# Download do OpenTelemetry Java Agent
#RUN wget -O /opentelemetry-javaagent.jar https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.31.0/opentelemetry-javaagent.jar
RUN wget -O /opentelemetry-javaagent.jar https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

# Download do Elastic APM Java Agent
#RUN wget -O /apm-agent.jar https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/1.46.0/elastic-apm-agent-1.46.0.jar
COPY --from=docker.elastic.co/observability/apm-agent-java:latest /usr/agent/elastic-apm-agent.jar /apm-agent.jar

RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring

ENTRYPOINT [ "java", \
"-javaagent:/apm-agent.jar", \
"-Delastic.apm.service_name=admin-do-catalogo", \
"-Delastic.apm.server_url=http://apm-admin-do-catalogo:8200", \
"-Delastic.apm.server_url=http://apm-codeflix:8200", \
"-Delastic.apm.environment=codeflix", \
"-Delastic.apm.application_packages=com.lukinhasssss", \
"-javaagent:/opentelemetry-javaagent.jar", \
"-Dotel.service.name=admin-do-catalogo", \
"-Dotel.traces.exporter=otlp", \
"-Dotel.metrics.exporter=otlp", \
"-Dotel.integration.jdbc.datasource.enabled=true", \
"-Dotel.instrumentation.jdbc.datasource.enabled=true", \
"-Dotel.exporter.otlp.endpoint=http://collector-admin-do-catalogo:4318", \
"-Dotel.exporter.otlp.endpoint=http://otel-collector-codeflix:4318", \
"-Dotel.exporter.otlp.protocol=http/protobuf", \
"-jar", "/app.jar" \
]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EventConfig {
@Bean
@VideoCreatedQueue
@Profile(value = ["development"])
fun inMemoryVideoCreatedEventService(): EventService = InMemoryEventService()
fun videoCreatedInMemoryEventService(): EventService = InMemoryEventService()

@Bean
@VideoCreatedQueue
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ spring:
hikari: # É responsável por gerenciar o pool de conexões
auto-commit: false
connection-timeout: 250 # É uma configuração em milliseconds. O ideal é manter baixo para que estoure timeout logo e não prenda as threads.
idle-timeout: 60000
max-lifetime: 600000 # Tempo máximo que uma conexão pode ficar aberta (10 min) - security.
maximum-pool-size: 20 # Mantemos até no máx 20 conexões com o banco de dados. O ideal é manter baixo mesmo, pois é algo custoso para o banco gerenciar. https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing
minimum-idle: 10
Expand All @@ -70,7 +71,7 @@ spring:
persistence:
sharedCache:
mode: UNSPECIFIED # https://github.com/spring-projects/spring-data-jpa/issues/2717
"[hibernate.dialect]": org.hibernate.dialect.PostgreSQLDialect
# "[hibernate.dialect]": org.hibernate.dialect.PostgreSQLDialect
"[hibernate.generate_statistics]": false
"[hibernate.connection.provider_disables_autocommit]": true
# Para aumentar a performance ao máximo, desabilitamos o auto-commit e o open-in-view.
Expand Down

This file was deleted.

Binary file removed opentelemetry-javaagent.jar
Binary file not shown.
51 changes: 51 additions & 0 deletions sandbox/app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '3.9'

services:
admin-do-catalogo:
container_name: admin-do-catalogo
build:
context: ../../
dockerfile: Dockerfile
# image: lukinhasssss/admin-do-catalogo
ports:
- "8080:8080"
env_file:
- ../../.env
restart: on-failure
networks:
- admin-do-catalogo
- admin-do-catalogo-services
# - open-telemetry-codeflix
# - elasticsearch-codeflix
labels:
filebeat_collector: true

filebeat-admin-do-catalogo:
container_name: filebeat-admin-do-catalogo
image: docker.elastic.co/beats/filebeat:8.12.0
volumes:
- /var/lib/docker/containers:/var/lib/docker/containers:ro # Docker logs
- /var/run/docker.sock:/var/run/docker.sock:ro # Additional information about containers
- ./filebeat/filebeat.yaml:/usr/share/filebeat/filebeat.yml:ro # Configuration file
- ../.docker/filebeat:/usr/share/filebeat/data:rw # Persistence data
user: root # Allow access to log files and docker.sock
environment:
- ELASTIC_HOSTS=http://elasticsearch-codeflix:9200
- KIBANA_HOSTS=http://kibana-codeflix:5601
- LOGSTASH_HOSTS=http://logstash-codeflix:9600
restart: on-failure
command:
- '-strict.perms=false'
networks:
- admin-do-catalogo
- elasticsearch-codeflix

networks:
admin-do-catalogo:
external: true
admin-do-catalogo-services:
external: true
open-telemetry-codeflix:
external: true
elasticsearch-codeflix:
external: true
36 changes: 36 additions & 0 deletions sandbox/app/filebeat/filebeat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
filebeat:
autodiscover:
providers:
- type: docker
labels.dedot: true
templates:
- condition:
contains:
container.labels.filebeat_collector: "true"
config:
- type: container
format: docker
paths:
- "/var/lib/docker/containers/${data.docker.container.id}/*.log"
processors:
- decode_json_fields:
when.equals:
docker.container.labels.decode_log_event_to_json_object: "true"
fields: ["message"]
target: ""
overwrite_keys: true

output:
logstash:
hosts: logstash-codeflix:5044

#output.elasticsearch:
# hosts: ["elasticsearch-codeflix:9200"]

setup:
kibana:
host: "kibana-codeflix:5601"
dashboards:
enabled: true

logging.metrics.enabled: false
23 changes: 23 additions & 0 deletions sandbox/elk/apm/apm-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apm-server:
host: "apm-codeflix:8200"
rum:
enabled: true
source_mapping:
enabled: true
elasticsearch:
hosts: ["elasticsearch-codeflix:9200"]
username: "elastic"
password: "changeme"
expiration: 5m
index_pattern: "apm-*-sourcemap*"
kibana:
enabled: true
host: "kibana-codeflix:5601"
output.elasticsearch:
hosts: ["elasticsearch-codeflix:9200"]
username: 'elastic'
password: 'changeme'
enabled: true
output.logstash:
hosts: ["logstash-codeflix:5044"]
enabled: false
27 changes: 27 additions & 0 deletions sandbox/elk/beats/heartbeat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
heartbeat.monitors:
- type: http
schedule: '@every 5s'
urls:
- http://elasticsearch-codeflix:9200
- http://kibana-codeflix:5601
- http://admin-do-catalogo:8080/api
- http://catalogo-de-videos:8081/api

- type: icmp
schedule: '@every 5s'
hosts:
- elasticsearch-codeflix
- kibana-codeflix
- apm-codeflix
- metricbeat-codeflix

processors:
- add_cloud_metadata: ~

#output.logstash:
# hosts: 'logstash-codeflix:5044'

output.elasticsearch:
hosts: 'elasticsearch-codeflix:9200'
username: 'elastic' # elasticsearch default user
password: 'changeme' # elasticsearch default password
32 changes: 32 additions & 0 deletions sandbox/elk/beats/metricbeat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
metricbeat.modules:
- module: docker
metricsets: [ "container", "cpu", "diskio", "event", "healthcheck", "image", "info", "memory", "network" ]
hosts: [ "unix:///var/run/docker.sock" ]
period: 10s

- module: elasticsearch
metricsets: [ "node", "node_stats", "cluster_stats", "index" ]
period: 10s
hosts: ["elasticsearch-codeflix:9200"]

- module: prometheus
period: 10s
metricsets: [ "collector" ]
hosts: [ "prometheus-codeflix:9090" ]
metrics_path: /metrics

- module: postgresql
metricsets: [ "database", "bgwriter", "activity" ]
period: 10s
hosts: [ "postgres:////localhost:5432", "postgres://postgres-admin-do-catalogo:5432", "postgres://postgres-admin-do-catalogo:5432/adm_videos", "postgres-admin-do-catalogo:5432" ]

output.elasticsearch:
hosts: ["elasticsearch-codeflix:9200"]

#output.logstash:
# hosts: ["logstash-codeflix:5044"]

setup.kibana:
host: "kibana-codeflix:5601"

setup.dashboards.enabled: true
Loading

0 comments on commit c8698ae

Please sign in to comment.