-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add traffic mirroring as endpoint middleware #7351
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
base: master
Are you sure you want to change the base?
Conversation
|
💔 The detected issue is not in one of the allowed statuses 💔
Please ensure your jira story is in one of the allowed statuses |
|
API Changes --- prev.txt 2025-09-11 16:39:43.682393463 +0000
+++ current.txt 2025-09-11 16:39:34.142345459 +0000
@@ -520,6 +520,7 @@
ValidateJSON []ValidatePathMeta `bson:"validate_json" json:"validate_json,omitempty"`
ValidateRequest []ValidateRequestMeta `bson:"validate_request" json:"validate_request,omitempty"`
Internal []InternalMeta `bson:"internal" json:"internal,omitempty"`
+ TrafficMirror []TrafficMirrorMeta `bson:"traffic_mirror" json:"traffic_mirror,omitempty"`
GoPlugin []GoPluginMeta `bson:"go_plugin" json:"go_plugin,omitempty"`
PersistGraphQL []PersistGraphQLMeta `bson:"persist_graphql" json:"persist_graphql"`
RateLimit []RateLimitMeta `bson:"rate_limit" json:"rate_limit"`
@@ -1332,6 +1333,24 @@
Method string `bson:"method" json:"method"`
}
+type TrafficMirrorDestination struct {
+ URL string `bson:"url" json:"url"`
+ Headers map[string]string `bson:"headers,omitempty" json:"headers,omitempty"`
+ Timeout int `bson:"timeout,omitempty" json:"timeout,omitempty"` // seconds
+ SampleRate float64 `bson:"sample_rate,omitempty" json:"sample_rate,omitempty"`
+}
+
+type TrafficMirrorMeta struct {
+ Disabled bool `bson:"disabled" json:"disabled"`
+ Path string `bson:"path" json:"path"`
+ Method string `bson:"method" json:"method"`
+ IgnoreCase bool `bson:"ignore_case" json:"ignore_case"`
+ Destinations []TrafficMirrorDestination `bson:"destinations" json:"destinations"`
+ SampleRate float64 `bson:"sample_rate,omitempty" json:"sample_rate,omitempty"`
+ Async bool `bson:"async" json:"async"`
+ Headers map[string]string `bson:"headers,omitempty" json:"headers,omitempty"`
+}
+
type TransformJQMeta struct {
Filter string `bson:"filter" json:"filter"`
Path string `bson:"path" json:"path"`
@@ -9789,11 +9808,10 @@
CreateIntrospectionClient creates an HTTP client for OAuth introspection
requests.
-func (f *ExternalHTTPClientFactory) CreateJWKClient() (*http.Client, error)
- CreateJWKClient creates an HTTP client specifically configured for
- JWK endpoint requests. This method requires external services OAuth
- configuration to be set up and will fail if not configured. Callers should
- fall back to getJWK() function if this method returns an error.
+func (f *ExternalHTTPClientFactory) CreateJWKClient(insecureSkipVerify bool) (*http.Client, error)
+ CreateJWKClient creates an HTTP client specifically configured for JWK
+ endpoint requests. This method preserves existing SSL skip verify behavior
+ while adding proxy support.
func (f *ExternalHTTPClientFactory) CreateWebhookClient() (*http.Client, error)
CreateWebhookClient creates an HTTP client for webhook requests.
@@ -11401,6 +11419,7 @@
StatusGoPlugin RequestStatus = "Go plugin"
StatusPersistGraphQL RequestStatus = "Persist GraphQL"
StatusRateLimit RequestStatus = "Rate Limited"
+ StatusTrafficMirrored RequestStatus = "Traffic Mirrored"
)
Statuses of the request, all are false-y except StatusOk and
StatusOkAndIgnore
@@ -11830,6 +11849,23 @@
ProcessRequest will run any checks on the request on the way through the
system, return an error to have the chain fail
+type TrafficMirrorMiddleware struct {
+ *BaseMiddleware
+ // Has unexported fields.
+}
+ TrafficMirrorMiddleware mirrors incoming requests to configured destinations
+
+func (t *TrafficMirrorMiddleware) EnabledForSpec() bool
+
+func (t *TrafficMirrorMiddleware) Init()
+
+func (t *TrafficMirrorMiddleware) Name() string
+
+func (t *TrafficMirrorMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, _ interface{}) (error, int)
+
+func (t *TrafficMirrorMiddleware) Unload()
+ Unload cleans up resources
+
type TransformHeaders struct {
*BaseMiddleware
}
@@ -12012,6 +12048,7 @@
GoPluginMeta GoPluginMiddleware
PersistGraphQL apidef.PersistGraphQLMeta
RateLimit apidef.RateLimitMeta
+ TrafficMirror apidef.TrafficMirrorMeta
IgnoreCase bool
// Has unexported fields.
@@ -12048,6 +12085,7 @@
GoPlugin
PersistGraphQL
RateLimit
+ TrafficMirrored
)
Enums representing the various statuses for a VersionInfo Path match during
a proxy request |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
📦 Impact Review Snapshot
## Impact AssessmentThis PR adds a new traffic mirroring middleware to Tyk Gateway that allows mirroring API requests to configured destinations. The implementation is well-contained and follows existing patterns for middleware integration, but requires schema updates in downstream repositories. The changes introduce ## Required Updatestyk-operator:
portal:
tyk-charts:
tyk-sink (MDCB):
## Compatibility ConcernsThe changes are additive and don't modify existing behavior, making them backward compatible. Existing APIs will continue to function as before, and only APIs that explicitly configure traffic mirroring will use the new functionality. However, there's a potential compatibility issue if older versions of tyk-operator try to manage APIs with traffic mirroring configured, as they won't understand the new fields. This could lead to the traffic mirroring configuration being lost during API updates through tyk-operator. The middleware implementation includes proper error handling and fallbacks, ensuring that if mirroring fails, it won't affect the primary request processing. ## Summary & Recommendations
Tip: Mention me again using |
|
Error during chat processing: Error: Failed to get response from AI model during iteration 5. terminated Tip: Mention me again using |
🚀 Performance Snapshot
## Performance Impact AnalysisThe new traffic mirroring middleware introduces a mechanism to duplicate and forward requests to configured destinations. While the implementation includes optimizations like sampling and async processing, it has several performance implications:
## Critical Areas
## Optimization Recommendations
## Summary
Tip: Mention me again using |
User description
Description
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
Add traffic mirroring endpoint middleware
Define mirror config in API spec
Compile and route mirror path specs
Include unit tests for middleware
Diagram Walkthrough
File Walkthrough
api_definitions.go
Define traffic mirroring configuration schemaapidef/api_definitions.go
TrafficMirrortoExtendedPathsSet.TrafficMirrorMetaconfiguration struct.TrafficMirrorDestinationwith headers/timeout/samplerate.api_definition.go
Compile and register traffic mirror path statusgateway/api_definition.go
TrafficMirroredURLStatus andStatusTrafficMirrored.api_loader.go
Wire traffic mirror middleware into pipelinegateway/api_loader.go
TrafficMirrorMiddlewarein middleware chain.model_urlspec.go
Extend URLSpec to carry mirror metadatagateway/model_urlspec.go
TrafficMirrorfield toURLSpec.TrafficMirrored.mw_traffic_mirror.go
Implement traffic mirroring middlewaregateway/mw_traffic_mirror.go
TrafficMirrorMiddlewarewith async/sync send.mw_traffic_mirror_test.go
Unit tests for traffic mirroring middlewaregateway/mw_traffic_mirror_test.go