-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat.isolateServerUTCommunication
- Loading branch information
Showing
7 changed files
with
243 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 48 additions & 2 deletions
50
processor/internal/destination_transformer/destination_transformer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,57 @@ | ||
package destination_transformer | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
type DestTransformer struct{} | ||
"github.com/rudderlabs/rudder-go-kit/config" | ||
"github.com/rudderlabs/rudder-go-kit/logger" | ||
"github.com/rudderlabs/rudder-go-kit/stats" | ||
warehouseutils "github.com/rudderlabs/rudder-server/warehouse/utils" | ||
) | ||
|
||
type DestTransformer struct { | ||
config struct { | ||
destTransformationURL string | ||
} | ||
conf *config.Config | ||
log logger.Logger | ||
stat stats.Stats | ||
} | ||
|
||
func (d *DestTransformer) SendRequest(data interface{}) (interface{}, error) { | ||
fmt.Println("Sending request to Service A") | ||
// Add service-specific logic | ||
return "Response from Service A", nil | ||
} | ||
|
||
func NewDestTransformer(conf *config.Config, log logger.Logger, stat stats.Stats) *DestTransformer { | ||
handle := &DestTransformer{} | ||
handle.conf = conf | ||
handle.log = log | ||
handle.stat = stat | ||
|
||
handle.config.destTransformationURL = handle.conf.GetString("Warehouse.destTransformationURL", "http://localhost:9090") | ||
return handle | ||
} | ||
|
||
func (d *DestTransformer) destTransformURL(destType string) string { | ||
destinationEndPoint := fmt.Sprintf("%s/v0/destinations/%s", d.config.destTransformationURL, strings.ToLower(destType)) | ||
|
||
if _, ok := warehouseutils.WarehouseDestinationMap[destType]; ok { | ||
whSchemaVersionQueryParam := fmt.Sprintf("whSchemaVersion=%s&whIDResolve=%v", d.conf.GetString("Warehouse.schemaVersion", "v1"), warehouseutils.IDResolutionEnabled()) | ||
switch destType { | ||
case warehouseutils.RS: | ||
return destinationEndPoint + "?" + whSchemaVersionQueryParam | ||
case warehouseutils.CLICKHOUSE: | ||
enableArraySupport := fmt.Sprintf("chEnableArraySupport=%s", fmt.Sprintf("%v", d.conf.GetBool("Warehouse.clickhouse.enableArraySupport", false))) | ||
return destinationEndPoint + "?" + whSchemaVersionQueryParam + "&" + enableArraySupport | ||
default: | ||
return destinationEndPoint + "?" + whSchemaVersionQueryParam | ||
} | ||
} | ||
if destType == warehouseutils.SnowpipeStreaming { | ||
return fmt.Sprintf("%s?whSchemaVersion=%s&whIDResolve=%t", destinationEndPoint, d.conf.GetString("Warehouse.schemaVersion", "v1"), warehouseutils.IDResolutionEnabled()) | ||
} | ||
return destinationEndPoint | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package http_client | ||
|
||
import ( | ||
"fmt" | ||
"github.com/bufbuild/httplb" | ||
"github.com/bufbuild/httplb/resolver" | ||
"github.com/rudderlabs/rudder-go-kit/config" | ||
"github.com/rudderlabs/rudder-go-kit/logger" | ||
"github.com/rudderlabs/rudder-go-kit/stats" | ||
"github.com/rudderlabs/rudder-server/utils/sysUtils" | ||
"net" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type HTTPDoer interface { | ||
Do(req *http.Request) (*http.Response, error) | ||
} | ||
|
||
type HTTPHandle struct { | ||
sentStat stats.Measurement | ||
receivedStat stats.Measurement | ||
cpDownGauge stats.Measurement | ||
|
||
conf *config.Config | ||
logger logger.Logger | ||
stat stats.Stats | ||
|
||
httpClient HTTPDoer | ||
|
||
guardConcurrency chan struct{} | ||
|
||
config struct { | ||
maxConcurrency int | ||
maxHTTPConnections int | ||
maxHTTPIdleConnections int | ||
maxIdleConnDuration time.Duration | ||
disableKeepAlives bool | ||
|
||
timeoutDuration time.Duration | ||
|
||
maxRetry config.ValueLoader[int] | ||
failOnUserTransformTimeout config.ValueLoader[bool] | ||
failOnError config.ValueLoader[bool] | ||
maxRetryBackoffInterval config.ValueLoader[time.Duration] | ||
|
||
destTransformationURL string | ||
userTransformationURL string | ||
} | ||
} | ||
|
||
type HTTPLBTransport struct { | ||
*http.Transport | ||
} | ||
|
||
func (t *HTTPLBTransport) NewRoundTripper(scheme, target string, config httplb.TransportConfig) httplb.RoundTripperResult { | ||
return httplb.RoundTripperResult{RoundTripper: t.Transport, Close: t.CloseIdleConnections} | ||
} | ||
|
||
func NewHTTPClient(conf *config.Config, log logger.Logger, stat stats.Stats) (HTTPHandle, error) { | ||
trans := HTTPHandle{} | ||
|
||
trans.conf = conf | ||
trans.logger = log.Child("transformer") | ||
trans.stat = stat | ||
|
||
trans.sentStat = stat.NewStat("processor.transformer_sent", stats.CountType) | ||
trans.receivedStat = stat.NewStat("processor.transformer_received", stats.CountType) | ||
trans.cpDownGauge = stat.NewStat("processor.control_plane_down", stats.GaugeType) | ||
|
||
trans.config.maxConcurrency = conf.GetInt("Processor.maxConcurrency", 200) | ||
trans.config.maxHTTPConnections = conf.GetInt("Transformer.Client.maxHTTPConnections", 100) | ||
trans.config.maxHTTPIdleConnections = conf.GetInt("Transformer.Client.maxHTTPIdleConnections", 10) | ||
trans.config.maxIdleConnDuration = conf.GetDuration("Transformer.Client.maxIdleConnDuration", 30, time.Second) | ||
trans.config.disableKeepAlives = conf.GetBool("Transformer.Client.disableKeepAlives", true) | ||
trans.config.timeoutDuration = conf.GetDuration("HttpClient.procTransformer.timeout", 600, time.Second) | ||
trans.config.destTransformationURL = conf.GetString("DEST_TRANSFORM_URL", "http://localhost:9090") | ||
trans.config.userTransformationURL = conf.GetString("USER_TRANSFORM_URL", trans.config.destTransformationURL) | ||
|
||
trans.config.maxRetry = conf.GetReloadableIntVar(30, 1, "Processor.maxRetry") | ||
trans.config.failOnUserTransformTimeout = conf.GetReloadableBoolVar(false, "Processor.Transformer.failOnUserTransformTimeout") | ||
trans.config.failOnError = conf.GetReloadableBoolVar(false, "Processor.Transformer.failOnError") | ||
|
||
trans.config.maxRetryBackoffInterval = conf.GetReloadableDurationVar(30, time.Second, "Processor.Transformer.maxRetryBackoffInterval") | ||
|
||
trans.guardConcurrency = make(chan struct{}, trans.config.maxConcurrency) | ||
|
||
clientType := conf.GetString("Transformer.Client.type", "stdlib") | ||
|
||
transport := &http.Transport{ | ||
DisableKeepAlives: trans.config.disableKeepAlives, | ||
MaxConnsPerHost: trans.config.maxHTTPConnections, | ||
MaxIdleConnsPerHost: trans.config.maxHTTPIdleConnections, | ||
IdleConnTimeout: trans.config.maxIdleConnDuration, | ||
} | ||
client := &http.Client{ | ||
Transport: transport, | ||
Timeout: trans.config.timeoutDuration, | ||
} | ||
|
||
switch clientType { | ||
case "stdlib": | ||
trans.httpClient = client | ||
case "recycled": | ||
trans.httpClient = sysUtils.NewRecycledHTTPClient(func() *http.Client { | ||
return client | ||
}, config.GetDuration("Transformer.Client.ttl", 120, time.Second)) | ||
case "httplb": | ||
trans.httpClient = httplb.NewClient( | ||
httplb.WithTransport("http", &HTTPLBTransport{ | ||
Transport: transport, | ||
}), | ||
httplb.WithResolver( | ||
resolver.NewDNSResolver( | ||
net.DefaultResolver, | ||
resolver.PreferIPv6, | ||
config.GetDuration("Transformer.Client.ttl", 120, time.Second), // TTL value | ||
), | ||
), | ||
) | ||
default: | ||
return HTTPHandle{}, fmt.Errorf("unknown transformer client type: %s", clientType) | ||
} | ||
|
||
return trans, nil | ||
} |
29 changes: 27 additions & 2 deletions
29
processor/internal/trackingplan_validation/trackingplan_validation.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
package trackingplan_validation | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"github.com/rudderlabs/rudder-go-kit/config" | ||
"github.com/rudderlabs/rudder-go-kit/logger" | ||
"github.com/rudderlabs/rudder-go-kit/stats" | ||
) | ||
|
||
type TPValidator struct{} | ||
type TPValidator struct { | ||
config struct { | ||
destTransformationURL string | ||
} | ||
conf *config.Config | ||
log logger.Logger | ||
stat stats.Stats | ||
} | ||
|
||
func (t *TPValidator) SendRequest(data interface{}) (interface{}, error) { | ||
fmt.Println("Sending request to Service A") | ||
// Add service-specific logic | ||
return "Response from Service A", nil | ||
} | ||
|
||
func NewTPValidator(conf *config.Config, log logger.Logger, stat stats.Stats) *TPValidator { | ||
handle := &TPValidator{} | ||
handle.conf = conf | ||
handle.log = log | ||
handle.stat = stat | ||
handle.config.destTransformationURL = handle.conf.GetString("Warehouse.destTransformationURL", "http://localhost:9090") | ||
return handle | ||
} | ||
|
||
func (t *TPValidator) trackingPlanValidationURL() string { | ||
return t.config.destTransformationURL + "/v0/validate" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
package user_transformer | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"github.com/rudderlabs/rudder-go-kit/config" | ||
"github.com/rudderlabs/rudder-go-kit/logger" | ||
"github.com/rudderlabs/rudder-go-kit/stats" | ||
) | ||
|
||
type UserTransformer struct{} | ||
type UserTransformer struct { | ||
config struct { | ||
userTransformationURL string | ||
} | ||
conf *config.Config | ||
log logger.Logger | ||
stat stats.Stats | ||
} | ||
|
||
func (u *UserTransformer) SendRequest(data interface{}) (interface{}, error) { | ||
fmt.Println("Sending request to Service A") | ||
// Add service-specific logic | ||
return "Response from Service A", nil | ||
} | ||
|
||
func NewUserTransformer(conf *config.Config, log logger.Logger, stat stats.Stats) *UserTransformer { | ||
handle := &UserTransformer{} | ||
handle.conf = conf | ||
handle.log = log | ||
handle.stat = stat | ||
handle.config.userTransformationURL = handle.conf.GetString("Warehouse.userTransformationURL", "http://localhost:9090") | ||
return handle | ||
} | ||
|
||
func (u *UserTransformer) userTransformURL() string { | ||
return u.config.userTransformationURL + "/customTransform" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters