slime-io / slime

An intelligent ServiceMesh manager based on Istio
https://slime-io.github.io/
Other
426 stars 78 forks source link

meshreg: nacos source support custom instance service name #330

Closed believening closed 1 year ago

believening commented 1 year ago

At some point we need to regroup the instances that fetch from the registry, which means reassigning them to new Service. For this, we need a mechanism to customize the instance service name, then group the instances by the new service name.

We introduced the ServiceNaming field in the SourceArgs to configure to enable Rename&Regroup. A nonil ServiceNaming means enable.

The struct of ServiceNaming is

type ServiceNameConverter struct {
    Sep   string              `json:"Sep,omitempty"`
    Items []ServiceNamingItem `json:"Items,omitempty"`
}

type ServiceNamingItem struct {
    Kind  ServiceNameItemKind `json:"Kind,omitempty"`
    Value string              `json:"Value,omitempty"`
}

Each ServiceNamingItem configure how a service name substring is generated, then using the Seq to connect the substrings.

In ServiceNamingItem, The Kind field indicates the data source of the substring and configurable values are $, static and meta.

NOTE: only support nacos source for now.


For example:

An instance with a registered service name of demo and a metadata include of env:prod will have a new service name of demo.prod. When using the following configuration:

LEGACY:
  NacosSource:
    Enabled: true
    Address:
    - "http://1.1.1.1:8848"
    Mode: polling
    ServiceNaming:
      Sep: "."
      Items:
      - Kind: "$"
        Value: "service"
      - Kind: "meta"
        Value: "env"