diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f39edc6bd5c..8cfc29ff971 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -334,7 +334,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - gh release download --repo github.com/tyklabs/tyk-pro --archive tar.gz -O env.tgz + gh release download --repo github.com/TykTechnologies/tyk-pro --archive tar.gz -O env.tgz mkdir auto && tar --strip-components=1 -C auto -xzvf env.tgz - name: env up shell: bash diff --git a/.gitignore b/.gitignore index c3d3051bdea..4be204743e6 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,5 @@ tyk_linux_* *.test main + +/coprocess/*.pb.go-e diff --git a/gateway/handler_success.go b/gateway/handler_success.go index 0f24aadc3f9..f61281a2b7f 100644 --- a/gateway/handler_success.go +++ b/gateway/handler_success.go @@ -343,19 +343,16 @@ func recordDetail(r *http.Request, spec *APISpec) bool { } } - // Are we even checking? - if !spec.GlobalConfig.EnforceOrgDataDetailLogging { - return spec.GlobalConfig.AnalyticsConfig.EnableDetailedRecording - } - - // We are, so get session data - session, ok := r.Context().Value(ctx.OrgSessionContext).(*user.SessionState) - if ok && session != nil { - return session.EnableDetailedRecording || session.EnableDetailRecording // nolint:staticcheck // Deprecated DetailRecording + // decide based on org session. + if spec.GlobalConfig.EnforceOrgDataDetailLogging { + session, ok := r.Context().Value(ctx.OrgSessionContext).(*user.SessionState) + if ok && session != nil { + return session.EnableDetailedRecording || session.EnableDetailRecording // nolint:staticcheck // Deprecated DetailRecording + } } - // no session found, use global config - return spec.GlobalConfig.AnalyticsConfig.EnableDetailedRecording + // no org session found, use global config + return spec.GraphQL.Enabled || spec.GlobalConfig.AnalyticsConfig.EnableDetailedRecording } // ServeHTTP will store the request details in the analytics store if necessary and proxy the request to it's diff --git a/gateway/handler_success_test.go b/gateway/handler_success_test.go index 9f1c4a1d9d3..e96cf99eecd 100644 --- a/gateway/handler_success_test.go +++ b/gateway/handler_success_test.go @@ -102,6 +102,13 @@ func TestRecordDetail(t *testing.T) { }, expect: true, }, + { + title: "graphql request", + spec: testAPISpec(func(spec *APISpec) { + spec.GraphQL.Enabled = true + }), + expect: true, + }, } for _, tc := range testcases { diff --git a/gateway/reverse_proxy.go b/gateway/reverse_proxy.go index 820c4201638..6d2731b1004 100644 --- a/gateway/reverse_proxy.go +++ b/gateway/reverse_proxy.go @@ -515,7 +515,7 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) Prox startTime := time.Now() p.logger.WithField("ts", startTime.UnixNano()).Debug("Started") - resp := p.WrappedServeHTTP(rw, req, true) + resp := p.WrappedServeHTTP(rw, req, recordDetail(req, p.TykAPISpec)) finishTime := time.Since(startTime) p.logger.WithField("ns", finishTime.Nanoseconds()).Debug("Finished") diff --git a/gateway/reverse_proxy_test.go b/gateway/reverse_proxy_test.go index bfab9ab339c..65a6d0b48c1 100644 --- a/gateway/reverse_proxy_test.go +++ b/gateway/reverse_proxy_test.go @@ -14,6 +14,7 @@ import ( "net/http/httptest" "net/url" "reflect" + "strconv" "strings" "sync" "testing" @@ -2023,3 +2024,40 @@ func TestQuotaResponseHeaders(t *testing.T) { }) } + +func BenchmarkLargeResponsePayload(b *testing.B) { + ts := StartTest(func(_ *config.Config) {}) + b.Cleanup(ts.Close) + + // Create a 500 MB payload of zeros + payloadSize := 500 * 1024 * 1024 // 500 MB in bytes + largePayload := bytes.Repeat([]byte("x"), payloadSize) + + largePayloadHandler := func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/octet-stream") + w.Header().Set("Content-Length", strconv.Itoa(payloadSize)) + w.WriteHeader(http.StatusOK) + _, err := w.Write(largePayload) + assert.NoError(b, err) + } + + // Create a test server with the largePayloadHandler + testServer := httptest.NewServer(http.HandlerFunc(largePayloadHandler)) + b.Cleanup(testServer.Close) + + ts.Gw.BuildAndLoadAPI(func(spec *APISpec) { + spec.UseKeylessAccess = true + spec.Proxy.ListenPath = "/" + spec.Proxy.TargetURL = testServer.URL + }) + + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + ts.Run(b, test.TestCase{ + Method: http.MethodGet, + Path: "/", + Code: http.StatusOK, + }) + } +}