Skip to content
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

fix: warehouse proxy endpoints #3476

Merged
merged 1 commit into from
Jun 9, 2023

Conversation

achettyiitr
Copy link
Member

@achettyiitr achettyiitr commented Jun 9, 2023

Description

Using dedicated public endpoints for the warehouse instead of passing everything with the matching /warehouse pattern. Currently, the warehouse supports these endpoints:

GET     /health                         INTERNAL
POST    /v1/process                     INTERNAL
POST    /v1/warehouse/pending-events    PUBLIC
POST    /v1/warehouse/trigger-upload    PUBLIC
GET     /databricksVersion              INTERNAL
POST    /v1/warehouse/jobs              PUBLIC
GET     /v1/warehouse/jobs/status       PUBLIC
POST    /v1/warehouse/fetch-tables      PUBLIC

Notion Ticket

https://www.notion.so/rudderstacks/Gateway-endpoints-are-not-working-for-warehouse-b6e7acafe48f49a587f7f7ef7e401291?pvs=4

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@achettyiitr achettyiitr changed the title fix: warehouse endpoints through gateway using reverse proxy fix: warehouse proxy endpoints Jun 9, 2023
@codecov
Copy link

codecov bot commented Jun 9, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (0b5935b) 53.29% compared to head (7447c68) 53.30%.

Additional details and impacted files
@@                Coverage Diff                @@
##           release/1.9.x    #3476      +/-   ##
=================================================
+ Coverage          53.29%   53.30%   +0.01%     
=================================================
  Files                330      330              
  Lines              52789    52782       -7     
=================================================
+ Hits               28136    28138       +2     
+ Misses             23005    22996       -9     
  Partials            1648     1648              
Impacted Files Coverage Δ
gateway/gateway.go 79.88% <100.00%> (+0.24%) ⬆️

... and 11 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines -979 to -1014
Context("Warehouse proxy", func() {
DescribeTable("forwarding requests to warehouse with different response codes",
func(url string, code int, payload string) {
gateway := &HandleT{}
whMock := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expect(r.URL.String()).To(Equal(url))
Expect(r.Body)
Expect(r.Body).To(Not(BeNil()))
defer func() { _ = r.Body.Close() }()
reqBody, err := io.ReadAll(r.Body)
Expect(err).To(BeNil())
Expect(string(reqBody)).To(Equal(payload))
w.WriteHeader(code)
}))
GinkgoT().Setenv("WAREHOUSE_URL", whMock.URL)
GinkgoT().Setenv("RSERVER_WAREHOUSE_MODE", config.OffMode)
err := gateway.Setup(context.Background(), c.mockApp, c.mockBackendConfig, c.mockJobsDB, nil, c.mockVersionHandler, rsources.NewNoOpService(), sourcedebugger.NewNoOpService())
Expect(err).To(BeNil())

defer func() {
err := gateway.Shutdown()
Expect(err).To(BeNil())
whMock.Close()
}()

req := httptest.NewRequest("POST", "http://rudder-server"+url, bytes.NewBufferString(payload))
w := httptest.NewRecorder()
gateway.whProxy.ServeHTTP(w, req)
resp := w.Result()
Expect(resp.StatusCode).To(Equal(code))
},
Entry("successful request", "/v1/warehouse/pending-events", http.StatusOK, `{"source_id": "1", "task_run_id":"2"}`),
Entry("failed request", "/v1/warehouse/pending-events", http.StatusBadRequest, `{"source_id": "3", "task_run_id":"4"}`),
Entry("request with query parameters", "/v1/warehouse/pending-events?triggerUpload=true", http.StatusOK, `{"source_id": "5", "task_run_id":"6"}`),
)
})
Copy link
Member Author

@achettyiitr achettyiitr Jun 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to have this test verify the reverse proxy behaviour.

"testing"
"time"

kitHelper "github.com/rudderlabs/rudder-go-kit/testhelper"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] for consistency

Suggested change
kitHelper "github.com/rudderlabs/rudder-go-kit/testhelper"
kithelper "github.com/rudderlabs/rudder-go-kit/testhelper"

@achettyiitr achettyiitr force-pushed the fix.warehouse-gateway-paths branch 2 times, most recently from 287034e to 1fc6934 Compare June 9, 2023 14:47
parsedURL, err := url.Parse(WHURL)
Expect(err).To(BeNil())
whPort := parsedURL.Port()
os.Setenv("RSERVER_WAREHOUSE_WEB_PORT", whPort)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to use GinkgoT().Setenv(). Just check it out, if not nevermind.

@achettyiitr achettyiitr force-pushed the fix.warehouse-gateway-paths branch 2 times, most recently from a7d3284 to 7a556f5 Compare June 9, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants