{"record":{"id":"d5cd1199dd21e523","repo":"go-kratos/kratos","slug":"discovery-getservice-s-not-found","errorCode":null,"errorMessage":"Discovery.GetService(%s) not found","messagePattern":"Discovery\\.GetService\\((.+?)\\) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"contrib/registry/discovery/impl_discover.go","lineNumber":39,"sourceCode":"\t\tif v == nil {\n\t\t\tcontinue\n\t\t}\n\t\tout = append(out, toServiceInstance(v))\n\t}\n\n\treturn out\n}\n\nfunc (d *Discovery) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) {\n\tr := d.resolveBuild(serviceName)\n\tins, ok := r.fetch(ctx)\n\tif !ok {\n\t\treturn nil, errors.New(\"Discovery.GetService fetch failed\")\n\t}\n\n\tout := filterInstancesByZone(ins, d.config.Zone)\n\tif len(out) == 0 {\n\t\treturn nil, fmt.Errorf(\"Discovery.GetService(%s) not found\", serviceName)\n\t}\n\n\treturn out, nil\n}\n\nfunc (d *Discovery) Watch(ctx context.Context, serviceName string) (registry.Watcher, error) {\n\treturn &watcher{\n\t\tresolve:     d.resolveBuild(serviceName),\n\t\tserviceName: serviceName,\n\t\tcancelCtx:   ctx,\n\t}, nil\n}\n\ntype watcher struct {\n\tresolve *Resolve\n\n\tcancelCtx   context.Context\n\tserviceName string","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/contrib/registry/discovery/impl_discover.go#L21-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"Multi-zone rollouts where client zone config lags; providers registering without zone metadata; zone naming inconsistencies (case or code differences) between sides.","solutions":["Set the client Zone to exactly the zone providers register in their metadata","Ensure providers publish zone metadata when registering with Discovery","Align zone strings (case/format) across services; treat the zone name as a contract"],"exampleFix":"// before - client Zone does not match instance metadata\ncfg := &discovery.Config{Nodes: nodes, Region: \"sh\", Zone: \"sh001\", Env: \"dev\"}\n\n// after - align with the zone providers register\ncfg := &discovery.Config{Nodes: nodes, Region: \"sh\", Zone: \"sh002\", Env: \"dev\"}","handlingStrategy":"validation","validationCode":"if cfg.Region == \"\" || cfg.Zone == \"\" || cfg.Env == \"\" {\n    return errors.New(\"region/zone/env must match provider registration exactly\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use identical zone naming across services (case-sensitive)","Register zone metadata on every provider","Monitor per-zone instance counts and alert near zero"],"tags":["discovery","bilibili","zone","service-discovery","config"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}