Kitex + Etcd 的一点点小坑 | 青训营笔记

468 阅读1分钟

这是我参与「第五届青训营 」伴学笔记创作活动的第 5 天

github.com/kitex-contrib/registry-etcd v0.1.0 发布了,已经 fix 了引用的 etcd 3.5.5

什么“坑”

导入 github.com/kitex-contrib/registry-etcd 包后,使用 go mod tidy 自动处理依赖会出现:

module go.opentelemetry.io/otel@latest found (v1.11.2), but does not contain package go.opentelemetry.io/otel/semconv

以及

module go.opentelemetry.io/otel/metric@latest found (v0.34.0), but does not contain package go.opentelemetry.io/otel/metric/number

先上解决办法

修改 go.mod 文件,添加

replace go.etcd.io/etcd/server/v3 => go.etcd.io/etcd/server/v3 v3.5.7

3.5.5 及以上就行了,如果有更好的解决办法可以给我留言教我一下😭

遇到问题,直接开始 Google

其实是一开始普自信的自己改,没改好

通过不断查找,通过关键字 go.etcd.io/etcd/server/v3/embed imports go.opentelemetry.io/otel/semconv 找到了这个 Issues:

ETCD integration package is broken if any other module in the project uses updated opentelemetry · Issue #14268 · etcd-io/etcd (github.com)

通过翻看内容,看到了这样一句话:评论链接

image.png

也就是说当使用的 etcd 版本是 3.5.5 及以上版本就好了,但是这里先查看一下 registry-etcd 引用的 etcd 版本

打开 github.com/kitex-contrib/registry-etcd@v0.0.0-20221223084757-0d49e7162359/go.mod 文件,可以看到使用的 etcd 版本为 v3.5.1

总结

这里可以看到 go mod 在解决一些版本变更造成的问题时,对于新手还是不那么友好,中间尝试过使用查看依赖关系来找问题,但是很不幸,不会用,go mod 的 graph 不能很好的像 java maven 一样用树状的结构输出依赖的关系结构,在解决依赖冲突不知道从哪下手

二零二二年的最后一天,虽然不幸的在最后一天遇到了一个小问题,但还好解决了,不然留到明年怕是睡不好觉了🐶,各位看到这篇文章应该已经是新年了,各位新年快乐!!!