Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The nacos implementation of discovery interface ,custom group name is not supported #1801

Closed
JinPengCN opened this issue Jan 28, 2022 · 0 comments · Fixed by #1798
Closed
Labels
bug Something isn't working

Comments

@JinPengCN
Copy link
Contributor

JinPengCN commented Jan 28, 2022

What happened:

I want to get some registered services,but the program throwed error about: instance list is empty!
invoking like this:

registry.Discovery.GetService(ctx, "myservice")

image

What you expected to happen:

no error

How to reproduce it (as minimally and precisely as possible):

Just call registryDiscovery.GetService()

Anything else we need to know?:

The nacos implementation of discovery interface use nacos-sdk-go mothed: SelectInstances
source code:
(github.com/nacos-group/nacos-sdk-go/clients/naming_client)

func (sc *NamingClient) SelectInstances(param vo.SelectInstancesParam) ([]model.Instance, error) {
	if len(param.GroupName) == 0 {
		param.GroupName = constant.DEFAULT_GROUP
	}
	service, err := sc.hostReactor.GetServiceInfo(util.GetGroupName(param.ServiceName, param.GroupName), strings.Join(param.Clusters, ","))
	if err != nil {
		return nil, err
	}
	return sc.selectInstances(service, param.HealthyOnly)
}

(kratos/contrib/registry/nacos/v2)

// GetService return the service instances in memory according to the service name.
func (r *Registry) GetService(_ context.Context, serviceName string) ([]*registry.ServiceInstance, error) {
	res, err := r.cli.SelectInstances(vo.SelectInstancesParam{
		ServiceName: serviceName,
		HealthyOnly: true,
	})
	if err != nil {
		return nil, err
	}
	items := make([]*registry.ServiceInstance, 0, len(res))
	for _, in := range res {
		kind := r.opts.kind
		if k, ok := in.Metadata["kind"]; ok {
			kind = k
		}
		items = append(items, &registry.ServiceInstance{
			ID:        in.InstanceId,
			Name:      in.ServiceName,
			Version:   in.Metadata["version"],
			Metadata:  in.Metadata,
			Endpoints: []string{fmt.Sprintf("%s://%s:%d", kind, in.Ip, in.Port)},
		})
	}
	return items, nil
}

if the param.GroupName is empty, value is DEFAULT_GROUP.But the GetService() can`t pass the GroupName.My service group name is customized,so no value obtained.

Environment:

  • Kratos version (use kratos -v): v2.1.2
  • Go version (use go version): v1.16.0
  • OS (e.g: cat /etc/os-release): windows
  • Others:
    kratos/contrib/registry/nacos/v2 version is v2.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant