Repository: vanus-labs/vanus
Pull request #512 (2023-03-10 10:26:08)

refactor: change metadata key
<!--

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/512?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) Report
> Merging [#512](https://codecov.io/gh/vanus-labs/vanus/pull/512?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) (b317f5c) 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 `0.56%`.
> The diff coverage is `54.34%`.

> :exclamation: Current head b317f5c differs from pull request most recent head 1c8e083. Consider uploading reports for the commit 1c8e083 to get more accurate results

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


[![Impacted file tree graph](https://codecov.io/gh/vanus-labs/vanus/pull/512/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/512?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     #512      +/-   ##
==========================================
- Coverage   57.07%   56.51%   -0.56%     
==========================================
  Files         190      190              
  Lines       15191    15352     +161     
==========================================
+ Hits         8670     8676       +6     
- Misses       5884     6030     +146     
- Partials      637      646       +9     
```


| [Impacted Files](https://codecov.io/gh/vanus-labs/vanus/pull/512?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/512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvY29udHJvbGxlci9ldmVudGJ1cy9ibG9jay9ibG9jay5nbw==) | `52.63% <ø> (ø)` | |
| [internal/controller/eventbus/block/selector.go](https://codecov.io/gh/vanus-labs/vanus/pull/512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvY29udHJvbGxlci9ldmVudGJ1cy9ibG9jay9zZWxlY3Rvci5nbw==) | `100.00% <ø> (ø)` | |
| [internal/controller/eventbus/server/instance.go](https://codecov.io/gh/vanus-labs/vanus/pull/512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs#diff-aW50ZXJuYWwvY29udHJvbGxlci9ldmVudGJ1cy9zZXJ2ZXIvaW5zdGFuY2UuZ28=) | `72.04% <ø> (ø)` | |
| [internal/controller/trigger/storage/storage.go](https://codecov.io/gh/vanus-labs/vanus/pull/512?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/512?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/512?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/512?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/512?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/512?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/512?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%> (ø)` | |
| ... and [102 more](https://codecov.io/gh/vanus-labs/vanus/pull/512?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs) | |

... and [21 files with indirect coverage changes](https://codecov.io/gh/vanus-labs/vanus/pull/512/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/512?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/512?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vanus-labs). Last update [b7c178d...1c8e083](https://codecov.io/gh/vanus-labs/vanus/pull/512?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/eventbus/controller.go b/internal/controller/eventbus/controller.go
index 22d3456..d6402c1 100644
--- a/internal/controller/eventbus/controller.go
+++ b/internal/controller/eventbus/controller.go
@@ -218,7 +218,7 @@ func (ctrl *controller) createEventbus(
 		CreatedAt:   time.Now(),
 		UpdatedAt:   time.Now(),
 	}
-	exist, err := ctrl.kvStore.Exists(ctx, metadata.GetEventbusMetadataKey(eb.Name))
+	exist, err := ctrl.kvStore.Exists(ctx, metadata.GetEventbusMetadataKey(id))
 	if err != nil {
 		return nil, err
 	}
@@ -236,16 +236,15 @@ func (ctrl *controller) createEventbus(
 
 	{
 		data, _ := json.Marshal(eb)
-		if err := ctrl.kvStore.Set(ctx, metadata.GetEventbusMetadataKey(eb.Name), data); err != nil {
+		if err := ctrl.kvStore.Set(ctx, metadata.GetEventbusMetadataKey(id), data); err != nil {
 			return nil, err
 		}
 	}
 	return ctrl.getEventbus(eb.ID)
 }
 
-func (ctrl *controller) getDeadLetterEventbusID(ctx context.Context, id vanus.ID) vanus.ID {
+func (ctrl *controller) getDeadLetterEventbusID(_ context.Context, id vanus.ID) vanus.ID {
 	deadLetterEventbusName := primitive.GetDeadLetterEventbusName(id)
-	//
 	for _id, eb := range ctrl.eventbusMap {
 		if eb.Name == deadLetterEventbusName {
 			return _id
@@ -280,7 +279,7 @@ func (ctrl *controller) deleteEventbus(ctx context.Context, id vanus.ID) error {
 	if !exist {
 		return errors.ErrResourceNotFound.WithMessage("the eventbus doesn't exist")
 	}
-	err := ctrl.kvStore.Delete(ctx, metadata.GetEventbusMetadataKey(bus.Name))
+	err := ctrl.kvStore.Delete(ctx, metadata.GetEventbusMetadataKey(id))
 	if err != nil {
 		return errors.ErrInternal.WithMessage("delete eventbus metadata in kv failed").Wrap(err)
 	}
@@ -675,7 +674,7 @@ func (ctrl *controller) membershipChangedProcessor(ctx context.Context, event me
 
 func (ctrl *controller) loadEventbus(ctx context.Context) error {
 	// load eventbus metadata
-	pairs, err := ctrl.kvStore.List(ctx, metadata.EventbusKeyPrefixInKVStore)
+	pairs, err := ctrl.kvStore.List(ctx, kv.ResourceEventbus)
 	if err != nil {
 		return err
 	}
diff --git a/internal/controller/eventbus/metadata/info.go b/internal/controller/eventbus/metadata/info.go
index c58be70..8e65681 100644
--- a/internal/controller/eventbus/metadata/info.go
+++ b/internal/controller/eventbus/metadata/info.go
@@ -27,7 +27,7 @@ type Eventbus struct {
 	ID          vanus.ID    `json:"id"`
 	Name        string      `json:"name"`
 	LogNumber   int         `json:"log_number"`
-	Eventlogs   []*Eventlog `json:"event_logs"`
+	Eventlogs   []*Eventlog `json:"eventlogs"`
 	Description string      `json:"description"`
 	CreatedAt   time.Time   `json:"created_at"`
 	UpdatedAt   time.Time   `json:"updated_at"`
diff --git a/internal/controller/eventbus/metadata/key.go b/internal/controller/eventbus/metadata/key.go
index 2d881fc..55fd0bb 100644
--- a/internal/controller/eventbus/metadata/key.go
+++ b/internal/controller/eventbus/metadata/key.go
@@ -17,23 +17,23 @@ package metadata
 import (
 	"path"
 
+	"github.com/vanus-labs/vanus/internal/kv"
 	"github.com/vanus-labs/vanus/internal/primitive/vanus"
 )
 
 const (
-	VolumeKeyPrefixInKVStore         = "/vanus/internal/resource/volume/metadata"
-	BlockKeyPrefixInKVStore          = "/vanus/internal/resource/volume/block"
-	VolumeInstanceKeyPrefixInKVStore = "/vanus/internal/resource/volume/instance"
+	VolumeKeyPrefixInKVStore         = kv.ResourceVolumeMetadata
+	BlockKeyPrefixInKVStore          = kv.ResourceVolumeBlock
+	VolumeInstanceKeyPrefixInKVStore = kv.ResourceVolumeInstance
 
-	EventbusKeyPrefixInKVStore = "/vanus/internal/resource/eventbus"
-	EventlogKeyPrefixInKVStore = "/vanus/internal/resource/eventlog"
-	SegmentKeyPrefixInKVStore  = "/vanus/internal/resource/segment"
+	EventlogKeyPrefixInKVStore = kv.ResourceEventlog
+	SegmentKeyPrefixInKVStore  = kv.ResourceSegment
 
-	EventlogSegmentsKeyPrefixInKVStore = "/vanus/internal/resource/segs_of_eventlog"
+	EventlogSegmentsKeyPrefixInKVStore = kv.ResourceSegmentOfEventlog
 )
 
-func GetEventbusMetadataKey(ebName string) string {
-	return path.Join(EventbusKeyPrefixInKVStore, ebName)
+func GetEventbusMetadataKey(id vanus.ID) string {
+	return path.Join(kv.ResourceEventbus, id.Key())
 }
 
 func GetEventlogMetadataKey(elID vanus.ID) string {
@@ -41,7 +41,7 @@ func GetEventlogMetadataKey(elID vanus.ID) string {
 }
 
 func GetBlockMetadataKey(volumeID, blockID vanus.ID) string {
-	return path.Join(BlockKeyPrefixInKVStore, volumeID.Key(), blockID.Key())
+	return path.Join(kv.ResourceVolumeBlock, volumeID.Key(), blockID.Key())
 }
 
 func GetSegmentMetadataKey(segmentID vanus.ID) string {
diff --git a/internal/controller/member/config.go b/internal/controller/member/config.go
index ebae069..31325a0 100644
--- a/internal/controller/member/config.go
+++ b/internal/controller/member/config.go
@@ -21,8 +21,3 @@ type Config struct {
 	ComponentName         string            `yaml:"component_name"`
 	NodeName              string            `yaml:"-"`
 }
-
-const (
-	ResourceLockKeyPrefixInKVStore = "/vanus/internal/resource/resource_lock"
-	LeaderInfoKeyPrefixInKVStore   = "/vanus/internal/resource/leader_info"
-)
diff --git a/internal/controller/member/member.go b/internal/controller/member/member.go
index 126f95d..5fcb403 100644
--- a/internal/controller/member/member.go
+++ b/internal/controller/member/member.go
@@ -27,6 +27,7 @@ import (
 	"go.etcd.io/etcd/client/v3/concurrency"
 	"go.uber.org/atomic"
 
+	"github.com/vanus-labs/vanus/internal/kv"
 	"github.com/vanus-labs/vanus/observability/log"
 )
 
@@ -97,7 +98,7 @@ const (
 )
 
 func (m *member) Init(ctx context.Context) error {
-	m.resourceLockKey = fmt.Sprintf("%s/%s", ResourceLockKeyPrefixInKVStore, m.cfg.ComponentName)
+	m.resourceLockKey = fmt.Sprintf("%s/%s", kv.LeaderLock, m.cfg.ComponentName)
 	m.exit = make(chan struct{})
 
 	err := m.waitForEtcdReady(ctx, m.cfg.EtcdEndpoints)
@@ -258,7 +259,7 @@ func (m *member) setLeader(ctx context.Context) error {
 		LeaderID:   m.cfg.NodeName,
 		LeaderAddr: m.cfg.Topology[m.cfg.NodeName],
 	})
-	_, err := m.client.Put(ctx, LeaderInfoKeyPrefixInKVStore, string(data))
+	_, err := m.client.Put(ctx, kv.LeaderInfo, string(data))
 	return err
 }
 
@@ -343,7 +344,7 @@ func (m *member) IsLeader() bool {
 
 func (m *member) GetLeaderID() string {
 	// TODO(jiangkai): maybe lookup etcd per call has low performance.
-	resp, err := m.client.Get(context.Background(), LeaderInfoKeyPrefixInKVStore)
+	resp, err := m.client.Get(context.Background(), kv.LeaderInfo)
 	if err != nil {
 		log.Warning(context.Background(), "get leader info failed", map[string]interface{}{
 			log.KeyError: err,
@@ -360,7 +361,7 @@ func (m *member) GetLeaderID() string {
 
 func (m *member) GetLeaderAddr() string {
 	// TODO(jiangkai): maybe lookup etcd per call has low performance.
-	resp, err := m.client.Get(context.Background(), LeaderInfoKeyPrefixInKVStore)
+	resp, err := m.client.Get(context.Background(), kv.LeaderInfo)
 	if err != nil {
 		log.Warning(context.Background(), "get leader info failed", map[string]interface{}{
 			log.KeyError: err,
diff --git a/internal/controller/snowflake/snowflake.go b/internal/controller/snowflake/snowflake.go
index 495cb58..d5c3c26 100644
--- a/internal/controller/snowflake/snowflake.go
+++ b/internal/controller/snowflake/snowflake.go
@@ -36,9 +36,7 @@ import (
 )
 
 const (
-	clusterStartAtKey = "/vanus/internal/cluster/start_at"
-	nodeIDKey         = "/vanus/internal/cluster/nodes"
-	spinInterval      = 100 * time.Millisecond
+	spinInterval = 100 * time.Millisecond
 )
 
 type Config struct {
@@ -172,7 +170,7 @@ func (sf *snowflake) membershipChangedProcessor(ctx context.Context, event membe
 			return nil
 		}
 
-		exist, err := sf.kvStore.Exists(ctx, clusterStartAtKey)
+		exist, err := sf.kvStore.Exists(ctx, kv.ClusterStart)
 		if err != nil {
 			return err
 		}
@@ -180,12 +178,12 @@ func (sf *snowflake) membershipChangedProcessor(ctx context.Context, event membe
 		if !exist {
 			now := time.Now()
 			data, _ := now.MarshalJSON()
-			if err = sf.kvStore.Set(ctx, clusterStartAtKey, data); err != nil {
+			if err = sf.kvStore.Set(ctx, kv.ClusterStart, data); err != nil {
 				return err
 			}
 		}
 
-		val, err := sf.kvStore.Get(ctx, clusterStartAtKey)
+		val, err := sf.kvStore.Get(ctx, kv.ClusterStart)
 		if err != nil {
 			return err
 		}
@@ -196,7 +194,7 @@ func (sf *snowflake) membershipChangedProcessor(ctx context.Context, event membe
 		}
 		sf.startAt = startAt
 
-		pairs, err := sf.kvStore.List(ctx, nodeIDKey)
+		pairs, err := sf.kvStore.List(ctx, kv.ClusterNode)
 		if err != nil {
 			return err
 		}
@@ -221,5 +219,5 @@ func (sf *snowflake) membershipChangedProcessor(ctx context.Context, event membe
 }
 
 func GetNodeIDKey(nodeID uint16) string {
-	return path.Join(nodeIDKey, fmt.Sprintf("%d", nodeID))
+	return path.Join(kv.ClusterNode, fmt.Sprintf("%d", nodeID))
 }
diff --git a/internal/controller/trigger/storage/conf.go b/internal/controller/trigger/storage/conf.go
deleted file mode 100644
index 2220dce..0000000
--- a/internal/controller/trigger/storage/conf.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2022 Linkall Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package storage
-
-type KeyPrefix string
-
-func (s KeyPrefix) String() string {
-	return string(s)
-}
-
-const (
-	KeyPrefixOffset        KeyPrefix = "/trigger/offsets/"
-	KeyPrefixSubscription  KeyPrefix = "/trigger/subscriptions/"
-	KeyPrefixTriggerWorker KeyPrefix = "/trigger/triggerWorkers/"
-	KeyPrefixSecret        KeyPrefix = "/trigger/secret/"
-)
diff --git a/internal/controller/trigger/storage/offset.go b/internal/controller/trigger/storage/offset.go
index 63a689b..c4020d4 100644
--- a/internal/controller/trigger/storage/offset.go
+++ b/internal/controller/trigger/storage/offset.go
@@ -49,11 +49,11 @@ func NewOffsetStorage(client kv.Client) OffsetStorage {
 }
 
 func (s *offsetStorage) getKey(subscriptionID, eventlogID vanus.ID) string {
-	return path.Join(KeyPrefixOffset.String(), subscriptionID.String(), eventlogID.String())
+	return path.Join(kv.MetadataOffset, subscriptionID.Key(), eventlogID.Key())
 }
 
 func (s *offsetStorage) getSubKey(subscriptionID vanus.ID) string {
-	return path.Join(KeyPrefixOffset.String(), subscriptionID.String())
+	return path.Join(kv.MetadataSecret, subscriptionID.Key())
 }
 
 func (s *offsetStorage) int64ToByteArr(v uint64) []byte {
diff --git a/internal/controller/trigger/storage/secret.go b/internal/controller/trigger/storage/secret.go
index a84c000..b461fa2 100644
--- a/internal/controller/trigger/storage/secret.go
+++ b/internal/controller/trigger/storage/secret.go
@@ -46,7 +46,7 @@ type SecretStorage struct {
 }
 
 func (p *SecretStorage) getKey(subID vanus.ID) string {
-	return path.Join(KeyPrefixSecret.String(), subID.String())
+	return path.Join(kv.MetadataSecret, subID.Key())
 }
 
 func (p *SecretStorage) Read(ctx context.Context,
diff --git a/internal/controller/trigger/storage/subscription.go b/internal/controller/trigger/storage/subscription.go
index 828600a..f7863b0 100644
--- a/internal/controller/trigger/storage/subscription.go
+++ b/internal/controller/trigger/storage/subscription.go
@@ -46,7 +46,7 @@ func NewSubscriptionStorage(client kv.Client) SubscriptionStorage {
 }
 
 func (s *subscriptionStorage) getKey(subID vanus.ID) string {
-	return path.Join(KeyPrefixSubscription.String(), subID.String())
+	return path.Join(kv.ResourceSubscription, subID.Key())
 }
 
 func (s *subscriptionStorage) CreateSubscription(ctx context.Context, sub *metadata.Subscription) error {
@@ -91,7 +91,7 @@ func (s *subscriptionStorage) GetSubscription(ctx context.Context, id vanus.ID)
 }
 
 func (s *subscriptionStorage) ListSubscription(ctx context.Context) ([]*metadata.Subscription, error) {
-	l, err := s.client.List(ctx, KeyPrefixSubscription.String())
+	l, err := s.client.List(ctx, kv.ResourceSubscription)
 	if err != nil {
 		return nil, err
 	}
diff --git a/internal/controller/trigger/storage/trigger_worker.go b/internal/controller/trigger/storage/trigger_worker.go
index feaa185..2cb7d56 100644
--- a/internal/controller/trigger/storage/trigger_worker.go
+++ b/internal/controller/trigger/storage/trigger_worker.go
@@ -45,7 +45,7 @@ func NewTriggerWorkerStorage(client kv.Client) TriggerWorkerStorage {
 }
 
 func (s *triggerWorkerStorage) getKey(id string) string {
-	return path.Join(KeyPrefixTriggerWorker.String(), id)
+	return path.Join(kv.TriggerWorker, id)
 }
 
 func (s *triggerWorkerStorage) SaveTriggerWorker(ctx context.Context, info metadata.TriggerWorkerInfo) error {
diff --git a/internal/kv/constant.go b/internal/kv/constant.go
new file mode 100644
index 0000000..e98fc58
--- /dev/null
+++ b/internal/kv/constant.go
@@ -0,0 +1,40 @@
+// Copyright 2023 Linkall Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kv
+
+const (
+	ResourceEventbus          = "/vanus/core/eventbus_controller/eventbus"
+	ResourceEventlog          = "/vanus/core/eventbus_controller/eventlog"
+	ResourceSegment           = "/vanus/core/eventbus_controller/segment"
+	ResourceSegmentOfEventlog = "/vanus/core/eventbus_controller/segs_of_eventlog"
+	ResourceVolumeMetadata    = "/vanus/core/eventbus_controller/volume/metadata"
+	ResourceVolumeBlock       = "/vanus/core/eventbus_controller/volume/block"
+	ResourceVolumeInstance    = "/vanus/core/eventbus_controller/volume/instance"
+	ResourceSubscription      = "/vanus/core/trigger_controller/subscriptions"
+	MetadataSecret            = "/vanus/core/trigger_controller/secrets"
+	MetadataOffset            = "/vanus/core/trigger_controller/offsets"
+	TriggerWorker             = "/vanus/core/trigger_controller/trigger_workers"
+	LeaderLock                = "/vanus/core/cluster/resource_lock"
+	LeaderInfo                = "/vanus/core/cluster/leader_info"
+	ClusterNode               = "/vanus/core/cluster/nodes"
+	ClusterStart              = "/vanus/core/cluster/start_at"
+
+	namespace             = "/vanus/core/tenants/namespaces"
+	namespaceEventbus     = "/vanus/core/tenants/{ns_id}/eventbus/{eventbus_id}"
+	namespaceSubscription = "/vanus/core/tenants/{ns_id}/subscription/{subscription_id}"
+	userRoles             = "/vanus/core/tenants/users/{user_id}/roles/{role_id}"
+	roleUsers             = "/vanus/core/tenants/roles/{role_id}/users/{user_id}"
+	rolePermissions       = "/vanus/core/tenants/roles/{role_id}/permissions"
+)
diff --git a/pkg/cluster/raw_client/eventbus.go b/pkg/cluster/raw_client/eventbus.go
index 19aa22b..9892cf3 100644
--- a/pkg/cluster/raw_client/eventbus.go
+++ b/pkg/cluster/raw_client/eventbus.go
@@ -20,10 +20,10 @@ import (
 
 	"google.golang.org/grpc"
 	"google.golang.org/protobuf/types/known/emptypb"
+	"google.golang.org/protobuf/types/known/wrapperspb"
 
 	ctrlpb "github.com/vanus-labs/vanus/proto/pkg/controller"
 	metapb "github.com/vanus-labs/vanus/proto/pkg/meta"
-	wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
 )
 
 var _ io.Closer = (*eventbusClient)(nil)
@@ -111,6 +111,10 @@ func (ec *eventbusClient) UpdateEventbus(
 func (ec *eventbusClient) GetEventbusWithHumanFriendly(
 	ctx context.Context, in *ctrlpb.GetEventbusWithHumanFriendlyRequest, opts ...grpc.CallOption,
 ) (*metapb.Eventbus, error) {
-	// TODO
-	return nil, nil
+	out := new(metapb.Eventbus)
+	err := ec.cc.invoke(ctx, ctrlpb.EventbusController_GetEventbusWithHumanFriendly_FullMethodName, in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
 }


Test patch:
diff --git a/internal/controller/eventbus/controller_test.go b/internal/controller/eventbus/controller_test.go
index 72f9f43..0d9625c 100644
--- a/internal/controller/eventbus/controller_test.go
+++ b/internal/controller/eventbus/controller_test.go
@@ -52,8 +52,8 @@ func TestController_CreateEventbus(t *testing.T) {
 		mockMember.EXPECT().GetLeaderAddr().AnyTimes().Return("test")
 
 		Convey("test create a eventbus two times", func() {
-			kvCli.EXPECT().Exists(ctx, metadata.GetEventbusMetadataKey("test-1")).Times(1).Return(false, nil)
-			kvCli.EXPECT().Set(ctx, metadata.GetEventbusMetadataKey("test-1"), gomock.Any()).
+			kvCli.EXPECT().Exists(ctx, gomock.Any()).Times(1).Return(false, nil)
+			kvCli.EXPECT().Set(ctx, gomock.Any(), gomock.Any()).
 				Times(1).Return(nil)
 			kvCli.EXPECT().Exists(ctx, gomock.Any()).Times(1).Return(false, nil)
 			kvCli.EXPECT().Set(ctx, gomock.Any(), gomock.Any()).
@@ -90,7 +90,7 @@ func TestController_CreateEventbus(t *testing.T) {
 		})
 
 		Convey("test create a eventbus but exist", func() {
-			kvCli.EXPECT().Exists(ctx, metadata.GetEventbusMetadataKey("test-1")).Times(1).Return(true, nil)
+			kvCli.EXPECT().Exists(ctx, gomock.Any()).Times(1).Return(true, nil)
 
 			res, err := ctrl.CreateEventbus(ctx, &ctrlpb.CreateEventbusRequest{
 				Name:      "test-1",
@@ -145,7 +145,7 @@ func TestController_DeleteEventbus(t *testing.T) {
 		}
 
 		Convey("deleting an existed eventbus, but kv error", func() {
-			kvCli.EXPECT().Delete(ctx, metadata.GetEventbusMetadataKey("test-1")).Times(1).
+			kvCli.EXPECT().Delete(ctx, gomock.Any()).Times(1).
 				Return(fmt.Errorf("test"))
 
 			ctrl.eventbusMap[md.ID] = md
@@ -160,7 +160,7 @@ func TestController_DeleteEventbus(t *testing.T) {
 		})
 
 		Convey("deleting an existed eventbus success", func() {
-			kvCli.EXPECT().Delete(ctx, metadata.GetEventbusMetadataKey("test-1")).Times(1).
+			kvCli.EXPECT().Delete(ctx, gomock.Any()).Times(1).
 				Return(nil)
 
 			elMgr.EXPECT().DeleteEventlog(ctx, md.Eventlogs[0].ID).Times(1)
diff --git a/internal/controller/trigger/storage/subscription_test.go b/internal/controller/trigger/storage/subscription_test.go
index 8213d39..ca1ffe2 100644
--- a/internal/controller/trigger/storage/subscription_test.go
+++ b/internal/controller/trigger/storage/subscription_test.go
@@ -107,7 +107,7 @@ func TestListSubscription(t *testing.T) {
 			EventbusID: vanus.NewTestID(),
 		}
 		v, _ := json.Marshal(expect)
-		kvClient.EXPECT().List(ctx, KeyPrefixSubscription.String()).Return([]kv.Pair{
+		kvClient.EXPECT().List(ctx, kv.ResourceSubscription).Return([]kv.Pair{
 			{Key: fmt.Sprintf("%d", subID), Value: v},
 		}, nil)
 		list, err := s.ListSubscription(ctx)