apolloconfig / agollo Goto Github PK
View Code? Open in Web Editor NEW🚀Go client for ctrip/apollo (https://github.com/apolloconfig/apollo)
Home Page: https://www.apolloconfig.com
License: Apache License 2.0
🚀Go client for ctrip/apollo (https://github.com/apolloconfig/apollo)
Home Page: https://www.apolloconfig.com
License: Apache License 2.0
客户端容灾
缓存配置结果到本地文件
我定义了一个namespace的配置方式为json,这个有方法可以用吗
需要两个:初始拉取json配置,json配置更新,自动更新
请简单描述bug的场景
go mod 引用时,版本号与module的path不匹配,导致无法引用v2.x.x的任何版本。
参考:https://github.com/golang/go/wiki/Modules#semantic-import-versioning,
我试了一下事件监听可以用,但是有点问题
我一共有2个key,key1和key2,然后我通过管理平台删除了key1,结果收到通知后,只有key2的update事件,key1直接就没有了,而不是key1的delete事件
我一共2个key,只修改了其中一个key的值,但是两个我都收到了update事件,其中一个的结果old和new是同一个值(这个是个小问题,最好能够优化一下,这样会比较方便,不过如果太复杂的话,自己比较两个值也是可以的)
func (this *NotifyConfigComponent) Start() {
t2 := time.NewTimer(long_poll_interval)
//long poll for sync
for {
select {
case <-t2.C:
notifySyncConfigServices()
t2.Reset(long_poll_interval)
}
}
}
notifySyncConfigServices() 中进行请求时,http请求是阻塞住,下在那个timer应该去掉
我想使用yml文件作为配置 ,apollo中也添加好了,但是agollo好像是不支持是么?
指定配置文件去启动Apollo 是得自己重新定义一下,还是说有提供了 类似的方法吗@zouyx
Dependabot encountered the following error when parsing your .dependabot/config.yml
:
Top level entity must be an Object, not a NilClass
Please update the config file to conform with Dependabot's specification using our docs and online validator.
func updateApolloConfigCache(configurations map[string]string,expireTime int) {
if configurations==nil||len(configurations)==0{
return
}
apolloConfigCache.Clear()
for key,value:=range configurations{
apolloConfigCache.Set([]byte(key),[]byte(value),expireTime)
}
}
数据更新,先清除apolloConfigCache.Clear(), 再全量写入,写入过程中如果有访问,出现部分key访问不到, 可改成增量更新
func updateApolloConfigCache(configurations map[string]string, expireTime int) {
if configurations == nil || len(configurations) == 0 {
return
}
updateCacheLock.Lock()
defer updateCacheLock.Unlock()
// get old keys 保存老的key
mp := map[string]bool{}
it := apolloConfigCache.NewIterator()
for en := it.Next(); en != nil; en = it.Next() {
mp[string(en.Key)] = true
}
// update new keys 全量更新数据
for key, value := range configurations {
apolloConfigCache.Set([]byte(key), []byte(value), expireTime)
delete(mp, string(key)) // 删已有的key, mp剩下是就要删除的
}
// remove del keys 删除新配置中没有的项
for key := range mp {
apolloConfigCache.Del([]byte(key))
}
}
为了防止两次更新同时进行,数据出现问题,在一次数据更新过程中加个锁,保证同时只进行一次数据更新
updateCacheLock.Lock()
defer updateCacheLock.Unlock()
作者你好, 我使用下列方式 取得更換事件
event := agollo.ListenChangeEvent()
changeEvent := <-event
有時後我更該一個存在的key時, ChangeType有時取得1, 有時取得0
似乎長時間不操作後, 就會取得0
之後短時間內有一更新value, 就會取得1
請問如果要取得即時數據建議怎麼使用呢?
透過下面程式, 2分鐘後就會取不到資料
原因是因為GetStringValue是從cache拿資料
但是cahce只保存120s, 所以之後都是拿預設值
所以是否有建議的使用方法呢
agollo.Start()
for {
n := agollo.GetStringValue("name", "default_name")
fmt.Println(n)
time.Sleep(5 * time.Second)
}
Describe the bug
您好,按照 Apollo 指导添加了新的环境:
代码中 apollo 结构体如下,没有指定环境参数:
type AppConfig struct {
AppId string `json:"appId"`
Cluster string `json:"cluster"`
NamespaceName string `json:"namespaceName"`
Ip string `json:"ip"`
NextTryConnTime int64 `json:"-"`
}
想问下您,是不是默认读取的是 DEV 环境,如果添加了新的自定义环境,应该怎么读取。
Expected behavior
能够读取自定义环境的参数信息。
背景
在应用代码中重新设置 AppConfig
,修改 namespace 后再进行 Start
提示
2019/04/08 21:34:41 26666 1554730481482213000 [Debug] get all server info:[{"appName":"APOLLO-CONFIGSERVICE","instanceId":"192.168.0.105:apollo-configservice:8080","homepageUrl":"http://192.168.0.105:8080/"}]
问题
等待 60s 后程序才会继续运行下去
期待
快速响应,而不是每次切换不存在的 namespace 都等待那么久
对齐java
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
在某些情况下,部分key仅仅知道结果是不够的,可能还需要针对不同的事件做一些初始化操作,比如新增/更新key,或者删除某个key
看了下java的客户端是有这个功能的,能否在go里也增加同样的功能
https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97#312-%E7%9B%91%E5%90%AC%E9%85%8D%E7%BD%AE%E5%8F%98%E5%8C%96%E4%BA%8B%E4%BB%B6
根据不一样的环境变量读取不一样环境ip
https://github.com/zouyx/agollo/blob/master/repository.go#L42-L44 execute:
currentConnApolloConfig=&apolloConfig.ApolloConnConfig
but lock in
type ApolloConnConfig struct {
AppId string `json:"appId"`
Cluster string `json:"cluster"`
NamespaceName string `json:"namespaceName"`
ReleaseKey string `json:"releaseKey"`
sync.RWMutex
}
will not protect currentConnApolloConfig
itself, only properties in currentConnApolloConfig
will be protect.
如题~
Is your feature request related to a problem? Please describe.
暂无
Describe the solution you'd like
运行时动态获取新namespace,并刷新到更新列表中
Describe alternatives you've considered
暂无
Additional context
暂无
Is your feature request related to a problem? Please describe.
类似java的做法:
Config.addChangeListener(apolloListener, Collections.singleton(key));
简化用户的使用心智
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
建议使用go fmt格式化代码
现在的风格像c/c++工程
Is your feature request related to a problem? Please describe.
java 支 持只提供 namespace 创建 Config 对象 的方式
ConfigService.getConfig(url.getParameter(Constants.CONFIG_NAMESPACE_KEY, DEFAULT_GROUP));
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
看源码好像,目前好像只能订阅一个namespace.
这个不能支持指定配置文件吗?方便线上和线下环境切换
如题
现在的两个配置文件是必须的,连接apollo的配置,是否可以不采用配置文件的方式,直接通过代码传一个ApolloConfig
的结构体?
agollo.InitCustomConfig(func () (*agollo.AppConfig, error) {
return &agollo.AppConfig{
AppId: "123",
Cluster: "456",
Ip: "ip",
NamespaceName: "application",
}, nil
)
agollo.Start()
请简单描述bug的场景
我故意将配置中心地址配错,验证容灾能力,结果再存在本地配置文件的情况下报如下错误:
[loadConfigFile fail,error: [open : no such file or directory]]
如何重现
很简单,将配置中心地址填错就行,然后调用 demo 的接口:curl localhost:9000/check,返回的内容是空的
*bug 位置
file.go 的 getConfigFile 函数,fullPath 为空时,内部应该返回 filePath
如题,项目需求,需要在APP启动的时候获取到全部的配置项和值,进行定制操作,但是用GetStringValue()只能获取到指定key项的value,在不知道所有key的情况下有方法能一次拿到吗?
另外,同样也遇到了这个bug:https://github.com/zouyx/agollo/issues/23 ,希望能尽快解决,感谢!
在request.go中周期的性的发生连接Apollo config service的配置更新通知超时失败,大概每隔几分钟就发生一次,并超过最大重试次数后停止发生请求。比如
[ERROR] [19:49:07] [requestRecovery @ request.go.97] Connect Apollo Server Fail,Error:Get http://xxx.xxx.xxx.xxx:8080/notifications/v2?appId=xxx-xxx-xxx&cluster=default¬ifications=%5B%7B%22namespaceName%22%3A%22application%22%2C%22notificationId%22%3A448%7D%5D: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
[ERROR] [19:49:07] [requestRecovery @ request.go.97] Over Max Retry Still Error,Error:Get http://xxx.xxx.xxx.xxx:8080/notifications/v2?appId=xxx-xxx-xxx&cluster=default¬ifications=%5B%7B%22namespaceName%22%3A
接入go-cached管理缓存
客户端支持服务端域名容灾
我配置的 namespaceName 不是application,但是刷新的时候取得是默认的application的配置,导致指针错误,希望修复这个bug,可以获取我配置的那个,具体错误位置:zouyx/agollo/repository.go:253
Is your feature request related to a problem? Please describe.
目前 appConfig 很多地方是全局唯一的, 支持下 多个 appConfig.
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
心跳检测时报错:
[ERROR] [02:56:57] [requestRecovery @ request.go.104] Connect Apollo Server Fail,Error:
[ERROR] [02:56:57] [requestRecovery @ request.go.104] Connect Apollo Server Fail,StatusCode:504
是不是apollo.start()的时候,和后面心跳检测的时候,连接方式不一样?
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
希望能支持一下多环境配置,目前只看到有支持多集群。
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
定时刷新列表存在map并发读写,可能导致panic
代码
// 这是写map的函数
func syncServerIpListSuccessCallBack(responseBody []byte) (o interface{}, err error) {
logger.Debug("get all server info:", string(responseBody))
tmpServerInfo := make([]*serverInfo, 0)
err = json.Unmarshal(responseBody, &tmpServerInfo)
if err != nil {
logger.Error("Unmarshal json Fail,Error:", err)
return
}
if len(tmpServerInfo) == 0 {
logger.Info("get no real server!")
return
}
for _, server := range tmpServerInfo {
if server == nil {
continue
}
servers[server.HomepageUrl] = server
}
return
}
// 这是读map的函数
func (this *AppConfig) selectHost() string {
if !this.isConnectDirectly() {
return this.getHost()
}
for host, server := range servers {
// if some node has down then select next node
if server.IsDown {
continue
}
return host
}
return ""
}
``
建议
使用sync.Map
Describe the bug
我设置的value大约270kb,超过了freecache包50mb/1024的大小,从repository.go的第90行apolloConfigCache.Set([]byte(key), []byte(value), expireTime)
可以看出,没有对返回的err进行处理,实际上在set过程中就提示value过大。后期get的时候就提示Entry not found。
To Reproduce
Steps to reproduce the behavior:
ERROR apollo: get config value fail!err:Entry not found
提个建议,如果某个字段不存在,可以把不存在的字段 key name 抛出来。
因为某些原因,会有一些字段特定情况下不会配置,然后出来好几个红色的获取字段失败,但失败的又不知道是哪些,就会比较尴尬。
在app_config.go中,##syncServerIpListSuccessCallBack的参数responseBody,使用string(responseBody)打印出来是标准的html,即apollo的登录页面。
请问如何反序列化为serverInfo?
功能适用的场景?
该功能适用于配置代理场景,代理监听多个服务的配置,可以同步多个服务的配置文件
根据官方文档 /notifications/v2接口会hold至少30S,官方建议timeout时间至少30S,最好是60S以上,目前默认值是1S,项目启动后会报超时错误
目前的connect_timeout和其他请求是共用的,可以考虑分两个超时时间。
如有使用的朋友可以在这里留言。谢谢大家支持
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.