Skip to content

Commit

Permalink
Caching (#2935)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced caching capabilities to the FlowControlService with new
RPCs for cache management.
- Added cache key and value fields to request and response messages for
enhanced service functionality.
- Implemented a new cache package with upsert and delete operations for
distributed caching.
- Expanded SDKs with new cache-related types and methods for managing
cached values.

- **Enhancements**
  - Updated SDKs to include new cache-related RPCs and message types.
- Improved error handling and added new utility functions in SDKs for
better integration with caching features.
- Refactored existing code to accommodate caching logic and improve
readability.

- **Documentation**
- Updated example usage in SDKs to demonstrate new caching features and
API changes.

- **Refactor**
- Renamed packages and updated import paths to align with new caching
functionality.
  - Replaced logging packages for consistency across the codebase.

- **Style**
- Made minor adjustments to code formatting for better consistency and
readability.

- **Chores**
- Updated Makefile to copy new generated SDK stubs for flow control to
respective SDK directories.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Hasit Mistry <hasit@fluxninja.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 20, 2023
1 parent d379149 commit 489d5e7
Show file tree
Hide file tree
Showing 93 changed files with 25,324 additions and 2,434 deletions.
5 changes: 5 additions & 0 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ buf-generate:

@#generate sdk flowcontrol stubs and copy them over

@#golang
@rm -rf ../sdks/aperture-go/gen/proto/flowcontrol/*
@cp -R gen/proto/go/aperture/flowcontrol/check ../sdks/aperture-go/gen/proto/flowcontrol/
@cp -R gen/proto/go/aperture/flowcontrol/checkhttp ../sdks/aperture-go/gen/proto/flowcontrol/

@#csharp
@rm -rf ../sdks/aperture-csharp/Generated/Aperture/Flowcontrol/
@cp -R gen/proto/csharp/Aperture/Flowcontrol/Check ../sdks/aperture-csharp/Generated/Aperture/Flowcontrol/
Expand Down
45 changes: 45 additions & 0 deletions api/aperture/flowcontrol/check/v1/check.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import "google/protobuf/timestamp.proto";
service FlowControlService {
// Check wraps the given arbitrary resource and matches the given labels against Flow Control Limiters to makes a decision whether to allow/deny.
rpc Check(CheckRequest) returns (CheckResponse) {}
rpc CacheUpsert(CacheUpsertRequest) returns (CacheUpsertResponse) {}
rpc CacheDelete(CacheDeleteRequest) returns (CacheDeleteResponse) {}
}

// CheckRequest contains fields required to perform Check call.
message CheckRequest {
string control_point = 1;
map<string, string> labels = 2;
bool ramp_mode = 3;
// Cache item to fetch.
string cache_key = 4;
}

// CheckResponse contains fields that represent decision made by Check call.
Expand Down Expand Up @@ -63,6 +67,47 @@ message CheckResponse {
// http_status contains the http status code to be returned to the client, if
// decision_type is REJECTED. Optional.
StatusCode denied_response_status_code = 14;
// Matching cached value.
CachedValue cached_value = 15;
}

enum CacheLookupStatus {
HIT = 0;
MISS = 1;
}

enum CacheOperationStatus {
SUCCESS = 0;
ERROR = 1;
}

message CachedValue {
bytes value = 1;
CacheLookupStatus lookup_status = 2;
CacheOperationStatus operation_status = 3;
string error = 4;
}

message CacheUpsertRequest {
string control_point = 1;
string key = 2;
bytes value = 3;
google.protobuf.Duration ttl = 4;
}

message CacheUpsertResponse {
CacheOperationStatus operation_status = 1;
string error = 2;
}

message CacheDeleteRequest {
string control_point = 1;
string key = 2;
}

message CacheDeleteResponse {
CacheOperationStatus operation_status = 1;
string error = 2;
}

// ClassifierInfo describes details for each ClassifierInfo.
Expand Down
Loading

0 comments on commit 489d5e7

Please sign in to comment.