Skip to content

Commit 8a457d9

Browse files
committed
docs: add dubbo-go agent skills
Signed-off-by: Oxidaner <18622412361@163.com>
1 parent 9af5395 commit 8a457d9

19 files changed

Lines changed: 1072 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
name: dubbo-go-cluster
3+
description: >-
4+
Implements and reviews dubbo-go cluster, routing, directory, and load-balancing changes. Use when the user asks about
5+
failover, failfast, failsafe, failback, forking, broadcast, available, zoneaware, adaptive service, Directory,
6+
RouterChain, condition, tag, script, affinity or Polaris routers, load balance algorithms, retries, provider
7+
selection, or packages cluster/cluster/, cluster/directory/, cluster/router/, and cluster/loadbalance/. Do not use
8+
for registry backend mechanics unless the directory snapshot contract is affected.
9+
---
10+
11+
# dubbo-go Cluster
12+
13+
## Purpose
14+
15+
Use this skill to change or explain how provider invokers are listed, routed, load-balanced, retried, and invoked by cluster fault-tolerance strategies.
16+
17+
## When to use
18+
19+
Use for cluster invokers, directory snapshots, router chain behavior, dynamic routing rules, tag or condition matching, load balancing, retries, and adaptive service behavior.
20+
21+
Do not use for registry backend code unless registry notifications affect directory snapshots.
22+
23+
## Inputs
24+
25+
Required:
26+
- Cluster strategy, router, load balancer, directory, or invocation selection behavior.
27+
- Intended routing/selection behavior or observed mismatch.
28+
29+
Optional:
30+
- Consumer URL, provider URLs, invocation attachments, method name, route rule, or registry event sequence.
31+
32+
If missing, start at `cluster/router/chain/chain.go` for routing or `cluster/cluster/` for fault tolerance.
33+
34+
## Workflow
35+
36+
1. Classify the behavior as directory update, router filtering, load balance selection, or cluster fault tolerance.
37+
2. Read `cluster/directory/` for provider invoker snapshots and registry notification handling.
38+
3. Read `cluster/router/chain/chain.go` and the relevant router package for filtering behavior.
39+
4. Read `cluster/loadbalance/` for provider selection.
40+
5. Read the relevant `cluster/cluster/*/cluster_invoker.go` for retry and error behavior.
41+
6. Check extension registration under `common/extension/cluster.go`, `loadbalance.go`, and `router_factory.go`.
42+
7. Read `references/routing-cluster-flow.md` before changing selection semantics.
43+
44+
## Output format
45+
46+
Return directory source, router chain result, load balance or cluster strategy, changed files, and validation performed.
47+
48+
## Validation
49+
50+
- Confirm router priority and stable ordering still produce deterministic results.
51+
- Confirm directory snapshots are copied safely and not mutated by callers.
52+
- Confirm retry count and business-error handling match the strategy.
53+
- Run focused tests such as `go test ./cluster/...`; use `make test` for broad invocation behavior.
54+
55+
## Edge cases
56+
57+
- RouterChain first narrows invokers by service key and falls back to all invokers if no service-key match exists.
58+
- Static router config is injected after builtin routers are created.
59+
- Failover retries non-business errors but returns business errors directly.
60+
- Method-level URL params can override interface-level routing, retries, and load balance settings.
61+
62+
## References
63+
64+
- Read `references/routing-cluster-flow.md` for directory, router, load balance, and cluster invocation details.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Routing and Cluster Flow
2+
3+
## Invocation Path
4+
5+
1. A proxy or protocol caller invokes a cluster invoker.
6+
2. The cluster invoker asks its directory for invokers matching the invocation.
7+
3. Directory output is routed through `RouterChain`.
8+
4. The cluster strategy chooses or retries invokers using a load balancer.
9+
5. The selected protocol invoker performs the remote call.
10+
11+
## Directory
12+
13+
- Static directory holds fixed invokers.
14+
- Registry directory reacts to registry notifications and rebuilds invoker snapshots.
15+
- Directory output should be treated as a snapshot for one invocation path.
16+
17+
## Router Chain
18+
19+
- `RouterChain.Route` copies invokers, filters by service key when possible, then applies routers in priority order.
20+
- Router factories are registered through `extension.SetRouterFactory`.
21+
- Static router configs are injected through routers implementing `StaticConfigSetter`.
22+
- Dynamic routers may update internal state on `Notify`.
23+
24+
## Load Balance
25+
26+
- Load balance implementations live under `cluster/loadbalance/`.
27+
- Selection receives candidate invokers and the invocation.
28+
- Method-level URL params can affect algorithm choice.
29+
30+
## Cluster Strategies
31+
32+
- `failover`: retry non-business errors and reselect providers.
33+
- `failfast`: fail immediately.
34+
- `failsafe`: swallow failures according to strategy.
35+
- `failback`: retry in background.
36+
- `forking`, `broadcast`, `available`, `zoneaware`, and `adaptivesvc` have specialized selection behavior.
37+
38+
## Contract Checks
39+
40+
- Keep router output deterministic for the same snapshot and invocation.
41+
- Avoid mutating shared invoker slices from callers.
42+
- Preserve distinction between business errors and transport or provider errors.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: dubbo-go-config
3+
description: >-
4+
Implements and reviews dubbo-go configuration changes. Use when the user asks about dubbo.Load, config.Load,
5+
RootConfig, InstanceOptions, global config structs, YAML or JSON loading, koanf parsing, config center integration,
6+
dynamic configuration, hot reload, config post processors, or packages loader.go, config/, global/, config_center/,
7+
and common/config/. Do not use for runtime export/refer behavior unless configuration injection is the contract.
8+
---
9+
10+
# dubbo-go Config
11+
12+
## Purpose
13+
14+
Use this skill to change or explain how dubbo-go loads, initializes, validates, hot-reloads, and exposes configuration to runtime client and server code.
15+
16+
## When to use
17+
18+
Use for configuration files, builder APIs, `RootConfig`, `InstanceOptions`, global config models, config center factories, hot reload allowlists, and config post-processing.
19+
20+
Do not use for protocol transport, registry events, or runtime export/refer behavior unless configuration injection is the contract being changed.
21+
22+
## Inputs
23+
24+
Required:
25+
- Config key, config struct, loader API, or package path.
26+
- Intended behavior or observed parse/init bug.
27+
28+
Optional:
29+
- YAML or JSON snippet.
30+
- Config center protocol and data ID or group.
31+
- Related client, server, reference, or service option.
32+
33+
If missing, inspect `loader.go`, `config/config_loader.go`, and the relevant `global/*_config.go` or `config/*_config.go`.
34+
35+
## Workflow
36+
37+
1. Identify whether the task targets top-level `dubbo.Load` and `InstanceOptions` or legacy `config.Load` and `RootConfig`.
38+
2. Read the owning config model under `global/` and compatibility or builder code under `config/`.
39+
3. Trace initialization into `InstanceOptions.init`, `RootConfig.Init`, service/reference init, or config center startup.
40+
4. For dynamic config, inspect `config/config_center_config.go`, `config_center/`, and `common/extension/config_center_factory.go`.
41+
5. For hot reload, inspect `loader.go` and keep `safeChanged` semantics narrow.
42+
6. Read `references/config-flow.md` before changing loader behavior or public config keys.
43+
44+
## Output format
45+
46+
Return changed config keys or structs, loader path, runtime injection impact, validation performed, and any compatibility notes.
47+
48+
## Validation
49+
50+
- Confirm new config fields are represented in the right `global/` or `config/` model and initialized before runtime use.
51+
- Confirm config center changes register the correct extension factory.
52+
- Confirm hot reload accepts only intended mutable keys.
53+
- Run focused tests such as `go test ./config ./global ./config_center/...`; use `make test` for broad config behavior.
54+
55+
## Edge cases
56+
57+
- `dubbo.Load` starts provider and consumer runtime; `config.Load` only initializes `RootConfig`.
58+
- Some config values are transported as URL params, while TLS, application, registry, shutdown, and Triple details often travel as URL attributes.
59+
- Existing compatibility tests may depend on legacy field names.
60+
61+
## References
62+
63+
- Read `references/config-flow.md` for loader, config center, and runtime injection details.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Config Flow
2+
3+
## Entry Points
4+
5+
- `loader.go`: top-level `dubbo.Load`, file watch, hot reload, and `InstanceOptions`.
6+
- `config/config_loader.go`: package-level `config.Load`, `RootConfig` storage, and legacy config accessors.
7+
- `dubbo.go`: maps `InstanceOptions` into `client.ClientOption` and `server.ServerOption`.
8+
- `global/`: config models used by public client/server options.
9+
- `config/`: builders, compatibility models, config center startup, and legacy `RootConfig` initialization.
10+
11+
## Loader Flow
12+
13+
Top-level `dubbo.Load`:
14+
1. Build `loaderConf`.
15+
2. Resolve config with koanf from file, raw bytes, or direct options.
16+
3. Unmarshal into `InstanceOptions`.
17+
4. Run `InstanceOptions.init`.
18+
5. Create an `Instance` and start consumer/provider loading.
19+
6. Start the file watcher once and register shutdown cleanup.
20+
21+
Package `config.Load`:
22+
1. Build `LoaderConf`.
23+
2. Resolve into `RootConfig` when one is not provided.
24+
3. Run `RootConfig.Init`.
25+
4. Store the initialized root config through the atomic pointer.
26+
27+
## Config Center
28+
29+
- Config center setup is coordinated by `config/config_center_config.go`.
30+
- Implementations live under `config_center/{apollo,file,nacos,zookeeper}`.
31+
- Factories register through `common/extension/config_center_factory.go`.
32+
- Parser behavior is under `config_center/parser/`.
33+
34+
## Runtime Injection
35+
36+
- `Instance.NewClient` clones consumer, application, registry, shutdown, metrics, otel, TLS, protocol, and router config into `client` options.
37+
- `Instance.NewServer` clones application, registry, protocol, shutdown, metrics, otel, and TLS config into `server` options.
38+
- Reference and service options ultimately build `common.URL` values. Use params for transportable Dubbo URL values and attributes for in-process objects.
39+
40+
## Hot Reload
41+
42+
- File watching is in `loader.go`.
43+
- `hotUpdateConfig` compares old and new koanf trees with `safeChanged`.
44+
- Keep hot reload allowlists conservative because changing immutable runtime fields after export or refer can leave stale protocols, registries, or metadata.
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
name: dubbo-go-domain
3+
description: >-
4+
Use this skill when working on the dubbo-go codebase, including implementing features, fixing bugs, writing tests,
5+
reviewing code, updating documentation, or routing work to a narrower dubbo-go-* domain skill. Use for cross-module
6+
questions, end-to-end flows, subsystem boundaries, or deciding whether config, runtime, protocol, registry, metadata,
7+
cluster routing, filters and observability, or tools guidance applies.
8+
---
9+
10+
# dubbo-go Project Guide
11+
12+
## Project Overview
13+
14+
dubbo-go is the Go implementation of Apache Dubbo. It is an RPC and microservice framework that provides service export and reference, registry and service discovery, protocol interoperability, cluster fault tolerance, traffic governance, configuration, metadata, metrics, tracing, and developer tools.
15+
16+
It mainly provides:
17+
- Public client and server APIs for Go services.
18+
- Dubbo, Dubbo3, Triple, gRPC, REST, JSONRPC, and related transport support.
19+
- Registry integration with Nacos, Zookeeper, Etcd, Polaris, and application-level service discovery.
20+
- Metadata collection, metadata reporting, service name mapping, routing, load balancing, filters, metrics, tracing, and CLI or code generation tools.
21+
22+
This repository does not own external registry servers, Dubbo Java implementation, sample applications outside this repository, or production deployment infrastructure.
23+
24+
## Tech Stack
25+
26+
- Language: Go, module `dubbo.apache.org/dubbo-go/v3`.
27+
- Go version: `go 1.25.0` in `go.mod`; root `Makefile` uses `GOTOOLCHAIN=go1.25.0+auto` for tests.
28+
- Build: Go modules plus nested Go modules under selected `tools/` directories.
29+
- Test: `go test`, `testify`, `gomock`, and focused package tests.
30+
- Lint and format: `go fmt`, `imports-formatter`, `go vet`, `golangci-lint`, and `make fmt` or `make lint`.
31+
32+
Do not introduce a new framework or dependency unless the task requires it and the compatibility impact is clear.
33+
34+
## Repository Structure
35+
36+
- `dubbo.go`, `loader.go`: public instance and top-level load/start APIs.
37+
- `config/`, `global/`, `config_center/`, `common/config/`: config models, loading, config center, and compatibility behavior.
38+
- `client/`, `server/`, `proxy/`, `graceful_shutdown/`: runtime client/server construction, refer/export, proxy, and shutdown behavior.
39+
- `protocol/`, `remoting/`, `common/url.go`: protocol interfaces, codecs, transports, URL contract, invokers, and exporters.
40+
- `registry/`, `metadata/`: registry discovery, service discovery, metadata, reports, mapping, and revisions.
41+
- `cluster/`: directories, routers, load balancing, and cluster fault tolerance.
42+
- `filter/`, `metrics/`, `otel/`, `logger/`: filters, observability, tracing, metrics, and logging.
43+
- `tools/`: CLI, schema generator, protoc plugins, import formatter, and RPC contract scanner.
44+
- `docs/`, `doc/`: project documentation and images.
45+
46+
## Workflow
47+
48+
When modifying code:
49+
50+
1. Classify the owning subsystem and load the narrower `dubbo-go-*` skill when relevant.
51+
2. Read the existing implementation and tests before editing.
52+
3. Make the smallest correct change that follows current package boundaries.
53+
4. Prefer existing abstractions, extension registries, URL params, and URL attributes over new patterns.
54+
5. Add or update focused tests for behavior changes.
55+
6. Run the most relevant validation command.
56+
7. Summarize changed files, behavior, compatibility impact, and validation result.
57+
58+
When fixing bugs:
59+
60+
1. Reproduce the issue or identify the failing path from tests, logs, or code.
61+
2. Find the smallest root cause.
62+
3. Make a minimal safe change.
63+
4. Add a regression test when feasible.
64+
5. Explain why the fix works and what risk remains.
65+
66+
When reviewing code:
67+
68+
1. Check behavior, compatibility, concurrency, error handling, generated file handling, and missing tests first.
69+
2. Ground findings in file and line references.
70+
3. Keep summary secondary to concrete risks.
71+
72+
## Coding Guidelines
73+
74+
- Keep changes focused and reviewable.
75+
- Follow existing package structure, naming, and extension registration patterns.
76+
- Preserve backward compatibility for public APIs, config keys, URL params, wire behavior, and generated output unless explicitly requested.
77+
- Use structured config, URL, and parser APIs instead of ad hoc string handling when available.
78+
- Avoid broad refactors during bug fixes.
79+
- Do not change unrelated files.
80+
81+
## Testing and Validation
82+
83+
Use the most relevant command:
84+
85+
```bash
86+
go test ./...
87+
make test
88+
make fmt
89+
make lint
90+
make rpc-contract-check
91+
```
92+
93+
For focused work, prefer package-level tests first, for example:
94+
95+
```bash
96+
go test ./config ./global ./config_center/...
97+
go test ./client ./server ./proxy ./graceful_shutdown
98+
go test ./protocol/... ./remoting/...
99+
go test ./registry/... ./metadata/...
100+
go test ./cluster/...
101+
go test ./filter/... ./metrics/... ./otel/...
102+
```
103+
104+
For nested tools, run tests from the owning module directory.
105+
106+
If validation cannot be run or fails, report the command, the error, and whether it appears related to the current change.
107+
108+
## Do Not
109+
110+
- Do not rewrite large parts of the project without explicit instruction.
111+
- Do not introduce new dependencies or frameworks unless necessary.
112+
- Do not change public APIs, config keys, wire contracts, or generated output without documenting compatibility impact.
113+
- Do not remove or weaken tests to make validation pass.
114+
- Do not commit secrets, tokens, passwords, private keys, or private config.
115+
- Do not modify generated files manually unless the generation source is also updated or the repository already treats that file as hand-maintained.
116+
- Do not ignore existing uncommitted user changes.
117+
118+
## Common Tasks
119+
120+
### Choose a Domain Skill
121+
122+
1. Map the request to the primary package.
123+
2. Use `references/architecture-map.md` when ownership is unclear.
124+
3. Load one narrower skill when possible.
125+
4. If multiple domains are involved, follow runtime flow: config, runtime, protocol, registry or metadata, cluster, filters, observability, tools.
126+
127+
### Add a Feature
128+
129+
1. Find the owning module and existing tests.
130+
2. Add the core behavior using existing abstractions.
131+
3. Add or update tests.
132+
4. Update documentation when public behavior changes.
133+
5. Run focused validation.
134+
135+
### Add a Configuration Option
136+
137+
1. Define the config key in the owning config model.
138+
2. Add default and initialization behavior.
139+
3. Wire it into the consuming module through existing options or URL params/attributes.
140+
4. Add tests for default and custom behavior.
141+
5. Update docs or schemas when relevant.
142+
143+
### Fix a Bug
144+
145+
1. Identify the root cause.
146+
2. Make the minimal fix.
147+
3. Add a regression test when possible.
148+
4. Verify with the narrowest relevant command.
149+
150+
## Output Format
151+
152+
Return the selected skill or subsystem, changed files, behavior change, compatibility impact, validation performed, and any residual risk.
153+
154+
## Edge cases
155+
156+
- `dubbo.Load` and `config.Load` both load configuration, but they serve different public APIs.
157+
- Registry discovery and metadata reporting are tightly coupled; use `dubbo-go-metadata` when revisions or metadata reports control behavior.
158+
- Filters wrap protocols through `protocol/protocolwrapper`; use `dubbo-go-protocol` when transport semantics change and `dubbo-go-observability-filters` when interception semantics change.
159+
- Some `tools/` subdirectories are independent Go modules.
160+
161+
## References
162+
163+
- Read `references/architecture-map.md` for subsystem ownership and end-to-end flow.
164+
- Read `references/project-rules.md` for compatibility, generated-file, validation, and PR guidance.

0 commit comments

Comments
 (0)