Skip to content

Commit 1fe8eae

Browse files
authored
Merge pull request #61 from SaraAlajmy/global/logging
Youssef PR bs sra2to
2 parents 07ee9c7 + bbee857 commit 1fe8eae

File tree

10 files changed

+219
-9
lines changed

10 files changed

+219
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea
1+
.idea
2+
**/logs/

build.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status.
4+
set -e
5+
6+
# Define your Docker Hub username
7+
DOCKERHUB_USERNAME="farahalfawzy"
8+
IMAGE_TAG="latest"
9+
10+
echo "Building Maven projects..."
11+
mvn clean install -DskipTests
12+
mvn package -DskipTests
13+
14+
# Services and their directories
15+
SERVICES=(
16+
"chat-service:./chat-service"
17+
"api-gateway-service:./gateway"
18+
"group-chat-service:./groupChatService"
19+
"notification-service:./notification-service"
20+
"user-service:./userService"
21+
)
22+
23+
for service_info in "${SERVICES[@]}"; do
24+
IFS=':' read -r service_name service_dir <<< "$service_info"
25+
26+
echo "Building and pushing $service_name..."
27+
docker build -t "${DOCKERHUB_USERNAME}/${service_name}:${IMAGE_TAG}" "${service_dir}"
28+
done
29+
30+
echo "All images built and pushed successfully!"

chat-service/src/main/resources/application.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ spring:
2323
write-dates-as-timestamps: false
2424
default-property-inclusion: NON_NULL
2525

26-
2726
user-service:
2827
url: http://localhost:8086

docker-compose.yml

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ services:
1111
image: rabbitmq:3-management
1212
container_name: rabbitmq
1313
ports:
14-
- "5672:5672"
15-
- "15672:15672"
14+
- "5672:5672"
15+
- "15672:15672"
1616
environment:
1717
RABBITMQ_DEFAULT_USER: guest
1818
RABBITMQ_DEFAULT_PASS: guest
@@ -25,10 +25,72 @@ services:
2525
environment:
2626
ME_CONFIG_MONGODB_URL: mongodb://mongo:27017/
2727
ME_CONFIG_BASIC_AUTH: false
28-
ME_CONFIG_BASICAUTH: false
28+
ME_CONFIG_BASICAUTH: false
2929

3030
depends_on:
3131
- mongo
3232

33+
# Initializing Loki with the config file
34+
loki:
35+
image: grafana/loki:latest
36+
ports:
37+
- "3100:3100"
38+
command: -config.file=/etc/loki/local-config.yaml
39+
networks:
40+
- loki
41+
42+
# Initializing Promtail with the config file
43+
# and mounting the log files
44+
promtail:
45+
image: grafana/promtail:latest
46+
volumes:
47+
- ./promtail:/etc/promtail
48+
- ./chat-service/logs:/var/log/chat-service
49+
- ./userService/logs:/var/log/user-service
50+
- ./gateway/logs:/var/log/gateway
51+
- ./notification-service/logs:/var/log/notification-service
52+
command: -config.file=/etc/promtail/promtail-config.yml
53+
networks:
54+
- loki
55+
56+
# Initializing Grafana with the config file
57+
# declaring the Loki datasource
58+
# and mounting the Grafana storage
59+
grafana:
60+
environment:
61+
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
62+
- GF_AUTH_ANONYMOUS_ENABLED=true
63+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
64+
- GF_FEATURE_TOGGLES_ENABLE=alertingSimplifiedRouting,alertingQueryAndExpressionsStepMode
65+
entrypoint:
66+
- sh
67+
- -euc
68+
- |
69+
mkdir -p /etc/grafana/provisioning/datasources
70+
cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
71+
apiVersion: 1
72+
datasources:
73+
- name: Loki
74+
type: loki
75+
access: proxy
76+
orgId: 1
77+
url: http://loki:3100
78+
basicAuth: false
79+
isDefault: true
80+
version: 1
81+
editable: false
82+
EOF
83+
/run.sh
84+
image: grafana/grafana:latest
85+
ports:
86+
- "3000:3000"
87+
networks:
88+
- loki
89+
3390
volumes:
3491
mongodb_data:
92+
grafana-storage:
93+
94+
95+
networks:
96+
loki:

gateway/src/main/resources/application.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,3 @@ jwt:
5151
expiration-time: 600
5252
userService:
5353
url: http://localhost:8086
54-
55-

groupChatService/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ spring.web.resources.add-mappings=false
88
server.error.include-stacktrace=never
99
server.error.include-message=always
1010

11-
user-service.url=http://localhost:8086
11+
user-service.url=http://localhost:8086

k8s/loki/loki-stack-values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
loki:
2+
enabled: true
3+
4+
promtail:
5+
enabled: true
6+
7+
grafana:
8+
enabled: true
9+
service:
10+
type: NodePort
11+
adminPassword: "admin" # Replace with a secure password
12+
persistence:
13+
enabled: true
14+
size: 1Gi

loki/local-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This is a sample configuration file for Loki.
2+
auth_enabled: false
3+
4+
server:
5+
http_listen_port: 3100
6+
7+
# The ingester is the component that receives logs and writes them to the storage backend.
8+
# It is responsible for managing the lifecycle of log entries
9+
ingester:
10+
lifecycler:
11+
ring:
12+
kvstore:
13+
store: inmemory
14+
replication_factor: 1
15+
final_sleep: 0s
16+
chunk_idle_period: 5m
17+
max_chunk_age: 1h
18+
chunk_retain_period: 30s
19+
max_transfer_retries: 0
20+
21+
22+
# The schema configuration defines how the logs are stored in the storage backend.
23+
# It includes the schema version, the object store, and the index configuration.
24+
schema_config:
25+
configs:
26+
- from: 2022-01-01
27+
store: boltdb-shipper
28+
object_store: filesystem
29+
schema: v11
30+
index:
31+
prefix: index_
32+
period: 24h
33+
34+
# The storage configuration defines how the logs are stored in the storage backend.
35+
# It includes the storage type, the directory for storing chunks, and the index configuration.
36+
storage_config:
37+
boltdb_shipper:
38+
active_index_directory: /tmp/loki/index
39+
cache_location: /tmp/loki/boltdb-cache
40+
shared_store: filesystem
41+
filesystem:
42+
directory: /tmp/loki/chunks
43+
44+
# The limits configuration defines the limits for the ingester and the storage backend.
45+
# It includes the maximum size of the chunks, the maximum number of chunks, and the maximum age of the chunks.
46+
limits_config:
47+
enforce_metric_name: false
48+
reject_old_samples: true
49+
reject_old_samples_max_age: 168h
50+
51+
# the chunk store configuration defines how the chunks are stored in the storage backend.
52+
# It includes the maximum look back period for the chunks and the maximum size of the chunks.
53+
chunk_store_config:
54+
max_look_back_period: 0s
55+
56+
# The table manager is responsible for managing the lifecycle of the tables in the storage backend.
57+
# It includes the retention period for the tables and the retention deletes configuration.
58+
table_manager:
59+
retention_deletes_enabled: false
60+
retention_period: 0s

promtail/promtail-config.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
# Promtail configuration file for scraping logs from various services
3+
server:
4+
http_listen_port: 9080
5+
grpc_listen_port: 0
6+
7+
# Positions configuration
8+
# This is where Promtail stores the last read position of each log file
9+
positions:
10+
filename: /tmp/positions.yaml
11+
12+
# Client configuration
13+
# This is where Promtail sends the scraped logs
14+
clients:
15+
- url: http://loki:3100/loki/api/v1/push
16+
17+
# Scrape configuration
18+
# This is where Promtail defines the jobs to scrape logs from
19+
scrape_configs:
20+
- job_name: chat-service
21+
static_configs:
22+
- targets: [localhost]
23+
labels:
24+
job: chat-service
25+
__path__: /var/log/chat-service/app.log
26+
27+
- job_name: user-service
28+
static_configs:
29+
- targets: [localhost]
30+
labels:
31+
job: user-service
32+
__path__: /var/log/user-service/app.log
33+
34+
- job_name: gateway
35+
static_configs:
36+
- targets: [localhost]
37+
labels:
38+
job: gateway
39+
__path__: /var/log/gateway/app.log
40+
41+
- job_name: notification-service
42+
static_configs:
43+
- targets: [localhost]
44+
labels:
45+
job: notification-service
46+
__path__: /var/log/notification-service/app.log

userService/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jwt.blacklist.expiration-time=600
2020
jwt.access-token-validity=600000
2121
jwt.refresh-token-validity=518400000
2222

23-
notification.service.url=http://localhost:8082
23+
notification.service.url=http://localhost:8082

0 commit comments

Comments
 (0)