Skip to content

Commit f6942e5

Browse files
committed
feat: rate limit
feat: add ratelimit implementation
1 parent edc90a0 commit f6942e5

File tree

1,073 files changed

+397
-86770
lines changed

Some content is hidden

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

1,073 files changed

+397
-86770
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.pconf linguist-language=Starlark
2+
*.mpconf linguist-language=Starlark
3+
*.pinc linguist-language=Starlark
4+
*.proto-validator linguist-language=Starlark
5+
*.materialized_JSON linguist-language=json
6+
# *.materialized_JSON linguist-generated # uncomment this line if you wish to hide these changes during code reviews (not recommended)

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919

2020
# Go workspace file
2121
go.work
22-
dist
22+
dist
23+
.protoconf_cache

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"protoc": { "options": ["-I", "src"] },
3+
"files.associations": {
4+
"*.pconf": "Starlark",
5+
"*.mpconf": "Starlark",
6+
"*.pinc": "Starlark",
7+
"*.proto-validator": "Starlark",
8+
"*.materialized_JSON": "json"
9+
}
10+
}

CONFIGSPACE

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
envoy = remote_repo(
2+
url="github.com/envoyproxy/data-plane-api",
3+
commit="54a58fd",
4+
# load protos from repo's root (default is to load from `/src`)
5+
additional_proto_dirs=["."],
6+
# patterns to exclude (mainly to avoid proto files duplications)
7+
exclude_file_regexps=[
8+
"^google/.*",
9+
"^bazel/.*",
10+
],
11+
)
12+
ratelimit = remote_repo(
13+
url="github.com/envoyproxy/ratelimit",
14+
commit="19f2079",
15+
additional_proto_dirs=["api"],
16+
exclude_file_regexps=["^google/.*"],
17+
)
18+
19+
xds = remote_repo(
20+
url="github.com/cncf/xds",
21+
commit="0335649",
22+
additional_proto_dirs=["."],
23+
)
24+
25+
GOOGLE_APIS_COMMIT = "cbe62016a4eb24e71186899b79b9a4736f858653"
26+
googleapis = remote_repo(
27+
url="https://github.com/googleapis/googleapis/archive/{0}.zip//googleapis-{0}/".format(
28+
GOOGLE_APIS_COMMIT
29+
),
30+
# commit="cbe6201",
31+
additional_proto_dirs=["."],
32+
exclude_file_regexps=[
33+
"^google/api/.*.proto",
34+
"^google/rpc/.*.proto",
35+
"^google/iam/.*.proto",
36+
"^google/type/.*.proto",
37+
"^google/storage/.*.proto",
38+
],
39+
)
40+
41+
# xds = remote_repo(
42+
# url="github.com/protoconf/protoconf-xds",
43+
# branch="main",
44+
# exclude_file_regexps=[
45+
# "google/.*",
46+
# "envoy/.*",
47+
# "io/prometheus/.*",
48+
# "opencensus/.*",
49+
# "opentelemetry/.*",
50+
# "udpa/.*",
51+
# "validate/.*",
52+
# ],
53+
# )

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM envoyproxy/envoy:dev-334a50e7ab10ff3247c300fdf32a2425e9deaa55
1+
FROM envoyproxy/envoy:dev-7f6df241c61094c6e1ec26c8d1acf05f5803a32c
22
COPY envoy.yaml /etc/envoy/envoy.yaml
33
RUN chmod go+r /etc/envoy/envoy.yaml

buf.gen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version: v1
22
plugins:
33
- name: go
4-
out: .
4+
out: src
55
opt: paths=source_relative

buf.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: v1
1+
version: v1beta1
22
deps:
33
- buf.build/googleapis/googleapis:62f35d8aed1149c291d606d958a7ce32
44
- buf.build/opencensus/opencensus
@@ -26,6 +26,8 @@ lint:
2626
- envoy/api/v2/listener.proto
2727
- envoy/config/bootstrap/v2/bootstrap.proto
2828
build:
29+
roots:
30+
- src
2931
excludes:
3032
- src/xds
3133
- src/validate
@@ -34,3 +36,4 @@ build:
3436
- src/google
3537
- src/opentelemetry
3638
- src/opencensus
39+
- src/io

cmd/serve/serve.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"path/filepath"
2424
"strings"
25+
"syscall"
2526

2627
"github.com/avast/retry-go"
2728
clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
@@ -31,6 +32,7 @@ import (
3132
routev3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
3233
tlsv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
3334
runtimev3 "github.com/envoyproxy/go-control-plane/envoy/service/runtime/v3"
35+
ratelimitv3 "github.com/envoyproxy/go-control-plane/ratelimit/config/ratelimit/v3"
3436
"github.com/mitchellh/cli"
3537
"github.com/stephenafamo/orchestra"
3638

@@ -148,6 +150,7 @@ func (c *Command) Run(args []string) int {
148150
resource.SecretType: makeSecrets(xdsRecord.Secrets),
149151
resource.ExtensionConfigType: makeExtensionConfigs(xdsRecord.ExtentionConfigs),
150152
resource.RuntimeType: makeRuntimes(xdsRecord.Runtimes),
153+
resource.RateLimitConfigType: makeRatelimits(xdsRecord.Ratelimits),
151154
})
152155
if err != nil {
153156
c.logger.Errorf("%v", err)
@@ -168,7 +171,7 @@ func (c *Command) Run(args []string) int {
168171
ctx := context.Background()
169172
cb := &test.Callbacks{Debug: c.logger.Debug}
170173
srv := server.NewServer(ctx, xdsCache, cb)
171-
err = orchestra.PlayUntilSignal(orchestra.PlayerFunc(xds.GeneratePlayer(srv, uint(c.config.Port))))
174+
err = orchestra.PlayUntilSignal(orchestra.PlayerFunc(xds.GeneratePlayer(srv, uint(c.config.Port))), syscall.SIGINT, syscall.SIGTERM)
172175
if err != nil {
173176
c.logger.Errorf("grpc server return error: %v", err)
174177
return 1
@@ -230,3 +233,10 @@ func makeRuntimes(input []*runtimev3.Runtime) (ret []types.Resource) {
230233
}
231234
return ret
232235
}
236+
237+
func makeRatelimits(input []*ratelimitv3.RateLimitConfig) (ret []types.Resource) {
238+
for _, item := range input {
239+
ret = append(ret, item)
240+
}
241+
return ret
242+
}

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ require (
1616

1717
require (
1818
github.com/Masterminds/goutils v1.1.1 // indirect
19-
github.com/Masterminds/semver v1.5.0 // indirect
2019
github.com/Masterminds/semver/v3 v3.2.0 // indirect
21-
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
2220
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
2321
github.com/armon/go-radix v1.0.0 // indirect
2422
github.com/bgentry/speakeasy v0.1.0 // indirect

0 commit comments

Comments
 (0)