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

feat: snowpipe streaming #5110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
go-version-file: 'go.mod'
- run: go version
- run: go mod download # Not required, used to segregate module download vs test times
- run: make test exclude="/rudder-server/(jobsdb|integration_test|processor|regulation-worker|router|services|suppression-backup-service|warehouse)"
- run: FORCE_RUN_INTEGRATION_TESTS=true make test exclude="/rudder-server/(jobsdb|integration_test|processor|regulation-worker|router|services|suppression-backup-service|warehouse)"
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
Expand All @@ -145,6 +145,7 @@ jobs:
- integration_test/tracing
- integration_test/backendconfigunavailability
- integration_test/trackedusersreporting
- integration_test/snowpipestreaming
- processor
- regulation-worker
- router
Expand Down Expand Up @@ -186,7 +187,8 @@ jobs:
TEST_KAFKA_AZURE_EVENT_HUBS_CLOUD_CONNECTION_STRING: ${{ secrets.TEST_KAFKA_AZURE_EVENT_HUBS_CLOUD_CONNECTION_STRING }}
TEST_S3_DATALAKE_CREDENTIALS: ${{ secrets.TEST_S3_DATALAKE_CREDENTIALS }}
BIGQUERY_INTEGRATION_TEST_CREDENTIALS: ${{ secrets.BIGQUERY_INTEGRATION_TEST_CREDENTIALS }}
run: make test exclude="${{ matrix.exclude }}" package=${{ matrix.package }}
SNOWPIPE_STREAMING_KEYPAIR_UNENCRYPTED_INTEGRATION_TEST_CREDENTIALS: ${{ secrets.SNOWPIPE_STREAMING_KEYPAIR_UNENCRYPTED_INTEGRATION_TEST_CREDENTIALS }}
run: FORCE_RUN_INTEGRATION_TESTS=true make test exclude="${{ matrix.exclude }}" package=${{ matrix.package }}
- name: Sanitize name for Artifact
run: |
name=$(echo -n "${{ matrix.package }}" | sed -e 's/[ \t:\/\\"<>|*?]/-/g' -e 's/--*/-/g')
Expand Down
3 changes: 2 additions & 1 deletion gateway/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
sourcedebugger "github.com/rudderlabs/rudder-server/services/debugger/source"
"github.com/rudderlabs/rudder-server/services/rsources"
"github.com/rudderlabs/rudder-server/utils/misc"
"github.com/rudderlabs/rudder-server/utils/timeutil"
"github.com/rudderlabs/rudder-server/utils/types"
)

Expand Down Expand Up @@ -488,7 +489,7 @@ func (gw *Handle) getJobDataFromRequest(req *webRequestT) (jobData *jobFromReq,
}
receivedAt, ok := userEvent.events[0]["receivedAt"].(string)
if !ok || !arctx.ReplaySource {
receivedAt = time.Now().Format(misc.RFC3339Milli)
receivedAt = timeutil.Now().Format(misc.RFC3339Milli)
}
singularEventBatch := SingularEventBatch{
Batch: userEvent.events,
Expand Down
1,512 changes: 1,512 additions & 0 deletions integration_test/snowpipestreaming/snowpipestreaming_test.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.9"

services:
rudder-snowpipe-clients:
image: "rudderstack/rudder-snowpipe-clients:develop"
ports:
- "9078"
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:9078/health || exit 1
interval: 1s
retries: 25
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.9"

services:
transformer:
image: "rudderstack/develop-rudder-transformer:fix.snowpipe-streaming-users"
ports:
- "9090:9090"
healthcheck:
test: wget --no-verbose --tries=1 --spider http://0.0.0.0:9090/health || exit 1
interval: 1s
retries: 25
3 changes: 3 additions & 0 deletions processor/transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@ func (trans *handle) destTransformURL(destType string) string {
return destinationEndPoint + "?" + whSchemaVersionQueryParam
}
}
if destType == warehouseutils.SnowpipeStreaming {
return destinationEndPoint + "?" + fmt.Sprintf("whSchemaVersion=%s&whIDResolve=%v", trans.conf.GetString("Warehouse.schemaVersion", "v1"), warehouseutils.IDResolutionEnabled())
}
return destinationEndPoint
}

Expand Down
2 changes: 1 addition & 1 deletion router/batchrouter/asyncdestinationmanager/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import "slices"

var (
asyncDestinations = []string{"MARKETO_BULK_UPLOAD", "BINGADS_AUDIENCE", "ELOQUA", "YANDEX_METRICA_OFFLINE_EVENTS", "BINGADS_OFFLINE_CONVERSIONS", "KLAVIYO_BULK_UPLOAD", "LYTICS_BULK_UPLOAD"}
asyncDestinations = []string{"MARKETO_BULK_UPLOAD", "BINGADS_AUDIENCE", "ELOQUA", "YANDEX_METRICA_OFFLINE_EVENTS", "BINGADS_OFFLINE_CONVERSIONS", "KLAVIYO_BULK_UPLOAD", "LYTICS_BULK_UPLOAD", "SNOWPIPE_STREAMING"}
sftpDestinations = []string{"SFTP"}
)

Expand Down
3 changes: 3 additions & 0 deletions router/batchrouter/asyncdestinationmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
lyticsBulkUpload "github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager/lytics_bulk_upload"
marketobulkupload "github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager/marketo-bulk-upload"
"github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager/sftp"
"github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager/snowpipestreaming"
"github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager/yandexmetrica"
)

Expand All @@ -41,6 +42,8 @@ func newRegularManager(
return klaviyobulkupload.NewManager(logger, statsFactory, destination)
case "LYTICS_BULK_UPLOAD":
return lyticsBulkUpload.NewManager(logger, statsFactory, destination)
case "SNOWPIPE_STREAMING":
return snowpipestreaming.New(conf, logger, statsFactory, destination), nil
}
return nil, errors.New("invalid destination type")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package snowpipestreaming

import (
"context"
"strconv"

"github.com/rudderlabs/rudder-go-kit/logger"
"github.com/rudderlabs/rudder-go-kit/stats"

backendconfig "github.com/rudderlabs/rudder-server/backend-config"
"github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager/snowpipestreaming/internal/model"
)

func newApiAdapter(
logger logger.Logger,
statsFactory stats.Stats,
api api,
destination *backendconfig.DestinationT,
) api {
return &apiAdapter{
logger: logger,
statsFactory: statsFactory,
destination: destination,
api: api,
}
}

func (a *apiAdapter) defaultTags() stats.Tags {
return stats.Tags{
"module": "batch_router",
"workspaceId": a.destination.WorkspaceID,
"destType": a.destination.DestinationDefinition.Name,
"destinationId": a.destination.ID,
}
}

func (a *apiAdapter) CreateChannel(ctx context.Context, req *model.CreateChannelRequest) (*model.ChannelResponse, error) {
a.logger.Infon("Creating channel",
logger.NewStringField("rudderIdentifier", req.RudderIdentifier),
logger.NewStringField("partition", req.Partition),
logger.NewStringField("database", req.TableConfig.Database),
logger.NewStringField("namespace", req.TableConfig.Schema),
logger.NewStringField("table", req.TableConfig.Table),
)
tags := a.defaultTags()
tags["api"] = "create_channel"

responseTimeStat := a.statsFactory.NewTaggedStat("snowpipe_streaming_api_response_time", stats.TimerType, tags)
defer responseTimeStat.RecordDuration()()

resp, err := a.api.CreateChannel(ctx, req)
if err != nil {
tags["status"] = "false"
return nil, err
}

Check warning on line 55 in router/batchrouter/asyncdestinationmanager/snowpipestreaming/apiadapter.go

View check run for this annotation

Codecov / codecov/patch

router/batchrouter/asyncdestinationmanager/snowpipestreaming/apiadapter.go#L53-L55

Added lines #L53 - L55 were not covered by tests
tags["status"] = strconv.FormatBool(resp.Success)
tags["code"] = resp.Code
return resp, nil
}

func (a *apiAdapter) DeleteChannel(ctx context.Context, channelID string, sync bool) error {
a.logger.Infon("Deleting channel",
logger.NewStringField("channelId", channelID),
logger.NewBoolField("sync", sync),
)
tags := a.defaultTags()
tags["api"] = "delete_channel"

responseTimeStat := a.statsFactory.NewTaggedStat("snowpipe_streaming_api_response_time", stats.TimerType, tags)
defer responseTimeStat.RecordDuration()()

err := a.api.DeleteChannel(ctx, channelID, sync)
if err != nil {
tags["status"] = "false"
return err
}
tags["status"] = "true"
return nil
}

func (a *apiAdapter) Insert(ctx context.Context, channelID string, insertRequest *model.InsertRequest) (*model.InsertResponse, error) {
tags := a.defaultTags()
tags["api"] = "insert"

responseTimeStat := a.statsFactory.NewTaggedStat("snowpipe_streaming_api_response_time", stats.TimerType, tags)
defer responseTimeStat.RecordDuration()()

resp, err := a.api.Insert(ctx, channelID, insertRequest)
if err != nil {
tags["status"] = "false"
return nil, err
}

Check warning on line 92 in router/batchrouter/asyncdestinationmanager/snowpipestreaming/apiadapter.go

View check run for this annotation

Codecov / codecov/patch

router/batchrouter/asyncdestinationmanager/snowpipestreaming/apiadapter.go#L90-L92

Added lines #L90 - L92 were not covered by tests
tags["status"] = strconv.FormatBool(resp.Success)
tags["code"] = resp.Code
return resp, nil
}

func (a *apiAdapter) Status(ctx context.Context, channelID string) (*model.StatusResponse, error) {
tags := a.defaultTags()
tags["api"] = "status"

responseTimeStat := a.statsFactory.NewTaggedStat("snowpipe_streaming_api_response_time", stats.TimerType, tags)
defer responseTimeStat.RecordDuration()()

resp, err := a.api.Status(ctx, channelID)
if err != nil {
tags["status"] = "false"
return nil, err
}
tags["status"] = strconv.FormatBool(resp.Success)
return resp, nil
}
Loading
Loading