Giter VIP home page Giter VIP logo

agollo's Introduction

Agollo - Go Client for Apollo

golang Build Status Go Report Card codebeat badge Coverage Status License GoDoc GitHub release 996.icu

方便Golang接入配置中心框架 Apollo 所开发的Golang版本客户端。

Features

  • 支持多 IP、AppID、namespace
  • 实时同步配置
  • 灰度配置
  • 延迟加载(运行时)namespace
  • 客户端,配置文件容灾
  • 自定义日志,缓存组件
  • 支持配置访问秘钥

Usage

快速入门

导入 agollo

go get -u github.com/apolloconfig/agollo/v4@latest

启动 agollo

package main

import (
	"fmt"
	"github.com/apolloconfig/agollo/v4"
	"github.com/apolloconfig/agollo/v4/env/config"
)

func main() {
	c := &config.AppConfig{
		AppID:          "testApplication_yang",
		Cluster:        "dev",
		IP:             "http://106.54.227.205:8080",
		NamespaceName:  "dubbo",
		IsBackupConfig: true,
		Secret:         "6ce3ff7e96a24335a9634fe9abca6d51",
	}

	client, _ := agollo.StartWithConfig(func() (*config.AppConfig, error) {
		return c, nil
	})
	fmt.Println("初始化Apollo配置成功")

	//Use your apollo key to test
	cache := client.GetConfigCache(c.NamespaceName)
	value, _ := cache.Get("key")
	fmt.Println(value)
}

更多用法

使用Demoagollo_demo

其他语言agollo-agent 做本地agent接入,如:PHP

欢迎查阅 Wiki 或者 godoc 获取更多有用的信息

如果你觉得该工具还不错或者有问题,一定要让我知道,可以发邮件或者留言

User

Contribution

License

The project is licensed under the Apache 2 license.

Reference

Apollo : https://github.com/ctripcorp/apollo

agollo's People

Contributors

anilople avatar bugmind avatar casper-mars avatar cloverstd avatar codfrm avatar daemon365 avatar dependabot-preview[bot] avatar dependabot[bot] avatar dougsong avatar fengqi avatar hxzqlh avatar ichiro999 avatar jiajunhuang avatar lj99boy avatar mergify[bot] avatar nanashake avatar onanying avatar piglig avatar qdsordinarydream avatar saltbo avatar siwenzhe avatar why444216978 avatar withlin avatar wubin1989 avatar yellowmarlboro avatar yldian avatar zanderme avatar zenghur avatar zouyx avatar zxdstyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

agollo's Issues

[FEATURE] 支持多个 appConfig

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.

[配置中心连不上时,不能容灾]

请简单描述bug的场景
我故意将配置中心地址配错,验证容灾能力,结果再存在本地配置文件的情况下报如下错误:
[loadConfigFile fail,error: [open : no such file or directory]]

如何重现
很简单,将配置中心地址填错就行,然后调用 demo 的接口:curl localhost:9000/check,返回的内容是空的

*bug 位置
file.go 的 getConfigFile 函数,fullPath 为空时,内部应该返回 filePath

[BUG] 在 apollo 平台上自定义了环境,代码中 apollo 配置项中没有环境参数字段

Describe the bug

您好,按照 Apollo 指导添加了新的环境:

https://github.com/ctripcorp/apollo/wiki/%E9%83%A8%E7%BD%B2&%E5%BC%80%E5%8F%91%E9%81%87%E5%88%B0%E7%9A%84%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98#42-%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E7%8E%AF%E5%A2%83

代码中 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
能够读取自定义环境的参数信息。

数据长轮询更新

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应该去掉

切换一个不存在的 namespace 后,停滞 60s 后才运行...

背景

在应用代码中重新设置 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 都等待那么久

[FEATURE]运行时获取新namespace

Is your feature request related to a problem? Please describe.
暂无

Describe the solution you'd like
运行时动态获取新namespace,并刷新到更新列表中

Describe alternatives you've considered
暂无

Additional context
暂无

默认超时时间不合理

根据官方文档 /notifications/v2接口会hold至少30S,官方建议timeout时间至少30S,最好是60S以上,目前默认值是1S,项目启动后会报超时错误

目前的connect_timeout和其他请求是共用的,可以考虑分两个超时时间。

周期性的连接Apollo服务器端超时失败

在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&notifications=%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&notifications=%5B%7B%22namespaceName%22%3A

GetStringValue - get config value fail!err:Entry not found

請問如果要取得即時數據建議怎麼使用呢?
透過下面程式, 2分鐘後就會取不到資料
原因是因為GetStringValue是從cache拿資料
但是cahce只保存120s, 所以之後都是拿預設值
所以是否有建議的使用方法呢

agollo.Start()
for {
n := agollo.GetStringValue("name", "default_name")
fmt.Println(n)
time.Sleep(5 * time.Second)
}

[FEATURE] 支持只提供 namespace 创建 Config 对象

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.

can not find apollo config!please confirm!

agollo.InitCustomConfig(func () (*agollo.AppConfig, error) {
	return &agollo.AppConfig{
		AppId:         "123",
		Cluster:       "456",
		Ip:            "ip",
		NamespaceName: "application",
	}, nil
)
agollo.Start()

事件通知结果和期望不同

我试了一下事件监听可以用,但是有点问题

  1. 我一共有2个key,key1和key2,然后我通过管理平台删除了key1,结果收到通知后,只有key2的update事件,key1直接就没有了,而不是key1的delete事件

  2. 我一共2个key,只修改了其中一个key的值,但是两个我都收到了update事件,其中一个的结果old和new是同一个值(这个是个小问题,最好能够优化一下,这样会比较方便,不过如果太复杂的话,自己比较两个值也是可以的)

[BUG] 当value大到超过cache限制会导致get失败

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:

  1. 使用超过50kb的value
  2. 获取该key的结果便会失败

如何获取到全部配置项?

如题,项目需求,需要在APP启动的时候获取到全部的配置项和值,进行定制操作,但是用GetStringValue()只能获取到指定key项的value,在不知道所有key的情况下有方法能一次拿到吗?

另外,同样也遇到了这个bug:https://github.com/zouyx/agollo/issues/23 ,希望能尽快解决,感谢!

changeEvent.ChangeType 定義為何

作者你好, 我使用下列方式 取得更換事件

event := agollo.ListenChangeEvent()
changeEvent := <-event

有時後我更該一個存在的key時, ChangeType有時取得1, 有時取得0

似乎長時間不操作後, 就會取得0
之後短時間內有一更新value, 就會取得1

[BUG]

在app_config.go中,##syncServerIpListSuccessCallBack的参数responseBody,使用string(responseBody)打印出来是标准的html,即apollo的登录页面。
请问如何反序列化为serverInfo?

[BUG]每个20min刷新ip列表存在对map的并发读写,可能导致panic

定时刷新列表存在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

定时刷新配置出错

我配置的 namespaceName 不是application,但是刷新的时候取得是默认的application的配置,导致指针错误,希望修复这个bug,可以获取我配置的那个,具体错误位置:zouyx/agollo/repository.go:253

show `get config value fail` key name

ERROR apollo: get config value fail!err:Entry not found
提个建议,如果某个字段不存在,可以把不存在的字段 key name 抛出来。
因为某些原因,会有一些字段特定情况下不会配置,然后出来好几个红色的获取字段失败,但失败的又不知道是哪些,就会比较尴尬。

数据更新增量更新

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()

使用者名单

如有使用的朋友可以在这里留言。谢谢大家支持

[FEATURE] 支持 listener 回调

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.

[FEATURE]测试问题

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.

[FEATURE]监听器支持多种文件格式类型

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.

[FEATURE]支持多环境

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.

获取配置时如何指定 env 环境?

你好,我想请问一下。在 Go Client 调用方法获取配置时,如何指定不同的环境(如 dev/test/prod...)获取配置?

image

我在官方文档中发现 Java Client ,可以通过运行时设置指定读取的环境。但是我在本项目中没有看到

请问使用本项目的话,如何通过设置不同的环境值读取不同的配置项呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.