This repository follows the philosophy of Learning by Doing. It includes plays, experiments with Golang and its frameworks to learn. Later Kubernetes including Docker, Istio (Service Mesh), Performance testing is also included.
-
FunApp is a Sample Rest App which tries to use various golang Frameworks commonly required. It tries to follow good practices and standards. It runs without any dependencies with in memory sqlite3 database by default.
-
-
- We will use Make for Project Management.
- Installs required dependencies and tools,
make prepare
- To check what all is available run
make
to display Help.
- Run
make reset
will do Complete Build, Test, Coverage and Show Info. - Use
make info
(orinfos
) for displaying Info.
-
-
Easy ways to Play with FunApp without Dev Setup.
- Start
- Golang:
make run
- Docker Image:
docker run amanfdk/fun-app
- Golang:
- Testing
- Unit and Integration Testing is done via Ginkgo.
- Run Tests:
make test test-slow
(Excludes that require separate setup.)
- Performance Test
Vegeta is the tool of choice here. Gum helps in prompts.
- Installation:
brew install gum vegeta
- Run:
make -C ./components/fun-app/it setup
- Installation:
- Linting
make lint
will do Code Linting using golangci-lint
- Start
-
This section guides on setup for Development Setup for this Repository. We are using Vscode and Kubernetes for this example.
-
- Use Command Palatte and run application using
> Select and Start Debugging
and then SelectFunApp
- Change ENV to override default Configuration.
- Use Command Palatte and run application using
-
- Development help you live debug an application in K8 Cluster.
- It is configured to Auto Reload Code Changes.
- This Sets Up Dev Container in
fun-app
Namespace. - Try:
- Run
make space
, Open http://localhost:8080/metrics - Tests:
make space-test
- Cleanup:
make space-purge
- Check Environment Vars:
make infos
- Override Vars:
devspace list vars --var DB="mysql-primary",RATE_LIMIT=10
- Run
-
- Below Section requires running Kubernetes Cluster and Helm CLI. Charts can be used from local or from Github.
- Via Github
- Setup:
helm install -n fun-app fun-app go-fun/fun-app
(Onetime Setup Needed) - Cleanup:
helm -n fun-app delete fun-app
- Setup:
- Via Local
- Deploys FunApp and Vegeta Container (for Load Test).
- Setup:
make -C ./components/fun-app/charts setup
(orreset
) - Clean:
make -C ./components/fun-app/charts clean
(orinfo
)
- Access
- Open: http://localhost:9090/metrics (Tunnel required for forwarding:
minikube tunnel
) - Load Test (From Vegeta Container):
echo 'GET http://fun-app:9090/person/all' | vegeta attack | vegeta report
- Log Analyzer :
make -C ./components/fun-app/charts analyse
- Open: http://localhost:9090/metrics (Tunnel required for forwarding:
-
-
-
-
To ease development and easy setup of dependencies we use Kubernetes. Also K9S provides easy interface to manage containers, see logs etc. Helms are used to setup various services which application can depend on.
-
- To setup kubernetes there are multiple options available like minikube, kind, k89, k3s etc. In this project we are using minikube.
- This will also setup traifik ingress for easy access.
- DNS Mapping via
/etc/hosts
is done as part of Onetime Prepration. - User needs to give sudo for port 80 forward.
- DNS Mapping via
- Setup -
make -C ./Kubernetes setup
(orreset
for clean and setup) - Teardown -
make -C ./Kubernetes clean
- Useful Targets: Istio Setup
istio
, Info (info
orinfos
), Portforwardport
, K8 Dashboarddashboard
.
-
- Package has multiple service which can be setup on top of Minikube. This helps in easy setup of complex dependencies like Mysql Cluster, Load Testing, Mongo, Prometheus, Sonar and many more ...
- Service Script allows you to configure a set of Services. This can then be installed, upgraded or deleted.
- Select:
make -C ./Kubernetes/services select
will show a gum menu (Multiselect) to choose one or more services. - Setup:
make -C ./Kubernetes/services setup
(orreset
) to deploy selected services. - Update:
make -C ./Kubernetes/services update
to update values or helm chart changes. - Stop:
make -C ./Kubernetes/services clean
to remove deployed helms. (Configured Services only) - Info:
make -C ./Kubernetes/services info
(orinfos
)
-
-
- Monitor Logs via GoAccess
- Terminal Access:
go run main.go | goaccess --log-format='%^ %d - %t | %s | %~%D | %b | %~%h | %^ | %m %U' --date-format='%Y/%m/%d' --time-format '%H:%M:%S'
- Web Access
- Add Flags to Above Command
-o report.html --real-time-html
. - Open report.html in Browser and it should auto refresh.
- Add Flags to Above Command
- Terminal Access:
- Useful Fields
-
Mandatory Fields: %d (Date), %h (Host), %r/%m %U (Request)
-
Skip: Ignore (%^) , Skip Space (%~)
-
DateTime: (%x/--datetime-format) OR Time (%t/--date-format) + Date (%d/--time-format)
-
Host: IP (%h) OR Virtual Host (%v)
-
Request: Full With Quotes (%r) or Method (%m), URL (%U), Query (%q), PROTOCOL (%H),
-
Response: Status Code (%s), Size (%b)
-
Latency: MicroSecond (%D), MilliSecond.MicroSecond (%T), MilliSecond With Decimal (%L)
-
User Info: User-Agent (%u), Referrer (%R)
TODO: Add GIF
-
- Custom Log Monitoring
- Custom Logs require configuring various flags.
- Identify Date and Time Format.
- Configured via flag
--date-format
and--time-format
- Verify Format, bash run:
date '+%Y/%m/%d - %H:%M:%S'
for output2023/01/23 - 14:38:2
- Configured via flag
- Identify Log Format
- Configured via flag
--log-format
- Start with initial fields and progress further for easy debug.
- Configured via flag
- Debug Mode:
-l debug.log
- Monitor Logs via GoAccess
TODO
Tree ExtensionTODO
Long Planned Enhancement in CodeFIXME
Medium Sized fix or Unhandled Case.HACK
Remove Hacky way to Do Things.BUG
Small Bug which is observed but need Fix.XXX
Someday Tasks which may or may not be Done.#A
#B
#C
for Priortizations. Eg.BUG: #A Some Message
-
To ease development and easy setup of dependencies we use Kubernetes. Also K9S provides easy interface to manage containers, see logs etc. Helms are used to setup various services which application can depend on.
-
This section covers common practices and tools for Golang.
-
This is multi module project. Each module has its own go mod file. Modules can be managed using semver tags. Eg. v1.0.0
- Sync Modules using
make sync
. This is automatically done before builds. - Mod
- New Module run
go mod init github.com/amanhigh/go-fun/components/fun-app
and to work usinggo work use ./components/fun-app
- Link Module to new Release using
go mod tidy
orgo get -u github.com/amanhigh/go-fun/models
- Recursive Depdency Update
find . -name "go.mod" -execdir sh -c 'go get -u && go mod tidy';
(Run it in ProjectBase Dir)
- New Module run
- Tags
- See existing tags.
git tag | grep common
- Tag New Release.
git tag common/v1.0.0
followed bygit push --tags
- Remove Release involves deleting Tag with
git push --delete origin common/v1.0.0
- See existing tags.
- Sync Modules using
-
Release management includes build and release of Artifacts like binaries, dockers etc.
- Build Only -
make build docker-build
(addclean
to remove residue) - Release -
make release release-docker VER=v1.0.3
- Delete Release -
make unrelease VER=v1.0.3
(Not Recommended)
- Build Only -
-
This is multi module project. Each module has its own go mod file. Modules can be managed using semver tags. Eg. v1.0.0