go-kratos/kratos · error

Discovery.GetService(%s) not found

Error message

Discovery.GetService(%s) not found

What it means

Discovery.GetService fetched instances from the Discovery server, but filterInstancesByZone kept none: every instance's zone metadata differs from the client's configured Zone. The service resolves globally but appears empty through this client's zone-affinity view.

Source

Thrown at contrib/registry/discovery/impl_discover.go:39

		if v == nil {
			continue
		}
		out = append(out, toServiceInstance(v))
	}

	return out
}

func (d *Discovery) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) {
	r := d.resolveBuild(serviceName)
	ins, ok := r.fetch(ctx)
	if !ok {
		return nil, errors.New("Discovery.GetService fetch failed")
	}

	out := filterInstancesByZone(ins, d.config.Zone)
	if len(out) == 0 {
		return nil, fmt.Errorf("Discovery.GetService(%s) not found", serviceName)
	}

	return out, nil
}

func (d *Discovery) Watch(ctx context.Context, serviceName string) (registry.Watcher, error) {
	return &watcher{
		resolve:     d.resolveBuild(serviceName),
		serviceName: serviceName,
		cancelCtx:   ctx,
	}, nil
}

type watcher struct {
	resolve *Resolve

	cancelCtx   context.Context
	serviceName string

View on GitHub (pinned to 668db92c2c)

Solutions

  1. Set the client Zone to exactly the zone providers register in their metadata
  2. Ensure providers publish zone metadata when registering with Discovery
  3. Align zone strings (case/format) across services; treat the zone name as a contract

Example fix

// before - client Zone does not match instance metadata
cfg := &discovery.Config{Nodes: nodes, Region: "sh", Zone: "sh001", Env: "dev"}

// after - align with the zone providers register
cfg := &discovery.Config{Nodes: nodes, Region: "sh", Zone: "sh002", Env: "dev"}
Defensive patterns

Strategy: validation

Validate before calling

if cfg.Region == "" || cfg.Zone == "" || cfg.Env == "" {
    return errors.New("region/zone/env must match provider registration exactly")
}

Prevention

When it happens

Trigger: GetService: resolveBuild(...).fetch(ctx) succeeds, but filterInstancesByZone(ins, d.config.Zone) returns an empty slice because no instance's zone metadata matches the configured Zone.

Common situations: Multi-zone rollouts where client zone config lags; providers registering without zone metadata; zone naming inconsistencies (case or code differences) between sides.

Related errors


AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16). Data as JSON: /api/errors/d5cd1199dd21e523. Report an issue: GitHub.