Repository: vanus-labs/vanus
Pull request #641 (2023-10-18 07:29:07)

feat: trigger http protocol push event support gateway
<!--

Thank you for contributing to Vanus!

PR Title Format: 

feat/fix/refactor/docs/...: what's changed

Note: see https://github.com/vanus-labs/vanus/blob/main/CONTRIBUTING.md to know details about title format

-->

### What problem does this PR solve?

<!--

Please create an issue first to describe the problem

There MUST be one line starting with "Issue Number:  ".

-->

Issue Number: close #xxx

### Problem Summary

### What is changed and how does it work?

### Check List

<!-- At least one of them must be included. -->

#### Tests

- [ ] Unit test
- [ ] Integration test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No code


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) Report
> Merging [#641](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) (2fe678c) into [main](https://app.codecov.io/gh/vanus-labs/vanus/commit/ee76217182ba60efbcbb62fd374b8e75127d5133?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) (ee76217) will **decrease** coverage by `5.81%`.
> Report is 103 commits behind head on main.
> The diff coverage is `3.63%`.

[![Impacted file tree graph](https://app.codecov.io/gh/vanus-labs/vanus/pull/641/graphs/tree.svg?width=650&height=150&src=pr&token=RSXSIMEY4V&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs)](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs)

```diff
@@            Coverage Diff             @@
##             main     #641      +/-   ##
==========================================
- Coverage   57.07%   51.27%   -5.81%     
==========================================
  Files         190      260      +70     
  Lines       15191    19539    +4348     
==========================================
+ Hits         8670    10018    +1348     
- Misses       5884     8706    +2822     
- Partials      637      815     +178     
```

| [Flag](https://app.codecov.io/gh/vanus-labs/vanus/pull/641/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) | Coverage Δ | |
|---|---|---|
| [unittests](https://app.codecov.io/gh/vanus-labs/vanus/pull/641/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) | `51.27% <3.63%> (?)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Files](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) | Coverage Δ | |
|---|---|---|
| [api/errors/app.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-YXBpL2Vycm9ycy9hcHAuZ28=) | `30.90% <ø> (ø)` | |
| [lib/bytes/clone\_go119.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2J5dGVzL2Nsb25lX2dvMTE5Lmdv) | `0.00% <ø> (ø)` | |
| [lib/bytes/escape.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2J5dGVzL2VzY2FwZS5nbw==) | `54.46% <ø> (ø)` | |
| [lib/bytes/io.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2J5dGVzL2lvLmdv) | `0.00% <ø> (ø)` | |
| [lib/bytes/parse.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2J5dGVzL3BhcnNlLmdv) | `7.14% <ø> (ø)` | |
| [lib/bytes/unsafe.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2J5dGVzL3Vuc2FmZS5nbw==) | `100.00% <ø> (ø)` | |
| [lib/bytes/utf8.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2J5dGVzL3V0ZjguZ28=) | `11.11% <ø> (ø)` | |
| [lib/json/path/parse.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2pzb24vcGF0aC9wYXJzZS5nbw==) | `49.41% <ø> (ø)` | |
| [lib/json/path/path.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2pzb24vcGF0aC9wYXRoLmdv) | `0.00% <ø> (ø)` | |
| [lib/json/path/segment.go](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-bGliL2pzb24vcGF0aC9zZWdtZW50Lmdv) | `0.00% <ø> (ø)` | |
| ... and [31 more](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) | |

... and [393 files with indirect coverage changes](https://app.codecov.io/gh/vanus-labs/vanus/pull/641/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs)

------

[Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs). Last update [5712f51...2fe678c](https://app.codecov.io/gh/vanus-labs/vanus/pull/641?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs).


Patch:
diff --git a/server/trigger/client/http.go b/server/trigger/client/http.go
index f93148c..ff6333f 100644
--- a/server/trigger/client/http.go
+++ b/server/trigger/client/http.go
@@ -33,6 +33,13 @@ func NewHTTPClient(url string) EventClient {
 	}
 }
 
+func NewHTTPClientWithGateway(url, gateway, headerKey string) EventClient {
+	c, _ := ce.NewClientHTTP(ce.WithTarget(gateway), ce.WithHeader(headerKey, url))
+	return &http{
+		client: c,
+	}
+}
+
 func (c *http) Send(ctx context.Context, events ...*ce.Event) Result {
 	event := events[0]
 	res := c.client.Send(ctx, *event)
diff --git a/server/trigger/config.go b/server/trigger/config.go
index 05364f7..fce8e36 100644
--- a/server/trigger/config.go
+++ b/server/trigger/config.go
@@ -19,14 +19,16 @@ import (
 	"time"
 
 	"github.com/vanus-labs/vanus/pkg/observability"
+	"github.com/vanus-labs/vanus/server/trigger/trigger"
 )
 
 type Config struct {
 	Observability  observability.Config `yaml:"observability"`
 	TriggerAddr    string
-	Port           int      `yaml:"port"`
-	IP             string   `yaml:"ip"`
-	ControllerAddr []string `yaml:"controllers"`
+	Port           int                    `yaml:"port"`
+	IP             string                 `yaml:"ip"`
+	ControllerAddr []string               `yaml:"controllers"`
+	Gateway        *trigger.TargetGateway `yaml:"gateway"`
 
 	HeartbeatInterval time.Duration `yaml:"heartbeat_interval"`
 	// send event goroutine size
diff --git a/server/trigger/reader/reader.go b/server/trigger/reader/reader.go
index 801bd2f..9b37e4c 100644
--- a/server/trigger/reader/reader.go
+++ b/server/trigger/reader/reader.go
@@ -44,6 +44,8 @@ const (
 	lookupReadableLogsTimeout = 5 * time.Second
 	readEventTimeout          = 5 * time.Second
 	readErrSleepTime          = 2 * time.Second
+	checkEventlogInterval     = 2 * time.Minute
+	logFrequencyMini          = 10
 )
 
 type Config struct {
@@ -143,12 +145,12 @@ func (r *reader) Start() error {
 	r.wg.Add(1)
 	go func() {
 		defer r.wg.Done()
-		ticker := time.NewTicker(time.Minute * 2)
+		ticker := time.NewTicker(checkEventlogInterval)
 		defer ticker.Stop()
 		for {
 			select {
 			case <-ticker.C:
-				r.findEventlog(ctx)
+				_ = r.findEventlog(ctx)
 			case <-ctx.Done():
 				return
 			}
@@ -219,7 +221,7 @@ func (elReader *eventlogReader) stop() {
 	elReader.cancel()
 }
 
-// get earliest offset
+// getOffset get earliest offset.
 func (elReader *eventlogReader) getOffset(ctx context.Context) (int64, error) {
 	logs, err := elReader.config.Client.Eventbus(ctx,
 		api.WithID(elReader.config.EventbusID.Uint64())).ListLog(ctx)
@@ -251,7 +253,7 @@ func (elReader *eventlogReader) run(parentCtx context.Context) {
 		Uint64("offset", elReader.offset).
 		Msg("eventlog reader init success")
 
-	min := time.Now().Minute() / 10
+	min := time.Now().Minute() / logFrequencyMini
 	for {
 		select {
 		case <-ctx.Done():
@@ -259,7 +261,7 @@ func (elReader *eventlogReader) run(parentCtx context.Context) {
 		default:
 		}
 		err := elReader.loop(ctx, r)
-		currMin := time.Now().Minute() / 10
+		currMin := time.Now().Minute() / logFrequencyMini
 		if currMin != min {
 			min = currMin
 			log.Info().Err(err).
diff --git a/server/trigger/trigger/config.go b/server/trigger/trigger/config.go
index fb91e08..f392be3 100644
--- a/server/trigger/trigger/config.go
+++ b/server/trigger/trigger/config.go
@@ -45,6 +45,12 @@ type Config struct {
 	SendBatchSize int
 	PullBatchSize int
 	MaxUACKNumber int
+	TargetGateway *TargetGateway
+}
+
+type TargetGateway struct {
+	Address          string `yaml:"address"`
+	TargetHeaderName string `yaml:"header_name"`
 }
 
 func defaultConfig() Config {
@@ -155,3 +161,9 @@ func WithMaxUACKNumber(maxUACKNumber int) Option {
 		t.config.MaxUACKNumber = maxUACKNumber
 	}
 }
+
+func WithProxy(proxy *TargetGateway) Option {
+	return func(t *trigger) {
+		t.config.TargetGateway = proxy
+	}
+}
diff --git a/server/trigger/trigger/trigger.go b/server/trigger/trigger/trigger.go
index 29a247c..42a8543 100644
--- a/server/trigger/trigger/trigger.go
+++ b/server/trigger/trigger/trigger.go
@@ -68,6 +68,7 @@ type Trigger interface {
 
 type trigger struct {
 	subscriptionIDStr string
+	eventbusIDStr     string
 
 	subscription  *primitive.Subscription
 	offsetManager *offset.SubscriptionOffset
@@ -119,6 +120,7 @@ func newTrigger(subscription *primitive.Subscription, opts ...Option) (*trigger,
 		filter:            filter.GetFilter(subscription.Filters),
 		subscription:      subscription,
 		subscriptionIDStr: subscription.ID.String(),
+		eventbusIDStr:     subscription.EventbusID.String(),
 		transformer:       trans,
 	}
 	if subscription.Protocol == primitive.GRPC {
@@ -154,7 +156,11 @@ func (t *trigger) getClient() client.EventClient {
 func (t *trigger) changeTarget(
 	sink primitive.URI, protocol primitive.Protocol, credential primitive.SinkCredential,
 ) error {
-	eventCli := newEventClient(sink, protocol, credential)
+	eventCli := newEventClient(clientConfig{
+		sink:       sink,
+		protocol:   protocol,
+		credential: credential,
+		gateway:    t.config.TargetGateway})
 	t.lock.Lock()
 	defer t.lock.Unlock()
 	t.eventCli = eventCli
@@ -280,7 +286,10 @@ func (t *trigger) runRetryEventFilterTransform(ctx context.Context) {
 				if err != nil {
 					log.Info(ctx).Err(err).
 						Str("event_id", event.record.Event.ID()).
-						Interface("event_offset", event.record.OffsetInfo).
+						Str(log.KeySubscriptionID, t.subscriptionIDStr).
+						Str(log.KeyEventbusID, t.eventbusIDStr).
+						Stringer(log.KeyEventlogID, event.record.EventlogID).
+						Uint64("event_offset", event.record.OffsetInfo.Offset).
 						Msg("event transform error")
 					t.writeFailEvent(ctx, record.Event, ErrTransformCode, err)
 					t.offsetManager.EventCommit(record.OffsetInfo)
@@ -315,7 +324,10 @@ func (t *trigger) runEventFilterTransform(ctx context.Context) {
 				if err != nil {
 					log.Info(ctx).Err(err).
 						Str("event_id", event.record.Event.ID()).
-						Interface("event_offset", event.record.OffsetInfo).
+						Str(log.KeySubscriptionID, t.subscriptionIDStr).
+						Str(log.KeyEventbusID, t.eventbusIDStr).
+						Stringer(log.KeyEventlogID, event.record.EventlogID).
+						Uint64("event_offset", event.record.OffsetInfo.Offset).
 						Msg("event transform error")
 					t.writeFailEvent(ctx, record.Event, ErrTransformCode, err)
 					t.offsetManager.EventCommit(record.OffsetInfo)
@@ -395,7 +407,7 @@ func (t *trigger) processEvent(ctx context.Context, events ...*toSendEvent) {
 	es := make([]*ce.Event, l)
 	for i := range events {
 		if events[i].retry {
-			retryEventCnt += 1
+			retryEventCnt++
 		}
 		es[i] = events[i].transform
 	}
@@ -406,7 +418,11 @@ func (t *trigger) processEvent(ctx context.Context, events ...*toSendEvent) {
 			Int("code", r.StatusCode).
 			Int("count", l).
 			Str("event_id", events[0].record.Event.ID()).
-			Interface("event_offset", events[0].record.OffsetInfo).
+			Interface("target", t.subscription.Sink).
+			Str(log.KeySubscriptionID, t.subscriptionIDStr).
+			Str(log.KeyEventbusID, t.eventbusIDStr).
+			Stringer(log.KeyEventlogID, events[0].record.EventlogID).
+			Uint64("event_offset", events[0].record.OffsetInfo.Offset).
 			Msg("send event fail")
 		code := r.StatusCode
 		if t.config.Ordered {
@@ -427,11 +443,11 @@ func (t *trigger) processEvent(ctx context.Context, events ...*toSendEvent) {
 			Msg("send event success")
 	}
 	if retryEventCnt > 0 {
-		metrics.TriggerPushEventCounter.WithLabelValues(t.subscriptionIDStr, t.subscription.EventbusID.String(), metrics.LabelTrue, result).
+		metrics.TriggerPushEventCounter.WithLabelValues(t.subscriptionIDStr, t.eventbusIDStr, metrics.LabelTrue, result).
 			Add(float64(retryEventCnt))
 	}
 	if l > retryEventCnt {
-		metrics.TriggerPushEventCounter.WithLabelValues(t.subscriptionIDStr, t.subscription.EventbusID.String(), metrics.LabelFalse, result).
+		metrics.TriggerPushEventCounter.WithLabelValues(t.subscriptionIDStr, t.eventbusIDStr, metrics.LabelFalse, result).
 			Add(float64(l - retryEventCnt))
 	}
 }
@@ -488,7 +504,7 @@ func (t *trigger) writeEventToRetry(ctx context.Context, e *ce.Event, attempts i
 			Observe(time.Since(startTime).Seconds())
 		if err != nil {
 			log.Info(ctx).Err(err).
-				Stringer(log.KeySubscriptionID, t.subscription.ID).
+				Str(log.KeySubscriptionID, t.subscriptionIDStr).
 				Int("attempt", writeAttempt).
 				Interface("event", e).
 				Msg("write retry event error")
@@ -502,7 +518,7 @@ func (t *trigger) writeEventToRetry(ctx context.Context, e *ce.Event, attempts i
 		}
 	}
 	log.Debug(ctx).
-		Stringer(log.KeySubscriptionID, t.subscription.ID).
+		Str(log.KeySubscriptionID, t.subscriptionIDStr).
 		Interface("event", e).
 		Msg("write retry event success")
 }
@@ -523,7 +539,7 @@ func (t *trigger) writeEventToDeadLetter(ctx context.Context, e *ce.Event, reaso
 			Observe(time.Since(startTime).Seconds())
 		if err != nil {
 			log.Info(ctx).Err(err).
-				Stringer(log.KeySubscriptionID, t.subscription.ID).
+				Str(log.KeySubscriptionID, t.subscriptionIDStr).
 				Int("attempt", writeAttempt).
 				Interface("event", e).
 				Msg("write dl event error")
@@ -536,7 +552,7 @@ func (t *trigger) writeEventToDeadLetter(ctx context.Context, e *ce.Event, reaso
 		}
 	}
 	log.Debug(ctx).
-		Stringer(log.KeySubscriptionID, t.subscription.ID).
+		Str(log.KeySubscriptionID, t.subscriptionIDStr).
 		Interface("event", e).
 		Msg("write dl event success")
 }
@@ -572,7 +588,11 @@ func getOffset(sub *primitive.Subscription) map[vanus.ID]uint64 {
 }
 
 func (t *trigger) Init(ctx context.Context) error {
-	t.eventCli = newEventClient(t.subscription.Sink, t.subscription.Protocol, t.subscription.SinkCredential)
+	t.eventCli = newEventClient(clientConfig{
+		sink:       t.subscription.Sink,
+		protocol:   t.subscription.Protocol,
+		credential: t.subscription.SinkCredential,
+		gateway:    t.config.TargetGateway})
 	t.client = eb.Connect(t.config.Controllers)
 
 	t.timerEventWriter = t.client.Eventbus(ctx, api.WithID(
@@ -592,7 +612,7 @@ func (t *trigger) Init(ctx context.Context) error {
 
 func (t *trigger) Start(ctx context.Context) error {
 	log.Info(ctx).
-		Stringer(log.KeySubscriptionID, t.subscription.ID).
+		Str(log.KeySubscriptionID, t.subscriptionIDStr).
 		Msg("trigger start...")
 	ctx, cancel := context.WithCancel(context.Background())
 	t.stop = cancel
@@ -613,14 +633,14 @@ func (t *trigger) Start(ctx context.Context) error {
 	t.wg.StartWithContext(ctx, t.runRetryEventFilterTransform)
 	t.state = TriggerRunning
 	log.Info(ctx).
-		Stringer(log.KeySubscriptionID, t.subscription.ID).
+		Str(log.KeySubscriptionID, t.subscriptionIDStr).
 		Msg("trigger started")
 	return nil
 }
 
 func (t *trigger) Stop(ctx context.Context) error {
 	log.Info(ctx).
-		Stringer(log.KeySubscriptionID, t.subscription.ID).
+		Str(log.KeySubscriptionID, t.subscriptionIDStr).
 		Msg("trigger stop...")
 
 	if t.state == TriggerStopped {
@@ -638,7 +658,7 @@ func (t *trigger) Stop(ctx context.Context) error {
 	t.offsetManager.Close()
 	t.state = TriggerStopped
 	log.Info(ctx).
-		Stringer(log.KeySubscriptionID, t.subscription.ID).
+		Str(log.KeySubscriptionID, t.subscriptionIDStr).
 		Msg("trigger stopped")
 	return nil
 }
diff --git a/server/trigger/trigger/util.go b/server/trigger/trigger/util.go
index 706e28d..201ddb1 100644
--- a/server/trigger/trigger/util.go
+++ b/server/trigger/trigger/util.go
@@ -25,20 +25,29 @@ import (
 	"github.com/vanus-labs/vanus/server/trigger/client"
 )
 
-func newEventClient(sink primitive.URI,
-	protocol primitive.Protocol,
-	credential primitive.SinkCredential) client.EventClient {
-	switch protocol {
+type clientConfig struct {
+	gateway    *TargetGateway
+	sink       primitive.URI
+	protocol   primitive.Protocol
+	credential primitive.SinkCredential
+}
+
+func newEventClient(cfg clientConfig) client.EventClient {
+	sink := string(cfg.sink)
+	switch cfg.protocol {
 	case primitive.AwsLambdaProtocol:
-		_credential, _ := credential.(*primitive.AkSkSinkCredential)
-		return client.NewAwsLambdaClient(_credential.AccessKeyID, _credential.SecretAccessKey, string(sink))
+		_credential, _ := cfg.credential.(*primitive.AkSkSinkCredential)
+		return client.NewAwsLambdaClient(_credential.AccessKeyID, _credential.SecretAccessKey, sink)
 	case primitive.GCloudFunctions:
-		_credential, _ := credential.(*primitive.GCloudSinkCredential)
-		return client.NewGCloudFunctionClient(string(sink), _credential.CredentialJSON)
+		_credential, _ := cfg.credential.(*primitive.GCloudSinkCredential)
+		return client.NewGCloudFunctionClient(sink, _credential.CredentialJSON)
 	case primitive.GRPC:
-		return client.NewGRPCClient(string(sink))
+		return client.NewGRPCClient(sink)
 	default:
-		return client.NewHTTPClient(string(sink))
+		if cfg.gateway != nil {
+			return client.NewHTTPClientWithGateway(sink, cfg.gateway.Address, cfg.gateway.TargetHeaderName)
+		}
+		return client.NewHTTPClient(sink)
 	}
 }
 
diff --git a/server/trigger/worker.go b/server/trigger/worker.go
index bfeec0a..866c4c7 100644
--- a/server/trigger/worker.go
+++ b/server/trigger/worker.go
@@ -261,6 +261,7 @@ func (w *worker) getTriggerOptions(subscription *primitive.Subscription) []trigg
 		trigger.WithGoroutineSize(w.config.SendEventGoroutineSize),
 		trigger.WithSendBatchSize(w.config.SendEventBatchSize),
 		trigger.WithPullBatchSize(w.config.PullEventBatchSize),
-		trigger.WithMaxUACKNumber(w.config.MaxUACKEventNumber))
+		trigger.WithMaxUACKNumber(w.config.MaxUACKEventNumber),
+		trigger.WithProxy(w.config.Gateway))
 	return opts
 }


Test patch:
diff --git a/server/trigger/trigger/util_test.go b/server/trigger/trigger/util_test.go
index dec7a72..14319f4 100644
--- a/server/trigger/trigger/util_test.go
+++ b/server/trigger/trigger/util_test.go
@@ -26,13 +26,13 @@ import (
 func TestNewEventClient(t *testing.T) {
 	Convey("test new event client", t, func() {
 		Convey("new lambda client", func() {
-			cli := newEventClient("test", primitive.AwsLambdaProtocol,
-				primitive.NewAkSkSinkCredential("ak", "sk"))
+			cli := newEventClient(clientConfig{sink: "test", protocol: primitive.AwsLambdaProtocol,
+				credential: primitive.NewAkSkSinkCredential("ak", "sk")})
 			So(cli, ShouldNotBeNil)
 		})
 		Convey("new http client", func() {
-			cli := newEventClient("test", primitive.HTTPProtocol,
-				primitive.NewPlainSinkCredential("identifier", "secret"))
+			cli := newEventClient(clientConfig{sink: "test", protocol: primitive.HTTPProtocol,
+				credential: primitive.NewPlainSinkCredential("identifier", "secret")})
 			So(cli, ShouldNotBeNil)
 		})
 	})