Skip to content

Commit 2b29d11

Browse files
committed
init from old account
0 parents  commit 2b29d11

110 files changed

Lines changed: 9215 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
# Service Configuration
3+
SERVICE_NAME=delivery
4+
PORT=5007
5+
DEVELOPMENT=true
6+
BASE_PATH=/api
7+
8+
# Logger Configuration
9+
LOGGER_LEVEL=debug
10+
LOGGER_DEBUG=false
11+
LOGGER_ENCODER=console
12+
13+
# MongoDB Configuration
14+
MONGO_URI=mongodb://mongodb:27017
15+
MONGO_INITDB_ROOT_USERNAME=admin
16+
MONGO_INITDB_ROOT_PASSWORD=admin
17+
MONGO_INITDB_DATABASE=orders
18+
MONGO_COLLECTIONS_ORDERS=orders
19+
20+
# Jaeger Configuration
21+
JAEGER_ENABLE=true
22+
JAEGER_SERVICE_NAME=delivery
23+
JAEGER_HOST_PORT=jaeger:6831
24+
JAEGER_LOG_SPANS=false
25+
26+
# EventStore Configuration
27+
EVENTSTORE_CONFIG_CONNECTION_STRING=esdb://eventstore:2113?tls=false
28+
29+
# Subscriptions Configuration
30+
SUBSCRIPTIONS_POOL_SIZE=10
31+
SUBSCRIPTIONS_ORDER_PREFIX=order-
32+
SUBSCRIPTIONS_MONGO_PROJECTION_GROUP_NAME=orders
33+
SUBSCRIPTIONS_ELASTIC_PROJECTION_GROUP_NAME=order_elastic
34+
35+
# ElasticSearch Configuration
36+
ELASTIC_URL=http://node01:9200
37+
ELASTIC_SNIFF=false
38+
ELASTIC_GZIP=true
39+
ELASTIC_EXPLAIN=true
40+
ELASTIC_FETCH_SOURCE=true
41+
ELASTIC_VERSION=true
42+
ELASTIC_PRETTY=true
43+
ELASTIC_INDEXES_ORDERS=orders

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build and Release Docker Image
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Log in to GitHub Container Registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ${{ env.REGISTRY }}
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34+
tags: |
35+
type=sha
36+
type=semver,pattern={{version}}
37+
type=ref,event=branch
38+
39+
- name: Build and push Docker image
40+
uses: docker/build-push-action@v5
41+
with:
42+
context: .
43+
push: true
44+
tags: ${{ steps.meta.outputs.tags }}
45+
labels: ${{ steps.meta.outputs.labels }}
46+
47+
- name: Create GitHub Release
48+
uses: softprops/action-gh-release@v1
49+
if: startsWith(github.ref, 'refs/tags/')
50+
with:
51+
generate_release_notes: true

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
name: tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Install Go
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: '1.24.x'
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
- name: Test
21+
run: go test ./...

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# env file
25+
.env
26+
.idea
27+
main
28+
config/config.yml
29+
config/config.yaml
30+
src
31+
deployments/base/configs/*-secret.yaml
32+
deployments/components/monitoring/charts/*
33+
deployments/components/istio/charts/*
34+
.garbage

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- repo: https://github.com/dnephin/pre-commit-golang
10+
rev: v0.5.0
11+
hooks:
12+
- id: go-fmt
13+
- id: go-imports
14+
- id: no-go-testing
15+
- id: golangci-lint
16+
- id: go-unit-tests
17+
# - id: validate-toml
18+
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
19+
rev: v8.0.0
20+
hooks:
21+
- id: commitlint
22+
stages: [commit-msg]
23+
additional_dependencies: ['@commitlint/config-conventional']

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch API",
6+
"type": "go",
7+
"request": "launch",
8+
"mode": "debug",
9+
"program": "${workspaceFolder}/cmd/server",
10+
"env": {
11+
"GO_ENV": "development",
12+
},
13+
"showLog": true,
14+
"trace": "verbose"
15+
}
16+
]
17+
}

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM golang:1.24-alpine as build
2+
3+
WORKDIR /app
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
COPY . .
8+
9+
RUN go build -o main cmd/server/main.go
10+
11+
FROM alpine:latest as run
12+
13+
WORKDIR /app
14+
COPY --from=build /app/main /app
15+
CMD ["./main"]

Dockerfile.dev

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM golang:1.24-alpine
2+
3+
WORKDIR /app
4+
5+
RUN go install github.com/githubnemo/CompileDaemon@latest
6+
COPY go.mod go.sum ./
7+
RUN go mod download
8+
COPY . .
9+
10+
ENTRYPOINT CompileDaemon --build="go build -o main cmd/server/main.go" --command=./main

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.PHONY:
2+
3+
start:
4+
@echo Starting dev docker compose
5+
docker-compose -f docker-compose.yaml up -d --build
6+
docker-compose -f docker-compose.yaml logs -f app
7+
8+
stop:
9+
docker-compose -f docker-compose.yaml down
10+
11+
test:
12+
@echo Starting test
13+
go test -v ./...
14+
15+
clean:
16+
docker system prune -f
17+
18+
deps-reset:
19+
git checkout -- go.mod
20+
go mod tidy
21+
22+
deps-upgrade:
23+
go get -u -t -d -v ./...
24+
go mod tidy
25+
26+
deps-cleancache:
27+
go clean -modcache
28+
29+
lint:
30+
@echo Starting linters
31+
golangci-lint run ./...
32+
33+
swagger:
34+
swag init --parseDependency --parseInternal -g **/**/*.go

README.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# **Motivation**
2+
3+
Pro tip: Don't drive blindfolded. 🏎️ 👮‍♂️
4+
5+
This project demonstrates a **production-grade observability setup** for a distributed system, capturing all three pillars of observability:
6+
- **Logs**
7+
- **Metrics**
8+
- **Traces**
9+
10+
### **Okitou! why This Demo?**
11+
The stack includes:
12+
- A **Golang API** (because why not?) with **MongoDB**, **EventStore** and **Elasticsearch**.
13+
- **Kubernetes manifests** across three namespaces (`prod`, `monitoring`, `istio-system`) to simulate a real multi-environment setup
14+
- The full **observability toolkit**:
15+
- **Prometheus** + **Node Exporter** (metrics, because $htop is *so* 1999)
16+
- **Grafana** (With enough dashboards)
17+
- **Loki** + **Promtail**
18+
- **Jaeger** (To play detective)
19+
- **Kiali** (Who knows what's up with Istio)
20+
21+
Although you might not need EVERYTHING in this repo, this setup mirrors real-world observability needs, ensuring you can **monitor, alert, and troubleshoot** before users notice anything’s wrong.
22+
23+
#### Key Configuration
24+
* Kustomize overlays for environment-specific configurations, although only worked on a "prod" setup.
25+
* Separate RBAC restrictions for developer-base in production VS sre role.
26+
* A base cluster policy using **kyverno** to ensure all namespaced resources are in [dev/prod/monitoring/istio-system].
27+
28+
## Prerequisites locally
29+
- Docker
30+
- Docker Compose
31+
- go 1.24
32+
33+
## Setup
34+
35+
1. Copy `.env.example` to `.env`:
36+
```sh
37+
cp .env.example .env
38+
go mod download
39+
```
40+
41+
2. Start the application:
42+
```sh
43+
make start
44+
```
45+
46+
3. To run tests:
47+
```sh
48+
make test
49+
```
50+
51+
## Swagger
52+
53+
The REST API documentation is available at: http://localhost:5007/swagger/index.html
54+
55+
## Project Structure
56+
57+
#### Internal Structure (DDD Approach)
58+
59+
The internal structure follows Domain-Driven Design (DDD) principles:
60+
61+
```sh
62+
/internal
63+
├── api
64+
│ ├── constants
65+
│ ├── dto
66+
│ ├── handlers
67+
│ ├── middlewares
68+
│ ├── server.go
69+
│ └── utils
70+
├── delivery
71+
│ ├── aggregate
72+
│ ├── commands
73+
│ ├── events
74+
│ ├── models
75+
│ ├── projections
76+
│ ├── queries
77+
│ ├── repository
78+
│ └── services
79+
└── infrastructure
80+
├── elasticsearch
81+
├── es
82+
├── eventstore
83+
├── mongodb
84+
└── tracing
85+
```
86+
87+
The structure separates concerns according to DDD layers:
88+
- `api`: Presentation layer handling HTTP requests/responses
89+
- `delivery`: Core domain logic and business rules
90+
- `infrastructure`: Technical implementation details and external integrations
91+
---
92+
93+
#### Cluster Diagram
94+
![current cluster](./diagram_cluster.png)
95+
96+
#### Cluster Structure
97+
```sh
98+
deployments
99+
├── base
100+
│ ├── api
101+
│ ├── configs
102+
│ │ ├── clusterroles.yaml
103+
│ │ ├── configmaps.yaml
104+
│ │ ├── github-registry-secret.yaml
105+
│ │ ├── kustomization.yaml
106+
│ │ ├── mongodb-secret.yaml
107+
│ │ └── policy.yaml
108+
│ ├── elasticsearch
109+
│ ├── eventstore
110+
│ ├── kustomization.yaml
111+
│ └── mongodb
112+
├── components
113+
│ ├── istio
114+
│ │ ├── charts
115+
│ │ ├── generator.yaml
116+
│ │ └── kustomization.yaml
117+
│ ├── kustomization.yaml
118+
│ ├── kustomizeconfig.yaml
119+
│ └── monitoring
120+
│ ├── charts
121+
│ ├── generator.yaml
122+
│ ├── jaeger
123+
│ ├── kustomization.yaml
124+
│ └── values.yaml
125+
└── overlays
126+
└── prod
127+
├── kustomization.yaml
128+
└── patches
129+
├── api-svc.yaml
130+
└── restrict-developer-permissions.yaml
131+
```
132+
133+
#### Screenshots
134+
![logs](./screenshots/go-service-logs.png)
135+
![traces](./screenshots/go-service-traces.png)
136+
![mesh](./screenshots/mesh-1.png)
137+
![mesh setup](./screenshots/mesh-2.png)
138+
![metrics](./screenshots/nodes.png)

0 commit comments

Comments
 (0)