Merge pull request #660 from xpunch/serviceNotFoundIssue

Service not found issue
This commit is contained in:
Asim Aslam 2019-08-11 12:44:27 +01:00 committed by GitHub
commit 3a5428fb36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 31 deletions

View File

@ -73,10 +73,11 @@ func (g *grpcClient) next(request client.Request, opts client.CallOptions) (sele
// get next nodes from the selector // get next nodes from the selector
next, err := g.opts.Selector.Select(service, opts.SelectOptions...) next, err := g.opts.Selector.Select(service, opts.SelectOptions...)
if err != nil && err == selector.ErrNotFound { if err != nil {
return nil, errors.NotFound("go.micro.client", "service %s not found: %v", service, err.Error()) if err == selector.ErrNotFound {
} else if err != nil { return nil, errors.InternalServerError("go.micro.client", "service %s: %s", service, err.Error())
return nil, errors.InternalServerError("go.micro.client", err.Error()) }
return nil, errors.InternalServerError("go.micro.client", "error selecting %s node: %s", service, err.Error())
} }
return next, nil return next, nil
@ -350,15 +351,17 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface
// select next node // select next node
node, err := next() node, err := next()
if err != nil && err == selector.ErrNotFound { service := req.Service()
return errors.NotFound("go.micro.client", "service %s not found: %v", req.Service(), err.Error()) if err != nil {
} else if err != nil { if err == selector.ErrNotFound {
return errors.InternalServerError("go.micro.client", err.Error()) return errors.InternalServerError("go.micro.client", "service %s: %s", service, err.Error())
}
return errors.InternalServerError("go.micro.client", "error selecting %s node: %s", service, err.Error())
} }
// make the call // make the call
err = gcall(ctx, node, req, rsp, callOpts) err = gcall(ctx, node, req, rsp, callOpts)
g.opts.Selector.Mark(req.Service(), node, err) g.opts.Selector.Mark(service, node, err)
return err return err
} }
@ -429,14 +432,16 @@ func (g *grpcClient) Stream(ctx context.Context, req client.Request, opts ...cli
} }
node, err := next() node, err := next()
if err != nil && err == selector.ErrNotFound { service := req.Service()
return nil, errors.NotFound("go.micro.client", "service %s not found: %v", req.Service(), err.Error()) if err != nil {
} else if err != nil { if err == selector.ErrNotFound {
return nil, errors.InternalServerError("go.micro.client", err.Error()) return nil, errors.InternalServerError("go.micro.client", "service %s: %s", service, err.Error())
}
return nil, errors.InternalServerError("go.micro.client", "error selecting %s node: %s", service, err.Error())
} }
stream, err := g.stream(ctx, node, req, callOpts) stream, err := g.stream(ctx, node, req, callOpts)
g.opts.Selector.Mark(req.Service(), node, err) g.opts.Selector.Mark(service, node, err)
return stream, err return stream, err
} }

View File

@ -312,10 +312,11 @@ func (r *rpcClient) next(request Request, opts CallOptions) (selector.Next, erro
// get next nodes from the selector // get next nodes from the selector
next, err := r.opts.Selector.Select(service, opts.SelectOptions...) next, err := r.opts.Selector.Select(service, opts.SelectOptions...)
if err != nil && err == selector.ErrNotFound { if err != nil {
return nil, errors.NotFound("go.micro.client", "service %s: %v", service, err.Error()) if err == selector.ErrNotFound {
} else if err != nil { return nil, errors.InternalServerError("go.micro.client", "service %s: %s", service, err.Error())
return nil, errors.InternalServerError("go.micro.client", "error selecting %s node: %v", service, err.Error()) }
return nil, errors.InternalServerError("go.micro.client", "error selecting %s node: %s", service, err.Error())
} }
return next, nil return next, nil
@ -375,15 +376,17 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
// select next node // select next node
node, err := next() node, err := next()
if err != nil && err == selector.ErrNotFound { service := request.Service()
return errors.NotFound("go.micro.client", "service %s: %v", request.Service(), err.Error()) if err != nil {
} else if err != nil { if err == selector.ErrNotFound {
return errors.InternalServerError("go.micro.client", "error getting next %s node: %v", request.Service(), err.Error()) return errors.InternalServerError("go.micro.client", "service %s: %s", service, err.Error())
}
return errors.InternalServerError("go.micro.client", "error getting next %s node: %s", service, err.Error())
} }
// make the call // make the call
err = rcall(ctx, node, request, response, callOpts) err = rcall(ctx, node, request, response, callOpts)
r.opts.Selector.Mark(request.Service(), node, err) r.opts.Selector.Mark(service, node, err)
return err return err
} }
@ -452,14 +455,16 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt
} }
node, err := next() node, err := next()
if err != nil && err == selector.ErrNotFound { service := request.Service()
return nil, errors.NotFound("go.micro.client", "service %s: %v", request.Service(), err.Error()) if err != nil {
} else if err != nil { if err == selector.ErrNotFound {
return nil, errors.InternalServerError("go.micro.client", "error getting next %s node: %v", request.Service(), err.Error()) return nil, errors.InternalServerError("go.micro.client", "service %s: %s", service, err.Error())
}
return nil, errors.InternalServerError("go.micro.client", "error getting next %s node: %s", service, err.Error())
} }
stream, err := r.stream(ctx, node, request, callOpts) stream, err := r.stream(ctx, node, request, callOpts)
r.opts.Selector.Mark(request.Service(), node, err) r.opts.Selector.Mark(service, node, err)
return stream, err return stream, err
} }

View File

@ -51,6 +51,9 @@ func (c *registrySelector) Select(service string, opts ...SelectOption) (Next, e
// if that fails go directly to the registry // if that fails go directly to the registry
services, err := c.rc.GetService(service) services, err := c.rc.GetService(service)
if err != nil { if err != nil {
if err == registry.ErrNotFound {
return nil, ErrNotFound
}
return nil, err return nil, err
} }

View File

@ -29,7 +29,7 @@ var (
DefaultRegistry = NewRegistry() DefaultRegistry = NewRegistry()
// Not found error when GetService is called // Not found error when GetService is called
ErrNotFound = errors.New("not found") ErrNotFound = errors.New("service not found")
// Watcher stopped error when watcher is stopped // Watcher stopped error when watcher is stopped
ErrWatcherStopped = errors.New("watcher stopped") ErrWatcherStopped = errors.New("watcher stopped")
) )

View File

@ -271,12 +271,12 @@ func (g *grpcServer) handler(srv interface{}, stream grpc.ServerStream) error {
g.rpc.mu.Unlock() g.rpc.mu.Unlock()
if service == nil { if service == nil {
return status.New(codes.Unimplemented, fmt.Sprintf("unknown service %v", service)).Err() return status.New(codes.Unimplemented, fmt.Sprintf("unknown service %s", serviceName)).Err()
} }
mtype := service.method[methodName] mtype := service.method[methodName]
if mtype == nil { if mtype == nil {
return status.New(codes.Unimplemented, fmt.Sprintf("unknown service %v", service)).Err() return status.New(codes.Unimplemented, fmt.Sprintf("unknown service %s.%s", serviceName, methodName)).Err()
} }
// process unary // process unary