Repository: vanus-labs/vanus
Pull request #529 (2023-03-13 05:47:21)

feat: subscription create need namespace
<!--

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://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) Report
> Merging [#529](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) (52fb137) into [main](https://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 `1.21%`.
> The diff coverage is `54.41%`.

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/vanus-labs/vanus/pull/529/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://codecov.io/gh/vanus-labs/vanus/pull/529?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     #529      +/-   ##
==========================================
- Coverage   57.07%   55.86%   -1.21%     
==========================================
  Files         190      191       +1     
  Lines       15191    15509     +318     
==========================================
- Hits         8670     8664       -6     
- Misses       5884     6197     +313     
- Partials      637      648      +11     
```


| [Impacted Files](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) | Coverage Δ | |
|---|---|---|
| [internal/controller/eventbus/block/block.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvY29udHJvbGxlci9ldmVudGJ1cy9ibG9jay9ibG9jay5nbw==) | `35.93% <0.00%> (-16.70%)` | :arrow_down: |
| [internal/controller/eventbus/block/selector.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvY29udHJvbGxlci9ldmVudGJ1cy9ibG9jay9zZWxlY3Rvci5nbw==) | `91.66% <ø> (-8.34%)` | :arrow_down: |
| [internal/controller/trigger/storage/storage.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvY29udHJvbGxlci90cmlnZ2VyL3N0b3JhZ2Uvc3RvcmFnZS5nbw==) | `0.00% <ø> (ø)` | |
| [internal/controller/trigger/worker/policy.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvY29udHJvbGxlci90cmlnZ2VyL3dvcmtlci9wb2xpY3kuZ28=) | `100.00% <ø> (ø)` | |
| [internal/gateway/config.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvZ2F0ZXdheS9jb25maWcuZ28=) | `61.11% <ø> (ø)` | |
| [internal/gateway/proxy/deadletter.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvZ2F0ZXdheS9wcm94eS9kZWFkbGV0dGVyLmdv) | `0.00% <0.00%> (ø)` | |
| [internal/primitive/cel/cel.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvcHJpbWl0aXZlL2NlbC9jZWwuZ28=) | `68.57% <0.00%> (ø)` | |
| [...rnal/primitive/interceptor/errinterceptor/error.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvcHJpbWl0aXZlL2ludGVyY2VwdG9yL2VycmludGVyY2VwdG9yL2Vycm9yLmdv) | `0.00% <0.00%> (ø)` | |
| [.../primitive/interceptor/memberinterceptor/member.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvcHJpbWl0aXZlL2ludGVyY2VwdG9yL21lbWJlcmludGVyY2VwdG9yL21lbWJlci5nbw==) | `0.00% <0.00%> (ø)` | |
| [internal/primitive/queue/queue.go](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvcHJpbWl0aXZlL3F1ZXVlL3F1ZXVlLmdv) | `87.87% <ø> (ø)` | |
| ... and [101 more](https://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) | |

... and [29 files with indirect coverage changes](https://codecov.io/gh/vanus-labs/vanus/pull/529/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://codecov.io/gh/vanus-labs/vanus/pull/529?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://codecov.io/gh/vanus-labs/vanus/pull/529?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs). Last update [942fc6a...52fb137](https://codecov.io/gh/vanus-labs/vanus/pull/529?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).

</details>

Patch:
diff --git a/internal/controller/trigger/controller.go b/internal/controller/trigger/controller.go
index 1bc6aa8..ec345e1 100644
--- a/internal/controller/trigger/controller.go
+++ b/internal/controller/trigger/controller.go
@@ -179,13 +179,6 @@ func (ctrl *controller) CreateSubscription(ctx context.Context,
 		})
 		return nil, err
 	}
-	// subscription name can't be repeated in an eventbus
-	eventbusID := vanus.NewIDFromUint64(request.Subscription.EventbusId)
-	_sub := ctrl.subscriptionManager.GetSubscriptionByName(ctx, eventbusID, request.Subscription.Name)
-	if _sub != nil {
-		return nil, errors.ErrInvalidRequest.WithMessage(
-			fmt.Sprintf("subscription name %s has exist", request.Subscription.Name))
-	}
 	sub := convert.FromPbSubscriptionRequest(request.Subscription)
 	sub.ID, err = vanus.NewID()
 	sub.CreatedAt = time.Now()
@@ -230,14 +223,6 @@ func (ctrl *controller) UpdateSubscription(ctx context.Context,
 	if request.Subscription.EventbusId != uint64(sub.EventbusID) {
 		return nil, errors.ErrInvalidRequest.WithMessage("can not change eventbus")
 	}
-	if request.Subscription.Name != sub.Name {
-		// subscription name can't be repeated in an eventbus
-		_sub := ctrl.subscriptionManager.GetSubscriptionByName(ctx, sub.EventbusID, request.Subscription.Name)
-		if _sub != nil {
-			return nil, errors.ErrInvalidRequest.WithMessage(
-				fmt.Sprintf("subscription name %s has exist", request.Subscription.Name))
-		}
-	}
 	update := convert.FromPbSubscriptionRequest(request.Subscription)
 	transChange := 0
 	if !sub.Transformer.Exist() && update.Transformer.Exist() {
diff --git a/internal/controller/trigger/metadata/info.go b/internal/controller/trigger/metadata/info.go
index c04eba4..b00bfb4 100644
--- a/internal/controller/trigger/metadata/info.go
+++ b/internal/controller/trigger/metadata/info.go
@@ -76,6 +76,7 @@ type Subscription struct {
 	Protocol           primitive.Protocol              `json:"protocol,omitempty"`
 	ProtocolSetting    *primitive.ProtocolSetting      `json:"protocol_settings,omitempty"`
 	EventbusID         vanus.ID                        `json:"eventbus_id"`
+	NamespaceID        vanus.ID                        `json:"namespace_id"`
 	Transformer        *primitive.Transformer          `json:"transformer,omitempty"`
 	Name               string                          `json:"name"`
 	Description        string                          `json:"description"`
diff --git a/internal/controller/trigger/subscription/subscription.go b/internal/controller/trigger/subscription/subscription.go
index 342e479..4f087ae 100644
--- a/internal/controller/trigger/subscription/subscription.go
+++ b/internal/controller/trigger/subscription/subscription.go
@@ -48,7 +48,7 @@ type Manager interface {
 	ResetOffsetByTimestamp(ctx context.Context, id vanus.ID, timestamp uint64) (info.ListOffsetInfo, error)
 	ListSubscription(ctx context.Context) []*metadata.Subscription
 	GetSubscription(ctx context.Context, id vanus.ID) *metadata.Subscription
-	GetSubscriptionByName(ctx context.Context, eventbusID vanus.ID, name string) *metadata.Subscription
+	GetSubscriptionByName(ctx context.Context, namespaceID vanus.ID, name string) *metadata.Subscription
 	AddSubscription(ctx context.Context, subscription *metadata.Subscription) error
 	UpdateSubscription(ctx context.Context, subscription *metadata.Subscription) error
 	Heartbeat(ctx context.Context, id vanus.ID, addr string, time time.Time) error
@@ -104,11 +104,11 @@ func (m *manager) ListSubscription(_ context.Context) []*metadata.Subscription {
 	return list
 }
 
-func (m *manager) GetSubscriptionByName(ctx context.Context, eventbusID vanus.ID, name string) *metadata.Subscription {
+func (m *manager) GetSubscriptionByName(ctx context.Context, namespaceID vanus.ID, name string) *metadata.Subscription {
 	m.lock.RLock()
 	defer m.lock.RUnlock()
 	for _, sub := range m.subscriptionMap {
-		if sub.EventbusID != eventbusID {
+		if sub.NamespaceID != namespaceID {
 			continue
 		}
 		if sub.Name == name {
diff --git a/internal/controller/trigger/validation/subscripton.go b/internal/controller/trigger/validation/subscripton.go
index b23b969..3ba7a65 100644
--- a/internal/controller/trigger/validation/subscripton.go
+++ b/internal/controller/trigger/validation/subscripton.go
@@ -24,6 +24,7 @@ import (
 	"google.golang.org/api/idtoken"
 	"google.golang.org/api/option"
 
+	"github.com/vanus-labs/vanus/internal/primitive/vanus"
 	"github.com/vanus-labs/vanus/pkg/errors"
 	ctrlpb "github.com/vanus-labs/vanus/proto/pkg/controller"
 	metapb "github.com/vanus-labs/vanus/proto/pkg/meta"
@@ -32,10 +33,15 @@ import (
 	"github.com/vanus-labs/vanus/internal/primitive/cel"
 	"github.com/vanus-labs/vanus/internal/primitive/transform/arg"
 	"github.com/vanus-labs/vanus/internal/primitive/transform/runtime"
-	"github.com/vanus-labs/vanus/internal/primitive/vanus"
 )
 
 func ValidateSubscriptionRequest(ctx context.Context, request *ctrlpb.SubscriptionRequest) error {
+	if request.NamespaceId == vanus.EmptyID().Uint64() {
+		return errors.ErrInvalidRequest.WithMessage("namespace is empty")
+	}
+	if request.EventbusId == vanus.EmptyID().Uint64() {
+		return errors.ErrInvalidRequest.WithMessage("eventbus is empty")
+	}
 	if err := ValidateFilterList(ctx, request.Filters); err != nil {
 		return errors.ErrInvalidRequest.WithMessage("filters is invalid").Wrap(err)
 	}
@@ -48,9 +54,6 @@ func ValidateSubscriptionRequest(ctx context.Context, request *ctrlpb.Subscripti
 	if err := validateSinkCredential(ctx, request.Sink, request.SinkCredential); err != nil {
 		return err
 	}
-	if request.EventbusId == vanus.EmptyID().Uint64() {
-		return errors.ErrInvalidRequest.WithMessage("eventbus is empty")
-	}
 	if request.Name == "" {
 		return errors.ErrInvalidRequest.WithMessage("name is empty")
 	}
diff --git a/internal/convert/convert.go b/internal/convert/convert.go
index e52868d..ec7deb5 100644
--- a/internal/convert/convert.go
+++ b/internal/convert/convert.go
@@ -40,6 +40,7 @@ func FromPbSubscriptionRequest(sub *ctrl.SubscriptionRequest) *metadata.Subscrip
 		Filters:            fromPbFilters(sub.Filters),
 		Transformer:        fromPbTransformer(sub.Transformer),
 		EventbusID:         vanus.NewIDFromUint64(sub.EventbusId),
+		NamespaceID:        vanus.NewIDFromUint64(sub.NamespaceId),
 		Name:               sub.Name,
 		Description:        sub.Description,
 	}
@@ -295,6 +296,7 @@ func ToPbSubscription(sub *metadata.Subscription, offsets info.ListOffsetInfo) *
 		Protocol:         toPbProtocol(sub.Protocol),
 		ProtocolSettings: toPbProtocolSettings(sub.ProtocolSetting),
 		EventbusId:       sub.EventbusID.Uint64(),
+		NamespaceId:      sub.NamespaceID.Uint64(),
 		Filters:          toPbFilters(sub.Filters),
 		Transformer:      ToPbTransformer(sub.Transformer),
 		Offsets:          ToPbOffsetInfos(offsets),
diff --git a/vsctl/command/subscription.go b/vsctl/command/subscription.go
index 6a4ccc3..2291a4c 100644
--- a/vsctl/command/subscription.go
+++ b/vsctl/command/subscription.go
@@ -96,6 +96,7 @@ func createSubscriptionCommand() *cobra.Command {
 					Sink:           sink,
 					SinkCredential: credential,
 					Protocol:       p,
+					NamespaceId:    mustGetNamespaceID(namespace).Uint64(),
 					EventbusId:     mustGetEventbusID(namespace, eventbus).Uint64(),
 					Transformer:    trans,
 					Name:           subscriptionName,
@@ -358,6 +359,7 @@ func updateSubscriptionCommand() *cobra.Command {
 					Sink:           sub.Sink,
 					SinkCredential: sub.SinkCredential,
 					Protocol:       sub.Protocol,
+					NamespaceId:    mustGetNamespaceID(namespace).Uint64(),
 					EventbusId:     mustGetEventbusID(namespace, eventbus).Uint64(),
 					Transformer:    sub.Transformer,
 					Name:           sub.Name,
@@ -577,6 +579,9 @@ func listSubscriptionCommand() *cobra.Command {
 			request := &ctrlpb.ListSubscriptionRequest{
 				Name: subscriptionName,
 			}
+			if namespace != "" {
+				request.NamespaceId = mustGetNamespaceID(namespace).Uint64()
+			}
 			if eventbus != "" {
 				request.EventbusId = mustGetEventbusID(namespace, eventbus).Uint64()
 			}


Test patch:
diff --git a/internal/controller/trigger/controller_test.go b/internal/controller/trigger/controller_test.go
index ea781b8..179296c 100644
--- a/internal/controller/trigger/controller_test.go
+++ b/internal/controller/trigger/controller_test.go
@@ -130,9 +130,10 @@ func TestController_CreateSubscription(t *testing.T) {
 			subManager.EXPECT().AddSubscription(gomock.Any(), gomock.Any()).AnyTimes().Return(nil)
 			create := &ctrlpb.CreateSubscriptionRequest{
 				Subscription: &ctrlpb.SubscriptionRequest{
-					EventbusId: vanus.NewTestID().Uint64(),
-					Name:       "test-name",
-					Sink:       "test-sink",
+					NamespaceId: vanus.NewTestID().Uint64(),
+					EventbusId:  vanus.NewTestID().Uint64(),
+					Name:        "test-name",
+					Sink:        "test-sink",
 				},
 			}
 			request := create.Subscription
@@ -141,10 +142,12 @@ func TestController_CreateSubscription(t *testing.T) {
 			So(err, ShouldBeNil)
 			So(resp.Sink, ShouldEqual, request.Sink)
 			So(resp.EventbusId, ShouldEqual, request.EventbusId)
+			So(resp.NamespaceId, ShouldEqual, request.NamespaceId)
 			resp2, err := ctrl.CreateSubscription(ctx, create)
 			So(err, ShouldBeNil)
 			So(resp2.Sink, ShouldEqual, request.Sink)
 			So(resp2.EventbusId, ShouldEqual, request.EventbusId)
+			So(resp2.NamespaceId, ShouldEqual, request.NamespaceId)
 			So(resp.Id, ShouldNotEqual, resp2.Id)
 		})
 	})
@@ -164,6 +167,7 @@ func TestController_UpdateSubscription(t *testing.T) {
 
 		subID := vanus.NewTestID()
 		eventbusID := vanus.NewTestID()
+		namespaceID := vanus.NewTestID()
 		ctrl.state = primitive.ServerStateRunning
 		Convey("update subscription not exist", func() {
 			subManager.EXPECT().GetSubscription(gomock.Any(), gomock.Eq(subID)).Return(nil)
@@ -181,6 +185,7 @@ func TestController_UpdateSubscription(t *testing.T) {
 			Phase:         metadata.SubscriptionPhaseStopped,
 			TriggerWorker: "test-addr",
 			EventbusID:    eventbusID,
+			NamespaceID:   namespaceID,
 			Name:          "test-name",
 			Sink:          "test-sink",
 			Protocol:      primitive.HTTPProtocol,
@@ -194,8 +199,21 @@ func TestController_UpdateSubscription(t *testing.T) {
 			request := &ctrlpb.UpdateSubscriptionRequest{
 				Id: subID.Uint64(),
 				Subscription: &ctrlpb.SubscriptionRequest{
-					EventbusId: eventbusID.Uint64(),
-					Sink:       "test-sink",
+					NamespaceId: namespaceID.Uint64(),
+					EventbusId:  eventbusID.Uint64(),
+					Sink:        "test-sink",
+				},
+			}
+			_, err := ctrl.UpdateSubscription(ctx, request)
+			So(err, ShouldNotBeNil)
+		})
+		Convey("tet update namespace fail", func() {
+			request := &ctrlpb.UpdateSubscriptionRequest{
+				Id: subID.Uint64(),
+				Subscription: &ctrlpb.SubscriptionRequest{
+					NamespaceId: vanus.NewTestID().Uint64(),
+					EventbusId:  eventbusID.Uint64(),
+					Sink:        "test-sink",
 				},
 			}
 			_, err := ctrl.UpdateSubscription(ctx, request)
@@ -205,8 +223,9 @@ func TestController_UpdateSubscription(t *testing.T) {
 			request := &ctrlpb.UpdateSubscriptionRequest{
 				Id: subID.Uint64(),
 				Subscription: &ctrlpb.SubscriptionRequest{
-					EventbusId: vanus.NewTestID().Uint64(),
-					Sink:       "test-sink",
+					NamespaceId: namespaceID.Uint64(),
+					EventbusId:  vanus.NewTestID().Uint64(),
+					Sink:        "test-sink",
 				},
 			}
 			_, err := ctrl.UpdateSubscription(ctx, request)
@@ -217,9 +236,10 @@ func TestController_UpdateSubscription(t *testing.T) {
 				request := &ctrlpb.UpdateSubscriptionRequest{
 					Id: subID.Uint64(),
 					Subscription: &ctrlpb.SubscriptionRequest{
-						EventbusId: eventbusID.Uint64(),
-						Sink:       "test-sink",
-						Protocol:   metapb.Protocol_AWS_LAMBDA,
+						NamespaceId: namespaceID.Uint64(),
+						EventbusId:  eventbusID.Uint64(),
+						Sink:        "test-sink",
+						Protocol:    metapb.Protocol_AWS_LAMBDA,
 						SinkCredential: &metapb.SinkCredential{
 							CredentialType: metapb.SinkCredential_AWS,
 						},
@@ -232,9 +252,10 @@ func TestController_UpdateSubscription(t *testing.T) {
 				request := &ctrlpb.UpdateSubscriptionRequest{
 					Id: subID.Uint64(),
 					Subscription: &ctrlpb.SubscriptionRequest{
-						EventbusId: eventbusID.Uint64(),
-						Sink:       "arn:aws:lambda:us-west-2:843378899134:function:xdltest",
-						Protocol:   metapb.Protocol_AWS_LAMBDA,
+						NamespaceId: namespaceID.Uint64(),
+						EventbusId:  eventbusID.Uint64(),
+						Sink:        "arn:aws:lambda:us-west-2:843378899134:function:xdltest",
+						Protocol:    metapb.Protocol_AWS_LAMBDA,
 						SinkCredential: &metapb.SinkCredential{
 							CredentialType: metapb.SinkCredential_PLAIN,
 						},
@@ -247,9 +268,10 @@ func TestController_UpdateSubscription(t *testing.T) {
 				request := &ctrlpb.UpdateSubscriptionRequest{
 					Id: subID.Uint64(),
 					Subscription: &ctrlpb.SubscriptionRequest{
-						EventbusId: eventbusID.Uint64(),
-						Sink:       "arn:aws:lambda:us-west-2:843378899134:function:xdltest",
-						Protocol:   metapb.Protocol_AWS_LAMBDA,
+						NamespaceId: namespaceID.Uint64(),
+						EventbusId:  eventbusID.Uint64(),
+						Sink:        "arn:aws:lambda:us-west-2:843378899134:function:xdltest",
+						Protocol:    metapb.Protocol_AWS_LAMBDA,
 						SinkCredential: &metapb.SinkCredential{
 							CredentialType: metapb.SinkCredential_AWS,
 						},
@@ -262,10 +284,11 @@ func TestController_UpdateSubscription(t *testing.T) {
 				request := &ctrlpb.UpdateSubscriptionRequest{
 					Id: subID.Uint64(),
 					Subscription: &ctrlpb.SubscriptionRequest{
-						EventbusId: eventbusID.Uint64(),
-						Name:       "test-name",
-						Sink:       "arn:aws:lambda:us-west-2:843378899134:function:xdltest",
-						Protocol:   metapb.Protocol_AWS_LAMBDA,
+						NamespaceId: namespaceID.Uint64(),
+						EventbusId:  eventbusID.Uint64(),
+						Name:        "test-name",
+						Sink:        "arn:aws:lambda:us-west-2:843378899134:function:xdltest",
+						Protocol:    metapb.Protocol_AWS_LAMBDA,
 						SinkCredential: &metapb.SinkCredential{
 							CredentialType: metapb.SinkCredential_AWS,
 							Credential: &metapb.SinkCredential_Aws{
@@ -292,9 +315,10 @@ func TestController_UpdateSubscription(t *testing.T) {
 			request := &ctrlpb.UpdateSubscriptionRequest{
 				Id: subID.Uint64(),
 				Subscription: &ctrlpb.SubscriptionRequest{
-					EventbusId: eventbusID.Uint64(),
-					Name:       "test-name",
-					Sink:       "modify-sink",
+					NamespaceId: namespaceID.Uint64(),
+					EventbusId:  eventbusID.Uint64(),
+					Name:        "test-name",
+					Sink:        "modify-sink",
 				},
 			}
 			resp, err := ctrl.UpdateSubscription(ctx, request)
@@ -308,9 +332,10 @@ func TestController_UpdateSubscription(t *testing.T) {
 			request := &ctrlpb.UpdateSubscriptionRequest{
 				Id: subID.Uint64(),
 				Subscription: &ctrlpb.SubscriptionRequest{
-					EventbusId: eventbusID.Uint64(),
-					Name:       "test-name",
-					Sink:       "test-sink",
+					NamespaceId: namespaceID.Uint64(),
+					EventbusId:  eventbusID.Uint64(),
+					Name:        "test-name",
+					Sink:        "test-sink",
 					Filters: []*metapb.Filter{
 						{
 							Exact: map[string]string{"type": "test"},
@@ -328,9 +353,10 @@ func TestController_UpdateSubscription(t *testing.T) {
 			request := &ctrlpb.UpdateSubscriptionRequest{
 				Id: subID.Uint64(),
 				Subscription: &ctrlpb.SubscriptionRequest{
-					EventbusId: eventbusID.Uint64(),
-					Name:       "test-name",
-					Sink:       "test-sink",
+					NamespaceId: namespaceID.Uint64(),
+					EventbusId:  eventbusID.Uint64(),
+					Name:        "test-name",
+					Sink:        "test-sink",
 					Transformer: &metapb.Transformer{
 						Define:   map[string]string{"k": "v"},
 						Template: "test",
diff --git a/internal/controller/trigger/validation/suscription_test.go b/internal/controller/trigger/validation/suscription_test.go
index 2721744..ccd9e03 100644
--- a/internal/controller/trigger/validation/suscription_test.go
+++ b/internal/controller/trigger/validation/suscription_test.go
@@ -30,6 +30,8 @@ func TestSubscriptionRequestValidator(t *testing.T) {
 	ctx := context.Background()
 	Convey("multiple dialect", t, func() {
 		request := &ctrlpb.SubscriptionRequest{
+			NamespaceId: vanus.NewTestID().Uint64(),
+			EventbusId:  vanus.NewTestID().Uint64(),
 			Filters: []*metapb.Filter{{
 				Not: &metapb.Filter{
 					Exact: map[string]string{
@@ -43,8 +45,7 @@ func TestSubscriptionRequestValidator(t *testing.T) {
 	})
 	Convey("eventbus empty", t, func() {
 		request := &ctrlpb.SubscriptionRequest{
-			Sink:       "sink",
-			EventbusId: vanus.EmptyID().Uint64(),
+			Sink: "sink",
 		}
 		So(ValidateSubscriptionRequest(ctx, request), ShouldNotBeNil)
 	})