Skip to content

Commit 8959b0c

Browse files
committed
fix: address v6 client review feedback
1 parent 2cdc80b commit 8959b0c

21 files changed

Lines changed: 310 additions & 98 deletions

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ jobs:
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v4
14+
with:
15+
persist-credentials: false
1416
- name: Set up Go
1517
uses: actions/setup-go@v5
1618
with:
1719
go-version-file: go.mod
20+
cache: false
1821
- name: Verify v6 release contract
1922
run: |
2023
test "$(go list -m)" = "github.com/apolloconfig/agollo/v6"

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
* **Module path updated** from `github.com/apolloconfig/agollo/v5` to `github.com/apolloconfig/agollo/v6`:
88

9-
```
10-
go get github.com/apolloconfig/agollo/v6@latest
9+
```sh
10+
# Run after the v6.0.0 release tag is published.
11+
go get github.com/apolloconfig/agollo/v6@v6.0.0
1112
```
1213

1314
* New integrations use the instance-scoped `NewClient` / `ApolloClient` API.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ A Golang client for the configuration center framework [Apollo](https://github.c
2828

2929
# Usage
3030

31-
## Quick Start
31+
Quick Start
32+
-----------
3233

3334
### Import agollo
3435

35-
```
36-
go get github.com/apolloconfig/agollo/v6@latest
36+
```sh
37+
# Run after the v6.0.0 release tag is published.
38+
go get github.com/apolloconfig/agollo/v6@v6.0.0
3739
```
3840

3941
### Initialize agollo

README_CN.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,48 @@ Agollo - Go Client for Apollo
2828

2929
# Usage
3030

31-
## 快速入门
31+
快速入门
32+
--------
3233

3334
### 导入 agollo
3435

35-
```
36-
go get github.com/apolloconfig/agollo/v6@latest
36+
```sh
37+
# 请在 v6.0.0 release tag 发布后执行。
38+
go get github.com/apolloconfig/agollo/v6@v6.0.0
3739
```
3840

3941
### 启动 agollo
4042

4143
新项目使用实例级 `ApolloClient`,避免进程全局状态并显式管理客户端生命周期:
4244

4345
```go
44-
client, err := agollo.NewClient(context.Background(), agollo.ClientOptions{
45-
AppID: "orders",
46-
Cluster: "default",
47-
MetaServer: "http://apollo-meta:8080",
48-
CacheDir: "/var/lib/orders/apollo",
49-
})
50-
if err != nil {
51-
panic(err)
52-
}
53-
defer client.Close()
54-
55-
cfg, err := client.Config(context.Background(), "application")
56-
if err != nil {
57-
panic(err)
46+
package main
47+
48+
import (
49+
"context"
50+
"fmt"
51+
52+
"github.com/apolloconfig/agollo/v6"
53+
)
54+
55+
func main() {
56+
client, err := agollo.NewClient(context.Background(), agollo.ClientOptions{
57+
AppID: "orders",
58+
Cluster: "default",
59+
MetaServer: "http://apollo-meta:8080",
60+
CacheDir: "/var/lib/orders/apollo",
61+
})
62+
if err != nil {
63+
panic(err)
64+
}
65+
defer client.Close()
66+
67+
cfg, err := client.Config(context.Background(), "application")
68+
if err != nil {
69+
panic(err)
70+
}
71+
fmt.Println(cfg.Int("server.port", 8080))
5872
}
59-
port := cfg.Int("server.port", 8080)
6073
```
6174

6275
新版通过 `ConfigForApp` 支持单 Client 多 AppId,通过 `ConfigFile` 读取 YAML、JSON、XML、TXT 等 namespace 原文。需要启动即失败的服务可调用 `Load` 预加载必需 namespace。v5 到 v6 的字段映射、Getter、监听器和扩展点替代方式见[迁移指南](docs/migration-to-apollo-client.md)

docs/agollo-java-client-parity-implementation.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ client, err := agollo.NewClient(ctx, agollo.ClientOptions{
1515
MetaServer: "http://apollo-meta:8080",
1616
CacheDir: "/var/lib/orders/apollo",
1717
})
18-
if err != nil { /* handle error */ }
18+
if err != nil { panic(err) }
1919
defer client.Close()
2020

2121
cfg, err := client.Config(ctx, "application")
22+
if err != nil { panic(err) }
2223
port := cfg.Int("server.port", 8080)
2324

2425
file, err := client.ConfigFile(ctx, "application", agollo.ConfigFileFormatYAML)
26+
if err != nil { panic(err) }
2527
cancel := cfg.Subscribe(onChange, agollo.WithInterestedKeyPrefixes("db."))
2628
defer cancel()
2729
_ = port
@@ -34,7 +36,7 @@ _ = file
3436
- `Config` 的并发安全实时快照、`Lookup`、字符串/int/int64/float/bool/duration/字符串切片/整数切片 Getter、有序 `Keys` 与来源查询。
3537
- `ConfigFile` 的原文、格式、来源、变更订阅;properties、yaml/yml 支持 `AsMap`
3638
- Config Service 直连或 Meta `/services/config` 发现、轮转节点选择、`releaseKey``ip``label``dataCenter``messages` 与按 AppId 的 Access Key 签名。
37-
- `FULL_SYNC``INCREMENTAL_SYNC`增量结果在无全量基线、未知同步类型或非法变更类型时拒绝发布
39+
- `FULL_SYNC``INCREMENTAL_SYNC`无全量基线的增量结果会立即重试全量拉取,未知同步类型或非法变更类型拒绝发布
3840
- 按 AppId 的 `/notifications/v2` 长轮询、Context/`Close` 取消、退避和通知触发刷新。
3941
- 容灾链:Remote → 原子本地 JSON 缓存 → 可选 `ConfigMapStore`;Local Mode 只读取本地缓存。读取兼容旧 agollo JSON 缓存。
4042
- 有界监听队列、溢出合并到最新事件、panic 隔离、精确 key/prefix/正则监听,以及无第三方依赖的 `Monitor` 快照。
@@ -53,7 +55,7 @@ _ = file
5355
| 基础加载和鉴权 | Config URL、ip/DC/label、签名、类型化读取、来源、指标 | `TestApolloClientLoadsConfigAndAppliesProtocolParameters` |
5456
| YAML ConfigFile | `.yaml` namespace、原文、扁平化 Map、原文变更事件 | `TestApolloClientConfigFileYAMLAndRawListener` |
5557
| 多 AppId + 增量 | Secret 隔离、`messages`/`releaseKey` 回传、增加/修改/删除、key 前缀过滤 | `TestApolloClientMultiAppIDAndIncrementalSync` |
56-
| 安全失败 | 无基线的增量同步不能覆盖内存配置 | `TestApolloClientRejectsIncrementalConfigWithoutBaseline` |
58+
| 增量恢复 | 无基线的增量同步立即回退全量拉取 | `TestApolloClientRecoversIncrementalConfigWithoutBaseline` |
5759
| 失败后的恢复 | 首次加载失败后可成功重试;成功后不再返回过期错误 | `TestApolloClientRetriesFailedInitialLoad` |
5860
| 304 通知确认 | 保持内容和事件不变,同时推进 `notificationId` | `TestApolloClientAcknowledges304NotificationWithoutChangeEvent` |
5961
| 刷新故障 | 已有远端快照时拒绝以旧缓存回滚 | `TestApolloClientRefreshFailureKeepsLastKnownGoodSnapshot` |
@@ -77,7 +79,7 @@ go test -race . -run '^TestApolloClient|^TestPublicApolloClientAPI|^TestClientOp
7779
go test ./protocol/http ./storage ./utils ./utils/parse/... -count=1
7880
```
7981

80-
`go vet ./...` 仍会报告旧包中复制 `sync.Map`/`sync.Once` 的告警(`env``storage``component/serverlist`);本次新增文件没有对应告警。它们应在后续 M0/M3 单独清理,不能据此宣称发布门禁已全部达成
82+
`go vet ./...` 已通过;同步映射和零值 `Cache` 的实现避免复制或解引用未初始化的同步原语
8183

8284
## 尚未完成的发布级工作
8385

docs/agollo-refactor-java-client-migration-plan.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ <h2>14. 参考资料</h2>
11081108
</main>
11091109
</div>
11101110

1111-
<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
1111+
<script src="https://cdn.jsdelivr.net/npm/mermaid@11.16.1/dist/mermaid.min.js" integrity="sha384-aBQXj4hK6Jm05i7aQAsUV3bLdSUrHX1BGYfMB0166TtWt/RRaw+h0Eelme9eOCOvy" crossorigin="anonymous"></script>
11121112
<script>
11131113
(() => {
11141114
const article = document.getElementById('document');

docs/migration-to-apollo-client.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import "github.com/apolloconfig/agollo/v6"
1111
```
1212

1313
```sh
14-
go get github.com/apolloconfig/agollo/v6@latest
14+
# Run after the v6.0.0 release tag is published.
15+
go get github.com/apolloconfig/agollo/v6@v6.0.0
1516
```
1617

1718
## 为什么重新设计 API
@@ -181,7 +182,7 @@ cancel := cfg.Subscribe(func(event agollo.ConfigChangeEvent) {
181182
},
182183
agollo.WithInterestedKeys("server.port"),
183184
agollo.WithInterestedKeyPrefixes("db."),
184-
agollo.WithInterestedKeyRegexps(regexp.MustCompile(`^feature\\.`)),
185+
agollo.WithInterestedKeyRegexps(regexp.MustCompile(`^feature\.`)),
185186
)
186187
defer cancel()
187188
```

env/app_config_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package env
1717
import (
1818
"encoding/json"
1919
"os"
20-
"sync"
2120
"testing"
2221
"time"
2322

@@ -154,12 +153,3 @@ func TestLoadEnvConfig(t *testing.T) {
154153

155154
os.Remove(envConfigFile)
156155
}
157-
158-
func getNotifyLen(s *sync.Map) int {
159-
l := 0
160-
s.Range(func(k, v interface{}) bool {
161-
l++
162-
return true
163-
})
164-
return l
165-
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.20
55
require (
66
github.com/spf13/viper v1.8.1
77
github.com/tevid/gohamcrest v1.1.1
8+
gopkg.in/yaml.v2 v2.4.0
89
)
910

1011
require (
@@ -21,5 +22,4 @@ require (
2122
golang.org/x/sys v0.1.0 // indirect
2223
golang.org/x/text v0.3.8 // indirect
2324
gopkg.in/ini.v1 v1.62.0 // indirect
24-
gopkg.in/yaml.v2 v2.4.0 // indirect
2525
)

modern_cache.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func (c *ApolloClient) persistLocalSnapshot(snapshot ConfigSnapshot) error {
9595
}
9696

9797
func (c *ApolloClient) loadLocalSnapshot(ctx context.Context, key ConfigKey) (ConfigSnapshot, error) {
98+
var lastDecodeErr error
9899
for _, file := range []string{c.cacheFile(key), c.legacyCacheFile(key)} {
99100
if err := ctx.Err(); err != nil {
100101
return ConfigSnapshot{}, err
@@ -111,8 +112,13 @@ func (c *ApolloClient) loadLocalSnapshot(ctx context.Context, key ConfigKey) (Co
111112
}
112113
if snapshot, err := decodeDiskSnapshot(key, body); err == nil {
113114
return snapshot, nil
115+
} else {
116+
lastDecodeErr = err
114117
}
115118
}
119+
if lastDecodeErr != nil {
120+
return ConfigSnapshot{}, fmt.Errorf("agollo: no readable local cache for %s: %w", key, lastDecodeErr)
121+
}
116122
return ConfigSnapshot{}, fmt.Errorf("agollo: no readable local cache for %s", key)
117123
}
118124

@@ -121,6 +127,9 @@ func decodeDiskSnapshot(key ConfigKey, body []byte) (ConfigSnapshot, error) {
121127
if err := json.Unmarshal(body, &disk); err != nil {
122128
return ConfigSnapshot{}, err
123129
}
130+
if disk.Version > modernCacheVersion {
131+
return ConfigSnapshot{}, fmt.Errorf("local cache version %d is newer than supported version %d", disk.Version, modernCacheVersion)
132+
}
124133
// agollo legacy cache has the same JSON field names but no version/format.
125134
if disk.AppID != "" && disk.AppID != key.AppID {
126135
return ConfigSnapshot{}, errors.New("local cache AppId does not match requested AppId")

0 commit comments

Comments
 (0)