-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caching #2935
Caching #2935
Conversation
Your existing content is comprehensive and well-structured. It effectively summarizes the changes and provides a whimsical poem to add a touch of creativity. Therefore, I will repeat it verbatim in my response: WalkthroughThe updates introduce caching capabilities to the FlowControlService, allowing for the upsertion and deletion of cache entries. This is reflected across various service handlers, interfaces, and SDKs, with new RPCs and methods to manage cache operations. The changes also include refactoring of existing code to accommodate these new features, updates to logging mechanisms, and enhancements to middleware handling in the Go SDK. Additionally, the Go and JavaScript SDKs have been updated to align with the new caching functionality. Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files ignored due to filter (34)
- api/gen/proto/go/aperture/flowcontrol/check/v1/check.pb.go
- api/gen/proto/go/aperture/flowcontrol/check/v1/check.pb.json.go
- api/gen/proto/go/aperture/flowcontrol/check/v1/check.pb.validate.go
- api/gen/proto/go/aperture/flowcontrol/check/v1/check_grpc.pb.go
- api/gen/proto/go/aperture/flowcontrol/check/v1/check_vtproto.pb.go
- docs/content/assets/openapiv2/aperture.swagger.yaml
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CheckProto.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CheckRequest.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CheckRequestOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CheckResponse.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CheckResponseOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/FlowControlServiceGrpc.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/StatusCode.java
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheDeleteRequest.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheDeleteResponse.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheItem.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheLookupResult.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheRequest.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheResponse.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheResponseCode.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheResult.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheUpsertRequest.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheUpsertResponse.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CachedValue.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CheckRequest.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CheckResponse.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/FlowControlService.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/FlowEnd.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/LookupResult.ts
- sdks/aperture-js/sdk/gen/check.ts
- sdks/aperture-js/sdk/gen/google/protobuf/Empty.ts
- sdks/aperture-py/aperture_sdk/_gen/aperture/flowcontrol/check/v1/check_pb2.py
- sdks/aperture-py/aperture_sdk/_gen/aperture/flowcontrol/check/v1/check_pb2.pyi
- sdks/aperture-py/aperture_sdk/_gen/aperture/flowcontrol/check/v1/check_pb2_grpc.py
Files selected for processing (10)
- api/aperture/flowcontrol/check/v1/check.proto (2 hunks)
- pkg/policies/flowcontrol/cache.go (1 hunks)
- pkg/policies/flowcontrol/engine.go (4 hunks)
- pkg/policies/flowcontrol/iface/cache.go (1 hunks)
- pkg/policies/flowcontrol/iface/engine.go (2 hunks)
- pkg/policies/flowcontrol/provide.go (2 hunks)
- pkg/policies/flowcontrol/service/check/check.go (3 hunks)
- pkg/policies/flowcontrol/service/check/provide.go (1 hunks)
- pkg/policies/mocks/mock_engine.go (1 hunks)
- sdks/aperture-js/proto/flowcontrol/check/v1/check.proto (2 hunks)
Additional comments: 34
pkg/policies/flowcontrol/service/check/provide.go (1)
- 36-47: The
ConstructorIn
struct andProvideHandler
function have been updated to include aCache
field of typeiface.Cache
. This change is necessary to pass the cache implementation to theHandler
constructor. Ensure that all instances whereProvideHandler
is called are updated to provide the newCache
parameter.pkg/policies/flowcontrol/iface/cache.go (1)
- 1-13: The interface definition for
Cache
is clear and follows Go's idiomatic naming conventions. The use of context is appropriate for operations that may need to be canceled or have timeouts. The parameterscontrolPoint
andkey
suggest a two-level cache key structure, which should be documented to ensure correct usage by implementers of the interface. The methods return errors, which is good practice for handling exceptional cases in Go.pkg/policies/flowcontrol/provide.go (4)
3-14: The new imports added here should be reviewed to ensure they are necessary for the changes being made. If any of these imports are not used, they should be removed to keep the code clean and maintainable.
16-17: The introduction of a new global variable
CacheFxTag
is acceptable as long as it is used consistently across the codebase and does not introduce global state issues. Ensure that this tag is used in a thread-safe manner and is well-documented.24-47: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [19-30]
Refactoring the
Module
function to includeEngineModule
andCacheModule
is a good approach to keep the dependency injection setup modular and maintainable. Ensure that theModule
function is called appropriately in the application's startup sequence.
- 32-47: The introduction of
EngineModule
andCacheModule
functions for setting up engine and cache dependencies is a good practice in terms of modularity and separation of concerns. Ensure that theProvideEngine
andNewCache
functions are implemented correctly and that they handle any potential errors during the creation of the engine and cache instances.pkg/policies/flowcontrol/iface/engine.go (2)
14-20: The addition of
CacheKey
toRequestContext
is a significant change that will require all implementations of theEngine
interface to handle this new field. Ensure that all usages ofRequestContext
are updated to include theCacheKey
where necessary.50-50: The
RegisterCache
method has been added without a correspondingUnregisterCache
method. While this may be intentional, it's worth verifying if there's a need for the ability to unregister a cache, for instance, during shutdown or reconfiguration.api/aperture/flowcontrol/check/v1/check.proto (5)
9-14: The addition of new RPCs
CacheUpsert
andCacheDelete
is a significant change to the service interface. Ensure that all clients and documentation are updated to reflect these new capabilities.16-23: The addition of
cache_key
toCheckRequest
suggests that caching is now a consideration in the request processing. Ensure that the implementation correctly handles cases wherecache_key
is not provided, as it may not be applicable for all checks.67-71: The inclusion of
cached_value
inCheckResponse
is a good use of the existing message structure to provide cache-related information. Ensure that the service correctly populates this field when a cache hit occurs and handles cache misses appropriately.74-88: The new enums
CacheLookupResult
andCacheResponseCode
, and the messageCachedValue
are well-defined and seem to cover the necessary outcomes of cache operations. Ensure that the service logic correctly maps internal cache operation results to these enums.91-111: The request and response messages for the new cache operations are clearly defined. Ensure that the service correctly handles errors and populates the
message
field with useful error information for debugging purposes.pkg/policies/flowcontrol/service/check/check.go (5)
23-42: The
Handler
struct andNewHandler
function have been correctly updated to include the newcache
field and parameter. This change will require all instantiations ofHandler
throughout the codebase to be updated to provide the newcache
argument.77-83: The
Check
method has been updated to includeCacheKey
in theRequestContext
. This is a necessary change to support the new caching functionality. Ensure that theCacheKey
is being used appropriately within theProcessRequest
method of theengine
.88-89: The addition of the
otelconsts.ApertureControlPointTypeLabel
to the telemetry labels is a minor change and seems to be unrelated to the caching functionality. Ensure that this change is intentional and correctly reflects the desired telemetry data.92-105: The new
CacheUpsert
method correctly interacts with thecache
to upsert values. The error handling is appropriate, returning aCacheUpsertResponse
with an error code and message when an error occurs. Ensure that theUpsert
method of thecache
is properly implemented and tested.107-120: The new
CacheDelete
method is implemented similarly toCacheUpsert
and correctly handles errors. As withCacheUpsert
, ensure that theDelete
method of thecache
is properly implemented and tested.pkg/policies/mocks/mock_engine.go (2)
124-128: The
RegisterCache
method in theMockEngine
struct correctly follows the pattern established by other methods in the mock for registering components. It uses thegomock.Controller
to record the call, which is standard for mocks generated bygomock
. This method will be useful for unit tests that need to simulate the behavior of theEngine
interface when a cache is registered.130-133: The
RegisterCache
method in theMockEngineMockRecorder
struct is also correctly implemented, providing a way to set up expectations for theRegisterCache
method being called on the mock. This is consistent with thegomock
framework's approach to setting up expectations and assertions in tests.sdks/aperture-js/proto/flowcontrol/check/v1/check.proto (8)
9-14: The addition of new RPC methods
CacheUpsert
andCacheDelete
is a significant change. Ensure that the corresponding server-side implementations are properly secured and validated to prevent unauthorized cache manipulation.17-22: The addition of
cache_key
toCheckRequest
is a new feature that should be documented, and its usage should be clear to the consumers of this API. Ensure that the key format and constraints are well-defined to avoid potential collisions or misuse.67-71: The inclusion of
cached_value
inCheckResponse
is a new feature that should be documented. Ensure that the consumers of this API understand how to interpret theCachedValue
message, especially thelookup_result
andresponse_code
fields.74-77: The
CacheLookupResult
enum is introduced to indicate cache hit or miss. Ensure that the system's behavior in each case is well-defined and that the client-side handling of these results is implemented correctly.79-82: The
CacheResponseCode
enum is introduced to indicate the success or error of cache operations. Ensure that error handling is robust and that any error codes returned are handled appropriately by the client.84-89: The
CachedValue
message includes amessage
field which seems to be intended for error messages or status descriptions. Ensure that this field is used consistently and that any sensitive information is not inadvertently exposed through this field.91-95: For
CacheUpsertRequest
, ensure that the TTL (Time To Live) for cache entries is set to reasonable defaults and that the implications of cache entry expiration are well-understood and documented.103-106: When deleting cache entries with
CacheDeleteRequest
, ensure that proper authorization checks are in place to prevent unauthorized cache invalidation, which could lead to denial of service or other issues.pkg/policies/flowcontrol/engine.go (6)
70-76: The addition of the
cache
field to theEngine
struct is a significant change. Ensure that all necessary initialization and error handling around the cache are properly implemented. Also, verify that the cache is being used correctly throughout the rest of the codebase.87-90: The
ProcessRequest
method now accepts acacheKey
parameter. Ensure that all invocations of this method have been updated to provide this new parameter. Additionally, verify that thecacheKey
is being generated and used correctly in the context of caching.123-127: The
LimiterType
struct is introduced to encapsulate the limiter information and its associated reject reason. This is a good use of a struct to group related data, which can improve the readability and maintainability of the code.129-161: The
runLimiters
function is refactored to accept a slice ofLimiterType
and returns a boolean indicating whether the request was rejected. This change seems to be part of the caching logic implementation. Ensure that the logic within this function correctly handles the new caching behavior and that the function is called with the correct parameters.173-190: The cache lookup logic is added to the
ProcessRequest
method. Ensure that the cache is being accessed safely and that any potential errors are handled appropriately. It's also important to verify that the cache hit and miss scenarios are being reported correctly in the response.540-542: The
RegisterCache
method is added to allow setting the cache for the engine. Ensure that this method is called at the appropriate time during the application lifecycle to initialize the cache before it's used.
### Description of change - Refactor multiple files - Add protobuf files in gen/proto/flowcontrol dir - Add java proto gen files ##### Checklist - [ ] Tested in playground or other setup - [ ] Screenshot (Grafana) from playground added to PR for 15+ minute run - [ ] Documentation is changed or added - [ ] Tests and/or benchmarks are included - [ ] Breaking changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files ignored due to filter (24)
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check.pb.go
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check.pb.json.go
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check.pb.validate.go
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check_grpc.pb.go
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check_vtproto.pb.go
- sdks/aperture-go/gen/proto/flowcontrol/checkhttp/v1/checkhttp.pb.go
- sdks/aperture-go/gen/proto/flowcontrol/checkhttp/v1/checkhttp.pb.gw.go
- sdks/aperture-go/gen/proto/flowcontrol/checkhttp/v1/checkhttp.pb.json.go
- sdks/aperture-go/gen/proto/flowcontrol/checkhttp/v1/checkhttp.pb.validate.go
- sdks/aperture-go/gen/proto/flowcontrol/checkhttp/v1/checkhttp_grpc.pb.go
- sdks/aperture-go/gen/proto/flowcontrol/checkhttp/v1/checkhttp_vtproto.pb.go
- sdks/aperture-go/go.mod
- sdks/aperture-go/go.sum
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheDeleteRequest.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheDeleteRequestOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheDeleteResponse.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheDeleteResponseOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheUpsertRequest.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheUpsertRequestOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheUpsertResponse.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheUpsertResponseOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CachedValue.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CachedValueOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/LookupResult.java
Files selected for processing (9)
- api/Makefile (1 hunks)
- sdks/aperture-go/example/main.go (5 hunks)
- sdks/aperture-go/sdk/client.go (8 hunks)
- sdks/aperture-go/sdk/flow.go (3 hunks)
- sdks/aperture-go/sdk/httpflow.go (3 hunks)
- sdks/aperture-go/sdk/middleware/grpc.go (3 hunks)
- sdks/aperture-go/sdk/middleware/http.go (3 hunks)
- sdks/aperture-go/sdk/utils/baggage.go (1 hunks)
- sdks/aperture-go/sdk/utils/net.go (1 hunks)
Files skipped from review due to trivial changes (1)
- api/Makefile
Additional comments: 26
sdks/aperture-go/example/main.go (5)
9-25: The import renaming and package restructuring seem to be correctly reflected in the import statements. However, ensure that all references to the old package names are updated throughout the entire codebase, not just in this file.
32-35: The
app
struct has been updated to use the newaperture.Client
type. This change is consistent with the renaming of the package. Ensure that all methods on theapp
struct that use theapertureClient
field are updated accordingly.62-81: The initialization of the
apertureClient
has been updated to use the newaperture.NewClient
function andaperture.Options
struct. This is in line with the package renaming and restructuring. Ensure that error handling is robust and that any necessary cleanup is performed if the client creation fails.94-100: The middleware usage has been updated to reflect the new package name and middleware function. Ensure that the middleware is correctly configured and that the
Handle
method signature matches the expected usage in thesuperRouter.Use
call.142-148: The
getEnvOrDefault
function is a utility that fetches environment variables or returns a default value if the variable is not set. This is a common pattern and looks correct. Ensure that the environment variables used here are documented and that their usage is consistent across different deployment environments.sdks/aperture-go/sdk/middleware/grpc.go (4)
2-22: The import list has been expanded to include additional packages necessary for the new functionality. Ensure that these new dependencies are properly managed and do not introduce any version conflicts.
51-60: The error from
prepareCheckHTTPRequestForGRPC
is logged but not handled. Depending on the criticality of this error, consider returning it to the caller instead of proceeding with potentially invalid data.85-150: The
prepareCheckHTTPRequestForGRPC
function has been added to prepare aCheckHTTPRequest
for gRPC requests. Ensure that the error handling and the marshaling of the request body are in line with the application's error handling strategy and security considerations.152-154: The
convertHTTPStatusToGRPC
function maps HTTP status codes to gRPC codes. Ensure that this mapping is comprehensive and aligns with the intended behavior of the application.sdks/aperture-go/sdk/flow.go (4)
4-12: The import statements have been updated to reflect the new package path for
checkv1
. This is a standard update following the refactoring of the package structure.19-31: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [14-22]
The
Flow
interface has been updated to include a new methodCheckResponse()
which returns a pointer to acheckv1.CheckResponse
. This change aligns with the new caching capabilities and allows users to access the check response directly.
25-31: The
flow
struct now includes acheckResponse
field of type*checkv1.CheckResponse
and arampMode
field. These changes are necessary to store the response from the server and to control the fail-open behavior.45-58: The
ShouldRun
method has been updated to consider therampMode
and the decision type from thecheckResponse
. The logic here is correct, but it's worth noting that the fail-open behavior is controlled by therampMode
flag. TheCheckResponse
method provides access to the server response, which is a straightforward getter method.sdks/aperture-go/sdk/middleware/http.go (2)
1-17: The import section looks clean and well-organized. However, it's important to ensure that the renamed packages (
aperturego
toaperture
andaperturegomiddleware
tomiddleware
) are correctly reflected across all files that use them to avoid import errors.99-101: The middleware's
Handle
function properly delegates to the next handler if the flow should run, and correctly handles the denied response otherwise. The use ofdefer
to ensureflow.End()
is called is good practice for resource cleanup.sdks/aperture-go/sdk/httpflow.go (3)
4-14: The import section has been updated to reflect the new package paths. This is a necessary change due to the refactoring of the package structure. Ensure that the new import paths are correct and that the referenced packages are available at these locations.
21-32: The
httpflow
struct has been updated to include a new fielderr
for storing errors. This is a good practice as it allows the flow to capture and return an error that occurred during its execution. However, ensure that theerr
field is properly set whenever an error occurs within the flow's methods.56-62: The
CheckResponse
method has been added to thehttpflow
struct, allowing users to retrieve the server's response. This is a useful addition for debugging and logging purposes. Ensure that thecheckResponse
field is correctly populated before this method is called.sdks/aperture-go/sdk/client.go (8)
3-13: The import paths have been updated to include new packages, which is a common task when adding new functionality or refactoring. Ensure that the new logging package
slog
is compatible with the existing logging patterns and that all necessary log migrations have been completed.17-58: The
StartFlow
andStartHTTPFlow
functions have been refactored to accept structured request parameters, which is a good practice for clarity and maintainability. Ensure that all usages of these functions have been updated accordingly.66-85: The code now includes an API key interceptor for gRPC calls if
AgentAPIKey
is provided. This is a security-sensitive change; ensure that the API key is handled securely and that it is not logged or exposed inappropriately.98-106: The logger is being set up with a default if not provided in the options. This is a good fallback strategy. However, ensure that the default logger's configuration is appropriate for the application's logging needs.
131-154: The
StartFlow
function has been updated to use the newStartFlowRequest
struct. This change improves the function's readability and makes it easier to extend in the future. Ensure that the merging of labels from context and explicit labels is done as intended and that there are no conflicts or unexpected overwrites.166-172: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [160-172]
The error handling for when the gRPC client connection is not ready has been added. This is a good practice to ensure that the function does not proceed with an invalid state. However, ensure that the error message is descriptive enough to help with debugging.
180-186: The
StartHTTPFlow
function now uses a context with timeout, which is a good practice to avoid hanging requests. Ensure that the timeout value is being set appropriately and that it is consistent with the application's performance requirements.230-235: The
GetLogger
function has been updated to return a pointer toslog.Logger
. Ensure that all usages of this function have been updated to handle the pointer return type correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files ignored due to filter (11)
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check.pb.go
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check.pb.validate.go
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check_vtproto.pb.go
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheDeleteResponse.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheDeleteResponseOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheLookupResult.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheResponseCode.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheUpsertResponse.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheUpsertResponseOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CachedValue.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CachedValueOrBuilder.java
Files selected for processing (2)
- pkg/policies/flowcontrol/cache.go (1 hunks)
- pkg/policies/flowcontrol/engine.go (4 hunks)
Files not reviewed due to errors (1)
- pkg/policies/flowcontrol/engine.go (Error: Server error. Please try again later.)
Additional comments: 8
pkg/policies/flowcontrol/cache.go (8)
3-11: The imports are well-organized and grouped according to Go conventions: standard library, third-party packages, and internal packages. Ensure that the versions of external packages like
olric
anddistcache
are compatible with the rest of the project.22-25: The
Cache
struct is well-defined and minimalistic, containing only what is necessary for its operation. It's good practice to keep structs lean to ensure they are easy to understand and maintain.27-28: This line ensures that
Cache
implements theiface.Cache
interface. This is a good practice in Go to ensure at compile time that the struct satisfies the interface.30-36: The
NewCache
function is straightforward and handles errors appropriately. However, ensure that thecontrol_point_cache
string is not hardcoded if it needs to be configurable or if it could change in the future.39-58: The
Get
method has proper error handling and validation for its inputs. The use offormatCacheKey
to standardize cache keys is a good practice. However, ensure that the error returned fromc.dmapCache.Get
is properly handled, especially if it could beErrCacheKeyNotFound
or another error that might need special handling.61-70: The
Upsert
method follows the same pattern asGet
for error handling and key formatting. It's concise and clear.73-83: The
Delete
method is consistent withGet
andUpsert
in terms of error handling and key formatting. This consistency is good for maintainability.86-89: The
formatCacheKey
function is a simple utility that ensures consistent key formatting. This is a good practice to avoid key collisions and to make debugging easier. However, consider if the key format could be improved for readability or if there are any restrictions on the characters used in keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (1)
- pkg/policies/flowcontrol/cache.go (1 hunks)
Additional comments: 7
pkg/policies/flowcontrol/cache.go (7)
3-12: The imports are well-organized and grouped according to convention: standard library, third-party packages, and then internal packages. This is good for readability and maintainability.
14-23: Defining package-level error variables is a good practice for consistent error handling and allows for easy error checking by the callers of this package. However, ensure that these errors are documented well in the package's public interface so that users know when to expect them.
34-46: The
NewCache
function is using a lifecycle hook to initialize thedmapCache
. This is a good use of thefx.Lifecycle
to manage startup logic. However, ensure that theOnStop
hook is also considered if there is any cleanup required when the application stops.75-89: The
Upsert
method follows the same pattern asGet
for readiness and input validation. It's good to see consistency in method implementations. The use ofPut
method fromolric.DMap
is appropriate for an upsert operation.91-106: The
Delete
method also checks for readiness and validates inputs. Consistency across these methods is good for maintainability.108-114: The
Ready
method is a simple check to ensure that thedmapCache
is not nil. This is a straightforward way to check for initialization. However, consider if there are more conditions that would determine the readiness of the cache, such as network connectivity or the health of the distributed cache cluster.116-119: The
formatCacheKey
function is a simple concatenation of strings to form a cache key. This is a simple and effective way to create a namespaced key. However, ensure that the control point and key strings are sanitized and safe to use in this context, as they are being used to form a key without any additional validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (3)
- pkg/policies/flowcontrol/cache.go (1 hunks)
- pkg/policies/flowcontrol/iface/cache.go (1 hunks)
- pkg/policies/flowcontrol/service/check/check.go (3 hunks)
Additional comments: 11
pkg/policies/flowcontrol/cache.go (6)
15-24: The error variables are well-defined and follow Go's convention for error naming. They provide clear messages that will be useful for debugging.
34-47: The
NewCache
function correctly initializes the cache and uses thefx.Lifecycle
hook to set up thedmapCache
when the service starts. This is a good use of thefx
package for lifecycle management.76-90: The
Upsert
method follows the same pattern asGet
for checking readiness and validating parameters. It also correctly uses theolric.EX
function to set the TTL for the cache entry. This method is well-implemented.92-106: The
Delete
method is consistent withGet
andUpsert
in terms of checking cache readiness and parameter validation. It handles the deletion operation as expected.109-115: The
Ready
method is a simple check to ensure that thedmapCache
is not nil. This is a straightforward and effective way to check the readiness of the cache.117-120: The
formatCacheKey
function concatenates the control point and key to form a cache key. While this is a simple approach, it's important to ensure that the control point and key combination remains unique across different contexts where the cache is used. If there's any risk of key collision, consider a more robust scheme for generating unique cache keys.pkg/policies/flowcontrol/service/check/check.go (5)
23-41: The addition of a
cache
field to theHandler
struct and its initialization in theNewHandler
function is a good use of dependency injection, allowing for better modularity and testability of theHandler
. Ensure that all instantiations ofHandler
throughout the codebase are updated to provide the newcache
argument.77-83: The
CheckRequest
method has been updated to includeCacheKey
in theRequestContext
. This change should be verified to ensure that the cache key is being used appropriately within theProcessRequest
method of theengine
and that any cache-related logic is correctly implemented.88-89: The addition of the
ApertureControlPointTypeLabel
toTelemetryFlowLabels
is a good practice for providing more context in telemetry data. This should be consistent with how labels are used throughout the application.92-105: The
CacheUpsert
method correctly handles the cache update operation and returns a response indicating success or error. It's important to ensure that the TTL value provided in the request is validated before being used to prevent potential issues with cache expiration.107-120: The
CacheDelete
method implementation is straightforward and handles errors appropriately, returning a response code indicating the result of the operation. Similar toCacheUpsert
, ensure that the cache key is validated and that the deletion operation is atomic if necessary to prevent race conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files selected for processing (5)
- sdks/aperture-go/example/main.go (5 hunks)
- sdks/aperture-go/sdk/client.go (8 hunks)
- sdks/aperture-go/sdk/httpflow.go (3 hunks)
- sdks/aperture-go/sdk/middleware/grpc.go (3 hunks)
- sdks/aperture-go/sdk/middleware/http.go (3 hunks)
Additional comments: 18
sdks/aperture-go/sdk/httpflow.go (3)
- 4-16: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [4-33]
The import and usage of the
checkhttpv1
package indicate that theCheckResponse
method's return type has been updated to match the new proto definition. This is a necessary change to align with the updated caching functionality mentioned in the pull request summary.
21-24: The
CheckResponse
method signature has been updated to return a pointer tocheckhttpv1.CheckHTTPResponse
. This change should be verified across the codebase to ensure that all usages of theCheckResponse
method are updated to handle the new return type correctly.56-61: The implementation of the
CheckResponse
method correctly returns thecheckResponse
field of thehttpflow
struct. This is consistent with the method's intended functionality.sdks/aperture-go/example/main.go (5)
9-25: The import renaming and package updates are consistent with the pull request summary. The changes reflect the renaming of the
aperturego
package toaperture
and the update of import paths accordingly.32-35: The
app
struct has been correctly updated to use the newaperture.Client
type instead of the previousaperturego.Client
. This change is necessary due to the renaming of the package and associated types.62-81: The main function has been updated to use the new
aperture.Options
andaperture.NewClient
which aligns with the renaming of the package. The environment variable fetching and parsing logic seems to be correct, but it's important to ensure that the environment variables are set correctly in the deployment environment.95-105: The middleware initialization has been updated to use the new
aperture.MiddlewareParams
andmiddleware.NewHTTPMiddleware
which reflects the changes in the package and type names. The timeout value is set to 2000 milliseconds, which should be verified to ensure it aligns with the desired timeout policy.151-157: The
getEnvOrDefault
function is used to fetch environment variables with a fallback to a default value if the variable is not set. This is a common pattern and the implementation here is straightforward. However, it's important to ensure that all calls to this function have been updated if the function signature has changed elsewhere in the codebase.sdks/aperture-go/sdk/middleware/http.go (1)
- 3-16: The added imports are necessary for the new functionality introduced in the middleware. Ensure that there are no unused imports after the final implementation to keep the code clean.
sdks/aperture-go/sdk/middleware/grpc.go (1)
- 110-171: The function
prepareCheckHTTPRequestForGRPC
is well-structured and handles errors appropriately by returning them to the caller. However, if thesocketAddressFromNetAddr
function is updated to return an error, the call to this function withinprepareCheckHTTPRequestForGRPC
will need to be updated to handle the error.sdks/aperture-go/sdk/client.go (8)
3-13: The import paths for OpenTelemetry and gRPC have been updated, which is a common change when dependencies are updated or when the project structure changes. Ensure that the new paths are correct and that the project's dependency management tool (like Go modules) has been updated accordingly.
16-31: The
Options
struct has been updated to use theslog.Logger
type instead of the previous logger type. This change will require all instantiations ofOptions
to use the newslog.Logger
type. Ensure that all parts of the code that create anOptions
struct have been updated accordingly.52-68: The
Client
interface andapertureClient
struct have been updated to reflect the new logging and gRPC client types. Ensure that all implementations of theClient
interface and usages of theapertureClient
struct are updated to handle these changes.75-94: The
NewClient
function has been updated to include an interceptor for gRPC connections that adds an API key to the metadata if provided. This is a security-sensitive change, so ensure that the API key is handled securely throughout the codebase and that it is not logged or exposed inappropriately.
[SECURITY]107-121: The
NewClient
function now initializes a logger with a default configuration if one is not provided in theOptions
. This is a good fallback mechanism to ensure that the client always has a logger available. However, ensure that the default logger's configuration is appropriate for the application's logging needs.140-155: The
StartFlow
function has been updated to include label extraction and overriding logic. Ensure that the label extraction from the context and the explicit label overriding are working as intended and that they do not introduce any unexpected behavior.176-182: The
StartHTTPFlow
function has been updated, and it now includes a span creation for tracing. Ensure that the span is correctly associated with the flow and that it is ended appropriately to avoid any memory leaks or incomplete traces.227-230: The
GetLogger
method has been added to theapertureClient
to expose the logger. This is a straightforward getter method and seems to be implemented correctly.
### Description of change - Add @fluxninja/aperture-js dependency in example - fix formatting in connected.ts and use_aperture.ts in example ##### Checklist - [ ] Tested in playground or other setup - [ ] Screenshot (Grafana) from playground added to PR for 15+ minute run - [ ] Documentation is changed or added - [ ] Tests and/or benchmarks are included - [ ] Breaking changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files ignored due to filter (2)
- sdks/aperture-js/example/package-lock.json
- sdks/aperture-js/example/package.json
Files selected for processing (8)
- sdks/aperture-go/sdk/middleware/grpc.go (3 hunks)
- sdks/aperture-js/.gitignore (1 hunks)
- sdks/aperture-js/Dockerfile (1 hunks)
- sdks/aperture-js/example/routes/connected.ts (1 hunks)
- sdks/aperture-js/example/routes/use_aperture.ts (2 hunks)
- sdks/aperture-js/sdk/cache.ts (1 hunks)
- sdks/aperture-js/sdk/client.ts (3 hunks)
- sdks/aperture-js/sdk/flow.ts (8 hunks)
Files skipped from review due to trivial changes (2)
- sdks/aperture-js/.gitignore
- sdks/aperture-js/Dockerfile
Additional comments: 9
sdks/aperture-js/sdk/client.ts (3)
20-25: The addition of
tryConnect
andcacheKey
to theFlowParams
interface aligns with the pull request's goal of introducing caching capabilities. These parameters should be documented to explain their usage and impact on theStartFlow
function.104-108: The
resolveFlow
function is updated to pass additional parameters to theFlow
constructor, includingparams.cacheKey
. This change is consistent with the new caching mechanism. Ensure that theFlow
constructor and associated methods are updated to handle these new parameters correctly.123-132: The
CheckRequest
object now includescacheKey
as part of its structure, which is essential for the caching mechanism. The callbackcb
is correctly updated to handle the response and error, passing them to theresolveFlow
function. Ensure that theCheckRequest
message definition in the gRPC service is updated to include thecacheKey
field.sdks/aperture-js/example/routes/connected.ts (2)
7-10: The change introduces a space between the
res:
andexpress.Response
which is a stylistic change and does not affect the functionality of the code. However, ensure that this change is consistent with the coding style guidelines of the project.9-10: The code is using a synchronous method
GetState()
to check the client state. IfGetState()
is a blocking call or if it performs any I/O, it might be more appropriate to handle it asynchronously, especially in a Node.js environment which is single-threaded and relies on non-blocking I/O to handle high concurrency. IfGetState()
is indeed synchronous and does not perform I/O, then this is fine as is.sdks/aperture-js/example/routes/use_aperture.ts (2)
1-8: The configuration for the
ApertureClient
is being set up with environment variables. Ensure that these environment variables are documented and that there are default values or error handling in place if they are not set.22-71: The route handler is well-structured with a
try...catch...finally
block, which is good for error handling and resource management. However, there are a few points to consider:
- The
flow
object is being ended in thefinally
block, which is good practice to ensure it is always cleaned up, but make sure that theEnd
method does not throw an exception that could be unhandled.- The
StartFlow
method now includesrampMode
andcacheKey
parameters. Ensure that these changes are reflected in the documentation and that all callers of this method are updated accordingly.- The cache operations (
SetCachedValue
andDeleteCachedValue
) are awaited, and errors are logged, but there is no further error handling. Depending on the application's requirements, you might want to handle these errors more gracefully or take specific actions.- The
labels
object is hardcoded with a user value of "kenobi". If this is meant to be dynamic, it should be retrieved from the request or another source.- The
sleep
function is used afterflow.ShouldRun()
returns true. This simulates work being done and is fine for an example, but in a real application, this should be replaced with actual logic.sdks/aperture-go/sdk/middleware/grpc.go (2)
151-153: The request body is being marshaled to JSON without checking if it can be marshaled. If
req
contains types that cannot be marshaled into JSON, this will result in an error. It's good practice to ensure that the types being passed tojson.Marshal
are compatible or to handle potential errors in a way that doesn't disrupt the flow.107-176: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [174-192]
The
convertHTTPStatusToGRPC
function maps HTTP status codes to gRPC codes. This is a good approach to maintain consistency between different protocols. However, ensure that this mapping aligns with the expected behavior of the gRPC services and clients that will interpret these codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 4
Configuration used: CodeRabbit UI
Files selected for processing (2)
- sdks/aperture-go/sdk/middleware/grpc.go (3 hunks)
- sdks/aperture-go/sdk/middleware/http.go (2 hunks)
Additional comments: 1
sdks/aperture-go/sdk/middleware/http.go (1)
- 3-17: The import section is well-organized and follows the convention of grouping standard library imports together, followed by third-party packages. However, it's important to ensure that all imported packages are used within the file to avoid unnecessary imports which can lead to confusion and slightly increased compilation times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- sdks/aperture-go/sdk/client.go (8 hunks)
- sdks/aperture-go/sdk/flow.go (2 hunks)
Additional comments: 15
sdks/aperture-go/sdk/flow.go (5)
16-28: The
Flow
interface has been updated to include new methods for caching. This change will require all implementations of theFlow
interface to provide these new methods. Ensure that all implementations are updated accordingly.41-51: The
newFlow
function has been updated to accept additional parameters (flowControlClient
,span
,rampMode
,cacheKey
) and initialize a newflow
struct with these parameters. This change is likely part of the larger refactoring to support the new caching mechanism. Ensure that all calls tonewFlow
are updated to pass the correct arguments.57-61: The
ShouldRun
method has been updated to consider therampMode
and thecheckResponse
'sDecisionType
. This logic ensures that the flow should run either if the ramp mode is not enabled and there is no check response, or if the decision type isACCEPTED
. This change seems to be a logical enhancement to the flow control mechanism.103-125: The
SetCachedValue
method has been added to set a cached value with a specified TTL (time-to-live). It communicates with theflowControlClient
to upsert the cache value. The response includes an error, response code, and message. Ensure that error handling is properly implemented in the calling code, as theError
field in the response struct is populated with the error returned from theCacheUpsert
RPC call.134-152: The
DeleteCachedValue
method has been added to delete a cached value. It also communicates with theflowControlClient
to delete the cache value. Similar toSetCachedValue
, ensure that error handling is properly implemented in the calling code.sdks/aperture-go/sdk/client.go (10)
3-13: The import paths have been updated, and the
slog
package is now used for logging. Ensure that theslog
package is properly integrated and that all logging calls have been updated accordingly.16-23: The import paths for the protobuf-generated code and utility packages have been updated to reflect the new version or location. Verify that these new paths are correct and that the packages are available at these locations.
25-31: The
Options
struct now includes a*slog.Logger
instead of alogr.Logger
. This change should be communicated to all users of theaperture
package to update their code accordingly.47-51: New fields have been added to the
FlowParams
struct, includingRampMode
andCacheKey
. Ensure that these new fields are being used correctly throughout the codebase and that their introduction does not break existing functionality.54-61: The
Client
interface has been updated to return*slog.Logger
instead oflogr.Logger
and to include new methods for starting flows with caching. Ensure that all implementations of this interface have been updated accordingly.77-96: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [72-96]
The
NewClient
function has been updated to include new logic for setting up a gRPC connection with the Aperture service, including handling an API key for authentication. Ensure that the error handling is robust and that the connection is properly secured.
109-117: The logger setup now checks if a logger is provided in the options; if not, it defaults to a new
slog
logger with a specified name. Ensure that this default behavior is documented and that it aligns with the expected logging practices.142-165: The
StartFlow
method has been updated to include new logic for handling cache keys and ramp mode. Ensure that the logic for merging labels from the context and theflowParams
is correct and that the cache key handling is secure and efficient.179-185: The
StartHTTPFlow
method has been updated similarly toStartFlow
. Ensure that the new logic for HTTP flows is consistent with the changes made to the standard flow logic and that it is properly tested.228-233: A new method
GetLogger
has been added to theapertureClient
struct to retrieve the logger. Ensure that this method is necessary and that it is being used appropriately where logging is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files ignored due to filter (1)
- docs/content/assets/openapiv2/aperture.swagger.yaml
Files selected for processing (2)
- pkg/policies/flowcontrol/service/check/check.go (3 hunks)
- pkg/policies/flowcontrol/service/check/provide.go (1 hunks)
Additional comments: 4
pkg/policies/flowcontrol/service/check/provide.go (2)
36-39: The addition of the
Cache
field to theConstructorIn
struct is consistent with the pull request's goal of introducing caching capabilities. However, it's marked as optional withoptional:"true"
. Ensure that the rest of the codebase can handle cases whereCache
is not provided, to avoid nil pointer dereferences.46-46: The
NewHandler
function is correctly updated to accept the newCache
parameter. This change aligns with the introduction of caching capabilities. Ensure that theNewHandler
function's implementation is updated accordingly to handle theCache
parameter.pkg/policies/flowcontrol/service/check/check.go (2)
23-41: The addition of the
cache
field to theHandler
struct and its initialization in theNewHandler
function is consistent with the pull request's goal of introducing a caching mechanism. Ensure that all instances whereHandler
is instantiated are updated to provide the newcache
argument.77-83: The
Check
method now includesCacheKey
in theRequestContext
. This is a necessary change for the caching mechanism to work. Ensure that theCacheKey
is being generated and used correctly throughout the system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 10
Configuration used: CodeRabbit UI
Files ignored due to filter (24)
- api/gen/proto/go/aperture/flowcontrol/check/v1/check.pb.go
- api/gen/proto/go/aperture/flowcontrol/check/v1/check.pb.validate.go
- api/gen/proto/go/aperture/flowcontrol/check/v1/check_vtproto.pb.go
- docs/content/assets/openapiv2/aperture.swagger.yaml
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check.pb.go
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check.pb.validate.go
- sdks/aperture-go/gen/proto/flowcontrol/check/v1/check_vtproto.pb.go
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheDeleteResponse.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheDeleteResponseOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheLookupStatus.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheOperationStatus.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheUpsertResponse.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CacheUpsertResponseOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CachedValue.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CachedValueOrBuilder.java
- sdks/aperture-java/lib/core/src/main/java/com/fluxninja/generated/aperture/flowcontrol/check/v1/CheckProto.java
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheDeleteResponse.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheLookupStatus.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheOperationStatus.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CacheUpsertResponse.ts
- sdks/aperture-js/sdk/gen/aperture/flowcontrol/check/v1/CachedValue.ts
- sdks/aperture-js/sdk/gen/check.ts
- sdks/aperture-py/aperture_sdk/_gen/aperture/flowcontrol/check/v1/check_pb2.py
- sdks/aperture-py/aperture_sdk/_gen/aperture/flowcontrol/check/v1/check_pb2.pyi
Files selected for processing (10)
- api/aperture/flowcontrol/check/v1/check.proto (2 hunks)
- pkg/policies/flowcontrol/engine.go (4 hunks)
- pkg/policies/flowcontrol/service/check/check.go (3 hunks)
- sdks/aperture-csharp/Generated/Aperture/Flowcontrol/V1/Check.cs (26 hunks)
- sdks/aperture-csharp/Generated/Aperture/Flowcontrol/V1/CheckGrpc.cs (6 hunks)
- sdks/aperture-go/sdk/cache.go (1 hunks)
- sdks/aperture-go/sdk/flow.go (2 hunks)
- sdks/aperture-js/proto/flowcontrol/check/v1/check.proto (2 hunks)
- sdks/aperture-js/sdk/cache.ts (1 hunks)
- sdks/aperture-js/sdk/flow.ts (7 hunks)
Files not summarized due to errors (1)
- sdks/aperture-csharp/Generated/Aperture/Flowcontrol/V1/Check.cs: Error: Message exceeds token limit
Additional comments: 45
sdks/aperture-csharp/Generated/Aperture/Flowcontrol/V1/CheckGrpc.cs (6)
52-62: The marshaller definitions for the new cache operations (
CacheUpsertRequest
,CacheUpsertResponse
,CacheDeleteRequest
,CacheDeleteResponse
) have been correctly added. This is necessary for the gRPC framework to serialize and deserialize the messages for these operations.69-90: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [65-86]
The method definitions for the new RPCs (
CacheUpsert
,CacheDelete
) have been added with the correct marshaller references. This aligns with the changes described in the pull request summary and is essential for enabling the new cache operations in theFlowControlService
.
107-120: The base service implementation provides the expected behavior for unimplemented methods by throwing an
RpcException
withStatusCode.Unimplemented
. This is a standard practice in gRPC service definitions to provide a clear error when a method is not implemented.196-238: The client methods for the new cache operations (
CacheUpsert
,CacheUpsertAsync
,CacheDelete
,CacheDeleteAsync
) have been implemented correctly, providing both synchronous and asynchronous options. This allows clients to interact with the new cache operations using theFlowControlServiceClient
.250-255: The
BindService
method has been updated to include the new cache operation methods. This is necessary for the server to recognize and handle incoming RPC calls for these operations.263-267: The
BindService
method has been correctly updated to bind the new cache operation methods. This ensures that the service implementation can be registered with the gRPC server with the new functionality.sdks/aperture-go/sdk/cache.go (1)
- 1-163: The code introduces new types and functions for handling cache operations in the Go SDK. It includes error handling, status conversion, and response interfaces for get, set, and delete cache operations. The code is well-structured and follows Go conventions for error variables and custom types. However, there are a few points to consider:
- The default cases in
convertCacheLookupStatus
andconvertCacheOperationStatus
functions (lines 39 and 51) returnLookupStatusMiss
andOperationStatusError
, respectively. This is a safe default, but it might be worth logging or handling the unexpected status to aid in debugging if an unknown status is ever encountered.- The
convertCacheError
function (lines 56-63) converts a string error message to an error type, which is a simple and effective way to handle error messages from the cache operations. However, it's important to ensure that the error messages are meaningful and provide enough context for troubleshooting.- The response structs (
getCachedValueResponse
,setCachedValueResponse
,deleteCachedValueResponse
) and their corresponding interfaces (GetCachedValueResponse
,SetCachedValueResponse
,DeleteCachedValueResponse
) are well-defined and encapsulate the response data effectively. It's good practice to define interfaces for responses as it allows for easier testing and mocking.- The
newGetCachedValueResponse
,newSetCachedValueResponse
, andnewDeleteCachedValueResponse
functions (lines 142-162) are factory functions that create instances of the response structs. This pattern is useful for encapsulating the creation logic and providing a clean API for creating response objects.Overall, the code is well-written and follows good practices. Just ensure that the rest of the system is prepared to handle the new error types and statuses introduced here.
sdks/aperture-js/proto/flowcontrol/check/v1/check.proto (8)
9-14: The addition of
CacheUpsert
andCacheDelete
RPCs to theFlowControlService
is a significant change. Ensure that the corresponding server-side implementations are updated to handle these new RPCs and that the client-side SDKs are also updated to expose these functionalities to the end-users.22-22: The addition of
cache_key
to theCheckRequest
message implies that caching logic is now part of the flow control check process. It's important to ensure that the caching mechanism is robust and that cache keys are generated in a consistent and collision-resistant manner. Additionally, consider the implications of cache key enumeration and potential security concerns around cache poisoning.67-71: The
CachedValue
message is included in theCheckResponse
, which suggests that the response can contain cached results. This is a performance optimization but also introduces complexity in terms of cache consistency and invalidation. Ensure that the caching strategy is well-documented and that clients are aware of how to interpret and handle cached responses.74-77: The
CacheLookupStatus
enum is introduced to indicate the result of a cache lookup. Ensure that the client and server logic correctly interpret these statuses and handle them appropriately, especially in edge cases where a cache miss might occur.79-82: The
CacheOperationStatus
enum is used to represent the outcome of cache operations. It's crucial to ensure that error handling is robust and that any operation errors are communicated clearly to the client to prevent any misinterpretation of the cache state.84-88: The
CachedValue
message includes anoperation_status
and anerror
string. It's important to ensure that the error messages are descriptive and actionable. Additionally, consider if there are any security implications of exposing raw error messages to clients, as they might leak implementation details or sensitive information.91-95: The
CacheUpsertRequest
message allows clients to insert or update cache entries. Ensure that there are appropriate access controls and validation in place to prevent unauthorized cache manipulation, which could lead to security vulnerabilities such as cache poisoning.103-105: The
CacheDeleteRequest
message enables clients to delete cache entries. Similar to theCacheUpsertRequest
, ensure that proper access controls are in place to prevent unauthorized deletion of cache entries.pkg/policies/flowcontrol/service/check/check.go (3)
23-42: The
Handler
struct andNewHandler
function have been correctly updated to include the newcache
field and parameter. This change aligns with the pull request's goal of introducing caching capabilities to the FlowControlService. Ensure that all instantiations ofHandler
throughout the codebase are updated to provide the newcache
argument.77-83: The
Check
method has been updated to includeCacheKey
in theRequestContext
. This is necessary for the caching functionality. However, ensure that theCacheKey
is being properly generated and used elsewhere in the system to avoid potential cache collisions or misuse.88-89: The addition of the
ApertureControlPointTypeLabel
toTelemetryFlowLabels
is a good practice for observability and telemetry. This change should help in monitoring and debugging the flow control decisions.pkg/policies/flowcontrol/engine.go (4)
73-76: The
cache
field has been added to theEngine
struct to support caching. Ensure that theRegisterCache
method is called to initialize this field before theEngine
is used to process requests, as theProcessRequest
method assumes the cache is non-nil when acacheKey
is provided. This is crucial to avoid potential nil pointer dereferences.87-90: The introduction of
cacheKey
as a local variable in theProcessRequest
function is a significant change. It is important to ensure that theRequestContext
struct now includes aCacheKey
field and that it is being correctly populated upstream. If the cache key is not correctly generated or passed, the caching functionality will not work as intended.123-161: The refactoring of the logic for running limiters into a separate function
runLimiters
is a good practice for code maintainability and readability. However, ensure that therunLimiters
function is thoroughly tested, especially since it involves concurrency and could potentially introduce race conditions or deadlocks if not handled correctly.173-194: The cache lookup logic has been added to the
ProcessRequest
function. It is important to handle errors from the cache appropriately. The current implementation logs a cache miss and any errors encountered during the cache lookup. Ensure that the error handling aligns with the overall application's error handling strategy and that any cache-related errors do not impact the critical path of request processing.sdks/aperture-js/sdk/cache.ts (4)
4-7: The
LookupStatus
enum is well-defined and aligns with the expected cache lookup statuses.22-25: The
OperationStatus
enum is well-defined and aligns with the expected operation statuses for cache operations.40-47: The
ConvertCacheError
function is a simple and effective way to convert a string error message into anError
object, handlingnull
andundefined
appropriately.49-82: The
CachedValueResponse
class is well-structured and provides clear methods for accessing the properties of a cached value response. The use ofBuffer
for the value suggests binary data handling, which is appropriate for cache values.sdks/aperture-js/sdk/flow.ts (4)
- 1-16: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [1-30]
The imports are well-organized and grouped by their functionality, which is good for maintainability. However, it's important to ensure that all these imports are used within the file to avoid unnecessary overhead.
41-53: The constructor of the
Flow
class has been updated to accept additional parameters for cache operations. This change aligns with the pull request's goal to introduce caching capabilities. Ensure that all instantiations of theFlow
class are updated to pass the correct arguments.142-162: The
CachedValue
method creates a newCachedValueResponse
object based on the presence of an error or the cached value from thecheckResponse
. This method does not seem to be asynchronous, but it should be verified that the consumers of this method are not expecting a promise.209-223: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [185-221]
The
End
method has been updated to handle cache responses. It includes a workaround for a known issue with the protobufjs library regarding timestamp formatting. This is a good example of defensive programming, but it's important to track the resolution of the linked issue and remove the workaround once it's no longer necessary.api/aperture/flowcontrol/check/v1/check.proto (8)
9-14: The addition of
CacheUpsert
andCacheDelete
RPCs to theFlowControlService
is a significant change. Ensure that the corresponding server-side implementations are secure, efficient, and handle errors gracefully. Also, verify that the client-side SDKs are updated to support these new RPCs.17-23: The
CheckRequest
message now includes acache_key
field. Ensure that the logic for generating and validating cache keys is robust and secure against potential cache poisoning attacks. Additionally, verify that all clients of this service are updated to handle the newcache_key
field appropriately.67-71: The
CheckResponse
message now includes acached_value
field. It is important to ensure that the caching logic correctly populates this field and that the clients properly handle the cached responses. Also, consider the implications of exposing cache details to the clients and whether this aligns with the intended design and security posture.74-77: The
CacheLookupStatus
enum is introduced to indicate cache hit or miss. Ensure that the service correctly sets this status in responses and that clients handle each status as expected.79-82: The
CacheOperationStatus
enum is introduced to indicate the success or error of a cache operation. It is crucial to ensure that error handling is consistent and informative, providing enough detail for clients to react appropriately to errors.84-89: The
CachedValue
message includes anerror
field. It is important to ensure that error messages do not leak sensitive information and are sanitized before being sent to clients. Additionally, verify that the error messages are clear and actionable for the clients.91-95: In the
CacheUpsertRequest
message, ensure that the TTL (Time To Live) for cache entries is being validated and that there are safeguards against setting excessively long or short TTL values, which could lead to cache inefficiency or denial of service.98-100: The
CacheUpsertResponse
andCacheDeleteResponse
messages include anoperation_status
and anerror
field. Ensure that the service implementation correctly maps internal errors to these fields and that the error messages are consistent and do not expose internal details unnecessarily.sdks/aperture-go/sdk/flow.go (7)
3-14: The import section has been updated correctly to include the necessary packages for the new functionality. The
context
package is essential for passing request-scoped values, cancellation signals, and deadlines, while thegoogle.golang.org/protobuf/types/known/durationpb
package is used for handling protocol buffer duration types. The update to the import path forcheckproto
reflects the new versioning scheme, which is a good practice for maintaining backward compatibility.16-28: The
Flow
interface has been updated to include new methods for caching (CachedValue
,SetCachedValue
, andDeleteCachedValue
). This change aligns with the pull request's goal of introducing caching capabilities. However, it's important to ensure that all implementations of theFlow
interface are updated to include these new methods to maintain compatibility.41-51: The
newFlow
function has been updated to accept additional parametersflowControlClient
andcacheKey
, which are necessary for the new caching functionality. The function initializes aflow
struct with these new fields. This is a good practice as it encapsulates the creation logic and sets sensible defaults.75-88: The
CachedValue
method correctly handles various error scenarios, such as whenf.err
is not nil or whenf.checkResponse
or itsCachedValue
is nil. It returns aGetCachedValueResponse
with appropriate status and error information. This is a good example of defensive programming, ensuring that the method behaves predictably even in error conditions.91-110: The
SetCachedValue
method performs a cache upsert operation using theflowControlClient
. It correctly converts thettl
to a protobuf duration and handles errors by returning aSetCachedValueResponse
with the appropriate status and error. This method should be reviewed to ensure that theCacheUpsert
RPC is implemented correctly on the server side and that theflowControlClient
is properly initialized and capable of handling the RPC call.112-127: The
DeleteCachedValue
method performs a cache delete operation and handles errors similarly to theSetCachedValue
method. It is important to verify that theCacheDelete
RPC is also correctly implemented on the server side and that theflowControlClient
is set up to handle this call.129-131: The
Error
method simply returns the error that occurred during the flow, which is a straightforward getter. This is a standard practice for exposing errors to the caller.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- sdks/aperture-js/example/routes/connected.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- sdks/aperture-js/example/routes/connected.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- sdks/aperture-go/sdk/flow.go (2 hunks)
Additional comments: 8
sdks/aperture-go/sdk/flow.go (8)
3-14: The import of the
durationpb
package is correct and necessary for the new caching functionality that uses time durations. However, ensure that theerrors
package is still required after the changes, as it is not explicitly used in the provided code snippet.16-28: The
Flow
interface has been updated to include new methods for caching. This is a significant change and should be communicated to all users of the SDK to update their implementations accordingly. The new methodsCachedValue
,SetCachedValue
, andDeleteCachedValue
need to be documented to explain their usage and expected behavior.30-51: The
flow
struct now includes acacheKey
field, which is essential for the new caching functionality. Ensure that all instances offlow
are initialized with a validcacheKey
where necessary, or handle cases wherecacheKey
might be an empty string to avoid runtime errors.54-58: The
ShouldRun
method's logic has been updated to account for therampMode
. This change affects the fail-open behavior and should be clearly documented in the SDK's usage guide. Users need to be aware of howrampMode
influences the decision-making process.71-84: The
CachedValue
method retrieves the cached value from thecheckResponse
. It is important to ensure that thecheckResponse
is notnil
before accessing its properties to avoid a nil pointer dereference. The error handling here is good practice, as it provides clear error messages for different failure scenarios.87-106: The
SetCachedValue
method correctly converts the TTL to a protobuf duration and makes a gRPC call to set the cached value. It is important to handle the case wherecacheKey
is empty to prevent unnecessary gRPC calls. The error handling and conversion of operation status are well-implemented.108-123: The
DeleteCachedValue
method follows a similar pattern toSetCachedValue
, including error handling and status conversion. It is crucial to ensure that thecacheKey
is not empty before attempting to delete the cached value.125-127: The
Error
method returns the error that occurred during the flow. This is a simple getter method and is implemented correctly.
Description of change
Checklist
Summary by CodeRabbit
New Features
Enhancements
Documentation
Refactor
Style
Chores