-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use koanf instead of viper to allow more possibility on config…
…uration (#160) **Describe the pull request** This pull request involves switching from the Viper library to the Koanf library in a Go application. The primary motivation behind this change is to enhance the application's configuration possibilities. Viper, although a comprehensive solution for configuration in Go applications, has some limitations, particularly its case-insensitive behavior and a large number of hardcoded dependencies, which result in a bigger binary size compared to Koanf. For instance, a simple program using Viper is significantly larger (about 313%) than its Koanf equivalent **Checklist** - [x] I have linked the relative issue to this pull request - [x] I have made the modifications or added tests related to my PR - [x] I have added/updated the documentation for my RP - [x] I put my PR in Ready for Review only when all the checklist is checked **Additional context** This switch to Koanf aims to reduce the application's binary size and dependency footprint while maintaining or enhancing configuration capabilities. The choice between Viper and Koanf largely depends on the specific needs and constraints of the application in question.
- Loading branch information
Showing
21 changed files
with
395 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- main | ||
paths: | ||
- '**/*.go' | ||
- '**/*.yml' | ||
- '**/*.yaml' | ||
workflow_dispatch: | ||
permissions: | ||
contents: read | ||
|
@@ -19,6 +19,7 @@ jobs: | |
matrix: | ||
goVersion: [ '1.18', '1.19', '1.20' ] | ||
env: | ||
WH_DEBUG: 'true' | ||
REDIS_HOST: '127.0.0.1' | ||
REDIS_PORT: '6379' | ||
REDIS_PASSWORD: '' | ||
|
@@ -62,9 +63,7 @@ jobs: | |
with: | ||
version: latest | ||
- name: Run Unit tests | ||
run: | | ||
go test ./... -coverprofile coverage.out -covermode count | ||
go tool cover -func coverage.out | ||
run: make test-units | ||
- name: Quality Gate - Test coverage shall be above threshold | ||
env: | ||
TESTCOVERAGE_THRESHOLD: 90 | ||
|
@@ -82,8 +81,7 @@ jobs: | |
fi | ||
- uses: codecov/codecov-action@v3 | ||
- name: Run Go Build | ||
run: | | ||
go build -o /tmp/applications-test-units | ||
run: make build | ||
integration-tests: | ||
name: "Integration tests" | ||
runs-on: ubuntu-latest | ||
|
@@ -92,6 +90,7 @@ jobs: | |
matrix: | ||
goVersion: [ '1.18', '1.19', '1.20' ] | ||
env: | ||
WH_DEBUG: 'true' | ||
REDIS_HOST: '127.0.0.1' | ||
REDIS_PORT: '6379' | ||
REDIS_PASSWORD: '' | ||
|
@@ -102,14 +101,11 @@ jobs: | |
uses: supercharge/[email protected] | ||
with: | ||
redis-version: 6 | ||
- name: Install k6 | ||
run: | | ||
curl https://github.com/grafana/k6/releases/download/v0.45.0/k6-v0.45.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1 | ||
- name: Run Integration tests | ||
run: | | ||
go run main.go serve --config tests/integrations/webhooked_config.integration.yaml >/dev/null 2>&1 & | ||
make run-integration >/dev/null 2>&1 & | ||
until $(curl --output /dev/null --silent --head --fail http://localhost:8080/metrics); do | ||
printf '.' | ||
sleep 1 | ||
done | ||
./k6 run tests/integrations/scenarios.js | ||
make test-integrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Start webhooked", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "main.go", | ||
"args": ["serve"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
test-payload: | ||
curl -XPOST -H 'X-Hook-Secret:test' \ | ||
-d "{\"time\": \"$(date +"%Y-%m-%dT%H:%M:%S")\", \"content\": \"Hello World\"}" \ | ||
http://localhost:8080/v1alpha1/webhooks/example | ||
|
||
install-k6: | ||
@if ! which k6 > /dev/null; then \ | ||
echo "Installing k6..." \ | ||
sudo gpg -k; \ | ||
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69; \ | ||
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list; \ | ||
sudo apt-get update; \ | ||
sudo apt-get install k6; \ | ||
echo "k6 installed successfully"; \ | ||
else \ | ||
echo "k6 is already installed"; \ | ||
fi | ||
|
||
build: | ||
@echo "Building webhooked..." | ||
@GOOS=linux GOARCH=amd64 go build -o ./bin/webhooked ./main.go | ||
|
||
tests: test-units test-integrations | ||
|
||
test-units: | ||
@echo "Running unit tests..." | ||
@export WH_DEBUG=true | ||
@go test ./... -coverprofile coverage.out -covermode count | ||
@go tool cover -func coverage.out | ||
|
||
run-integration: build | ||
@./bin/webhooked --config ./tests/integrations/webhooked_config.integration.yaml serve | ||
|
||
test-integrations: install-k6 | ||
@echo "Running integration tests..." | ||
|
||
@if ! pgrep -f "./bin/webhooked" > /dev/null; then \ | ||
echo "PID file not found. Please run 'make run-integration' in another terminal."; \ | ||
exit 1; \ | ||
fi | ||
|
||
@echo "Running k6 tests..." | ||
@k6 run ./tests/integrations/scenarios.js | ||
|
||
.PHONY: test-payload install-k6 build run-integration test-integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.