Skip to content

Commit 5246ea5

Browse files
committed
chore: example
1 parent 73b87a8 commit 5246ea5

19 files changed

+1150
-183
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"*.pinc": "starlark",
77
"*.proto-validator": "Starlark",
88
"*.materialized_JSON": "json"
9-
}
9+
},
10+
"editor.formatOnSave": true
1011
}

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ Protoconf XDS reads its configuration from the environment variables or command
6060
type: string (default localhost:4300)
6161
```
6262

63+
### Running the example
64+
65+
The example in this repository is inspired by Envoy's [ratelimit](https://github.com/envoyproxy/ratelimit) project.
66+
67+
#### Architecture diagram
68+
69+
![](docs/protoconf_xds_architechture.png)
70+
71+
To run the `protoconf` agent:
72+
73+
```sh
74+
protoconf agent -dev .
75+
```
76+
77+
To run the `proxy`, `mock` and `ratelimit`:
78+
79+
```sh
80+
docker-compose up
81+
```
82+
6383
### License
6484

6585
Protoconf XDS is licensed under the MIT License. See `LICENSE` file for more information.

cmd/serve/serve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (c *Command) Run(args []string) int {
102102
xdsCache := cache.NewSnapshotCache(false, cache.IDHash{}, c.logger)
103103

104104
conn, err := grpc.Dial(
105-
"localhost:4300",
105+
c.config.ProtoconfAgentAddr,
106106
grpc.WithTransportCredentials(insecure.NewCredentials()),
107107
)
108108
if err != nil {

docker-compose.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
version: "3"
2+
services:
3+
redis:
4+
image: redis:alpine
5+
expose:
6+
- 6379
7+
ports:
8+
- 6379:6379
9+
networks:
10+
- ratelimit-network
11+
12+
statsd:
13+
image: prom/statsd-exporter:v0.18.0
14+
entrypoint: /bin/statsd_exporter
15+
command:
16+
- "--statsd.mapping-config=/etc/statsd-exporter/conf.yaml"
17+
expose:
18+
- 9125
19+
- 9102
20+
ports:
21+
- 9125:9125
22+
- 9102:9102 # Visit http://localhost:9102/metrics to see metrics in Prometheus format
23+
networks:
24+
- ratelimit-network
25+
volumes:
26+
- ./examples/prom-statsd-exporter/conf.yaml:/etc/statsd-exporter/conf.yaml
27+
28+
ratelimit:
29+
image: envoyproxy/ratelimit:master
30+
command: /bin/ratelimit
31+
ports:
32+
- 8080:8080
33+
- 8081:8081
34+
- 6070:6070
35+
depends_on:
36+
- redis
37+
- statsd
38+
networks:
39+
- ratelimit-network
40+
# volumes:
41+
# - ./examples/ratelimit/config:/data/ratelimit/config
42+
environment:
43+
- USE_STATSD=true
44+
- STATSD_HOST=statsd
45+
- STATSD_PORT=9125
46+
- LOG_LEVEL=trace
47+
- REDIS_SOCKET_TYPE=tcp
48+
- REDIS_URL=redis:6379
49+
- RUNTIME_ROOT=/data
50+
- RUNTIME_SUBDIRECTORY=ratelimit
51+
- RUNTIME_WATCH_ROOT=false
52+
- CONFIG_TYPE=GRPC_XDS_SOTW
53+
- CONFIG_GRPC_XDS_NODE_ID=ratelimit
54+
- CONFIG_GRPC_XDS_SERVER_URL=xds-server:18000
55+
56+
xds-server:
57+
image: protoconf/protoconf-xds:latest
58+
command:
59+
[
60+
"serve",
61+
"-nodeId",
62+
"ratelimit",
63+
"-nodeId",
64+
"mock",
65+
"-nodeId",
66+
"proxy",
67+
"-prefix",
68+
"example/envoy",
69+
"-protoconfAgentAddr",
70+
"host.docker.internal:4300",
71+
]
72+
expose:
73+
- 18000
74+
networks:
75+
- ratelimit-network
76+
# profiles:
77+
# - xds-config
78+
79+
envoy-proxy:
80+
image: envoyproxy/envoy-dev:latest
81+
entrypoint: "/usr/local/bin/envoy"
82+
command:
83+
- "--service-node proxy"
84+
- "--service-cluster proxy"
85+
- "--config-path /etc/envoy/envoy.yaml"
86+
- "--concurrency 1"
87+
- "--mode serve"
88+
- "--log-level info"
89+
volumes:
90+
- ./examples/envoy/proxy.yaml:/etc/envoy/envoy.yaml
91+
networks:
92+
- ratelimit-network
93+
expose:
94+
- "8888"
95+
- "8001"
96+
ports:
97+
- "8888:8888"
98+
- "8001:8001"
99+
100+
envoy-mock:
101+
image: envoyproxy/envoy-dev:latest
102+
entrypoint: "/usr/local/bin/envoy"
103+
command:
104+
- "--service-node mock"
105+
- "--service-cluster mock"
106+
- "--config-path /etc/envoy/envoy.yaml"
107+
- "--concurrency 1"
108+
- "--mode serve"
109+
- "--log-level info"
110+
volumes:
111+
- ./examples/envoy/mock.yaml:/etc/envoy/envoy.yaml
112+
networks:
113+
- ratelimit-network
114+
expose:
115+
- "9999"
116+
ports:
117+
- "9999:9999"
118+
119+
networks:
120+
ratelimit-network:

docs/protoconf_xds_architechture.png

207 KB
Loading

examples/envoy/mock.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
node:
2+
cluster: mock-cluster
3+
id: mock
4+
5+
dynamic_resources:
6+
ads_config:
7+
api_type: GRPC
8+
transport_api_version: V3
9+
grpc_services:
10+
- envoy_grpc:
11+
cluster_name: xds_cluster
12+
cds_config:
13+
resource_api_version: V3
14+
ads: {}
15+
lds_config:
16+
resource_api_version: V3
17+
ads: {}
18+
19+
static_resources:
20+
clusters:
21+
- type: STRICT_DNS
22+
typed_extension_protocol_options:
23+
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
24+
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
25+
explicit_http_config:
26+
http2_protocol_options: {}
27+
name: xds_cluster
28+
load_assignment:
29+
cluster_name: xds_cluster
30+
endpoints:
31+
- lb_endpoints:
32+
- endpoint:
33+
address:
34+
socket_address:
35+
address: xds-server
36+
port_value: 18000
37+
38+
admin:
39+
address:
40+
socket_address:
41+
address: 0.0.0.0
42+
port_value: 19000

examples/envoy/proxy.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
node:
2+
cluster: mock-cluster
3+
id: proxy
4+
5+
dynamic_resources:
6+
ads_config:
7+
api_type: GRPC
8+
transport_api_version: V3
9+
grpc_services:
10+
- envoy_grpc:
11+
cluster_name: xds_cluster
12+
cds_config:
13+
resource_api_version: V3
14+
ads: {}
15+
lds_config:
16+
resource_api_version: V3
17+
ads: {}
18+
19+
static_resources:
20+
clusters:
21+
- type: STRICT_DNS
22+
typed_extension_protocol_options:
23+
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
24+
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
25+
explicit_http_config:
26+
http2_protocol_options: {}
27+
name: xds_cluster
28+
load_assignment:
29+
cluster_name: xds_cluster
30+
endpoints:
31+
- lb_endpoints:
32+
- endpoint:
33+
address:
34+
socket_address:
35+
address: xds-server
36+
port_value: 18000
37+
38+
admin:
39+
address:
40+
socket_address:
41+
address: 0.0.0.0
42+
port_value: 8001
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
mappings: # Requires statsd exporter >= v0.6.0 since it uses the "drop" action.
2+
- match: "ratelimit.service.rate_limit.*.*.near_limit"
3+
name: "ratelimit_service_rate_limit_near_limit"
4+
timer_type: "histogram"
5+
labels:
6+
domain: "$1"
7+
key1: "$2"
8+
- match: "ratelimit.service.rate_limit.*.*.over_limit"
9+
name: "ratelimit_service_rate_limit_over_limit"
10+
timer_type: "histogram"
11+
labels:
12+
domain: "$1"
13+
key1: "$2"
14+
- match: "ratelimit.service.rate_limit.*.*.total_hits"
15+
name: "ratelimit_service_rate_limit_total_hits"
16+
timer_type: "histogram"
17+
labels:
18+
domain: "$1"
19+
key1: "$2"
20+
- match: "ratelimit.service.rate_limit.*.*.within_limit"
21+
name: "ratelimit_service_rate_limit_within_limit"
22+
timer_type: "histogram"
23+
labels:
24+
domain: "$1"
25+
key1: "$2"
26+
27+
- match: "ratelimit.service.rate_limit.*.*.*.near_limit"
28+
name: "ratelimit_service_rate_limit_near_limit"
29+
timer_type: "histogram"
30+
labels:
31+
domain: "$1"
32+
key1: "$2"
33+
key2: "$3"
34+
- match: "ratelimit.service.rate_limit.*.*.*.over_limit"
35+
name: "ratelimit_service_rate_limit_over_limit"
36+
timer_type: "histogram"
37+
labels:
38+
domain: "$1"
39+
key1: "$2"
40+
key2: "$3"
41+
- match: "ratelimit.service.rate_limit.*.*.*.total_hits"
42+
name: "ratelimit_service_rate_limit_total_hits"
43+
timer_type: "histogram"
44+
labels:
45+
domain: "$1"
46+
key1: "$2"
47+
key2: "$3"
48+
- match: "ratelimit.service.rate_limit.*.*.*.within_limit"
49+
name: "ratelimit_service_rate_limit_within_limit"
50+
timer_type: "histogram"
51+
labels:
52+
domain: "$1"
53+
key1: "$2"
54+
key2: "$3"
55+
56+
- match: "ratelimit.service.call.should_rate_limit.*"
57+
name: "ratelimit_service_should_rate_limit_error"
58+
match_metric_type: counter
59+
labels:
60+
err_type: "$1"
61+
62+
- match: "ratelimit_server.*.total_requests"
63+
name: "ratelimit_service_total_requests"
64+
match_metric_type: counter
65+
labels:
66+
grpc_method: "$1"
67+
68+
- match: "ratelimit_server.*.response_time"
69+
name: "ratelimit_service_response_time_seconds"
70+
timer_type: histogram
71+
labels:
72+
grpc_method: "$1"
73+
74+
- match: "ratelimit.service.config_load_success"
75+
name: "ratelimit_service_config_load_success"
76+
match_metric_type: counter
77+
- match: "ratelimit.service.config_load_error"
78+
name: "ratelimit_service_config_load_error"
79+
match_metric_type: counter
80+
81+
- match: "ratelimit.service.rate_limit.*.*.*.shadow_mode"
82+
name: "ratelimit_service_rate_limit_shadow_mode"
83+
timer_type: "histogram"
84+
labels:
85+
domain: "$1"
86+
key1: "$2"
87+
key2: "$3"
88+
89+
# Enable below in production once you have the metrics you need
90+
# - match: "."
91+
# match_type: "regex"
92+
# action: "drop"
93+
# name: "dropped"

0 commit comments

Comments
 (0)