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.
$: basic information of the instance, supports service(the original service name of the instance), ip(the instance ip), port(the instance port).
meta: metadata of the instance, the value of the Value field is the extracted key specified in the metadata.
static: static configuration, directly using the value of the Value field.
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:
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 theSourceArgs
to configure to enable Rename&Regroup. A nonilServiceNaming
means enable.The struct of
ServiceNaming
isEach
ServiceNamingItem
configure how a service name substring is generated, then using theSeq
to connect the substrings.In ServiceNamingItem, The Kind field indicates the data source of the substring and configurable values are
$
,static
andmeta
.$
: basic information of the instance, supportsservice
(the original service name of the instance),ip
(the instance ip),port
(the instance port).meta
: metadata of the instance, the value of the Value field is the extracted key specified in the metadata.static
: static configuration, directly using the value of the Value field.NOTE: only support nacos source for now.
For example:
An instance with a registered service name of
demo
and a metadata include ofenv:prod
will have a new service name ofdemo.prod
. When using the following configuration: