-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* `RateLimitInfraIR` - holds the config to manage the ratelimit service. * `global-ratelimit` runner that subscribes to `XdsIR` messages and translates it to `RateLimitInfraIR`. * enhance the `infrastructure` runner to subscribe to `RateLimitInfraIR` messages and translate it into platform specific ratelimit resources. Relates to #670 Signed-off-by: Arko Dasgupta <arko@tetrate.io>
- Loading branch information
Showing
9 changed files
with
273 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package runner | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/envoyproxy/gateway/internal/envoygateway/config" | ||
"github.com/envoyproxy/gateway/internal/globalratelimit" | ||
"github.com/envoyproxy/gateway/internal/message" | ||
) | ||
|
||
type Config struct { | ||
config.Server | ||
XdsIR *message.XdsIR | ||
RateLimitInfraIR *message.RateLimitInfraIR | ||
} | ||
|
||
type Runner struct { | ||
Config | ||
} | ||
|
||
func (r *Runner) Name() string { | ||
return "global-ratelimit" | ||
} | ||
|
||
func New(cfg *Config) *Runner { | ||
return &Runner{Config: *cfg} | ||
} | ||
|
||
// Start starts the infrastructure runner | ||
func (r *Runner) Start(ctx context.Context) error { | ||
r.Logger = r.Logger.WithValues("runner", r.Name()) | ||
go r.subscribeAndTranslate(ctx) | ||
r.Logger.Info("started") | ||
return nil | ||
} | ||
|
||
func (r *Runner) subscribeAndTranslate(ctx context.Context) { | ||
// Subscribe | ||
xdsIRCh := r.XdsIR.Subscribe(ctx) | ||
for ctx.Err() == nil { | ||
select { | ||
case snapshot := <-xdsIRCh: | ||
r.Logger.Info("received a notification") | ||
xdsIRMap := make(globalratelimit.XdsIRMap) | ||
for key, value := range snapshot.State { | ||
xdsIRMap[key] = value | ||
} | ||
// Translate to ratelimit infra IR | ||
result, err := globalratelimit.Translate(xdsIRMap) | ||
if err != nil { | ||
r.Logger.Error(err, "failed to translate xds ir") | ||
} else { | ||
if result == nil { | ||
r.RateLimitInfraIR.Delete(r.Name()) | ||
} else { | ||
// Publish ratelimit infra IR | ||
r.RateLimitInfraIR.Store(r.Name(), result) | ||
} | ||
} | ||
} | ||
} | ||
r.Logger.Info("subscriber shutting down") | ||
} |
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,18 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package globalratelimit | ||
|
||
import ( | ||
"github.com/envoyproxy/gateway/internal/ir" | ||
) | ||
|
||
type XdsIRMap map[string]*ir.Xds | ||
|
||
// Translate converts the xdsIR into the rate limit infra IR. | ||
func Translate(xdsIRMap XdsIRMap) (*ir.RateLimitInfra, error) { | ||
// TODO | ||
return nil, nil | ||
} |
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
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,40 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package ir | ||
|
||
// RateLimitInfra defines the managed ratelimit infrastructure. | ||
// +k8s:deepcopy-gen=true | ||
type RateLimitInfra struct { | ||
// Service holds the envoy rate limit service | ||
// configuration | ||
Service *RateLimitService | ||
|
||
} | ||
|
||
// RateLimitInfra defines managed rate limit service infrastructure. | ||
// +k8s:deepcopy-gen=true | ||
type RateLimitService struct { | ||
// Config holds the YAML string representing the | ||
// Rate limit service configuration | ||
// https://github.com/envoyproxy/ratelimit#configuration-1 | ||
Config *string | ||
// Backend holds configuration associated with the backend database. | ||
// If nil, the ratelimit runner deploys a demo redis instance (should not be used in production). | ||
Backend *RateLimitDBBackend | ||
} | ||
|
||
// RateLimitDBBackend defines the database backend properties | ||
// associated with the rate limit service. | ||
// +k8s:deepcopy-gen=true | ||
type RateLimitDBBackend struct { | ||
Redis *RateLimitRedis | ||
} | ||
|
||
// RateLimitRedis defines the redis database configuration. | ||
// +k8s:deepcopy-gen=true | ||
type RateLimitRedis struct { | ||
// TODO https://github.com/envoyproxy/ratelimit#redis | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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