diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/.goreleaser.yml b/.goreleaser.yml index ee4431a..83f1fce 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,13 +1,17 @@ # This is an example .goreleaser.yml file with some sane defaults. # Make sure to check the documentation at https://goreleaser.com +builds: + - + goos: + - darwin + - linux + - windows + goarch: + - amd64 + - arm + - arm64 archives: - - replacements: - darwin: Darwin - linux: Linux - windows: Windows - 386: i386 - amd64: x86_64 files: - LICENSE - docs/* diff --git a/conf/conf-agent.toml b/conf/conf-agent.toml index 02dabbf..095826d 100644 --- a/conf/conf-agent.toml +++ b/conf/conf-agent.toml @@ -1,14 +1,14 @@ [Logger] LogDir = "./log/" LogName = "conf_gent" -LogLevel = "DEBUG" +LogLevel = "INFO" RotateWhen = "MIDNIGHT" BackupCount = 2 Format = "[%D %T] [%L] [%S] %M" -StdOut = true +StdOut = false [Basic] -BFECluster = "ALB-test-02" +BFECluster = "{BFECluster}" BFEConfDir = "/home/work/bfe/conf" BFEMonitorPort = 8421 BFEReloadTimeoutMs = 1500 @@ -16,11 +16,13 @@ BFEReloadTimeoutMs = 1500 ReloadIntervalMs = 5000 ConfServer = "http://127.0.0.1:8183" -ConfTaskHeaders = {"Authorization" = "Session bS9YlAKPFmtSdIp8_yvJ"} +# Token 获取参考 https://github.com/bfenetworks/dashboard/blob/develop/docs/zh-cn/user-guide/system-view/user-management.md#token%E7%AE%A1%E7%90%86 +ConfTaskHeaders = {"Authorization" = "Session {Token}"} ConfTaskTimeoutMs = 1500 ExtraFileServer = "http://127.0.0.1:8183/inner-api/v1/configs/extra_files/" -ExtraFileTaskHeaders = {"Authorization" = "Session bS9YlAKPFmtSdIp8_yvJ"} +# Token 获取参考 https://github.com/bfenetworks/dashboard/blob/develop/docs/zh-cn/user-guide/system-view/user-management.md#token%E7%AE%A1%E7%90%86 +ExtraFileTaskHeaders = {"Authorization" = "Session {Token}"} ExtraFileTaskTimeoutMs = 1500 diff --git a/conf_reload/reloader.go b/conf_reload/reloader.go index 07850f9..57fdc8d 100644 --- a/conf_reload/reloader.go +++ b/conf_reload/reloader.go @@ -75,16 +75,19 @@ func (r *Reloader) Start() { } func (r *Reloader) reload(ctx context.Context) { + xlog.Default.Info(xlog.InfoLogFormat(ctx, "reload begin")) + // fetch newer data file fileList, err := r.prober.Probe(ctx) if err != nil { xlog.Default.Error(xlog.ErrLogFormat(ctx, "probe", err)) return } + xlog.Default.Info(xlog.InfoLogFormat(ctx, "probe succ")) // no newer data file, exit if len(fileList) == 0 { - xlog.Default.Info(xlog.InfoLogFormat(ctx, "exit", "without_update")) + xlog.Default.Info(xlog.InfoLogFormat(ctx, "reload succ", "without_update")) return } @@ -100,20 +103,25 @@ func (r *Reloader) reload(ctx context.Context) { // store all newer data file err = r.fileStore.StoreFile2TmpDir(ctx, version, files) if err != nil { + xlog.Default.Error(xlog.ErrLogFormat(ctx, "StoreFile2TmpDir fail", err)) return } + xlog.Default.Info(xlog.InfoLogFormat(ctx, "StoreFile2TmpDir succ")) // trigger bfe reload err = r.trigger.TriggerBFEReload(ctx, version) if err != nil { + xlog.Default.Error(xlog.ErrLogFormat(ctx, "TriggerBFEReload fail", err)) return } + xlog.Default.Info(xlog.InfoLogFormat(ctx, "TriggerBFEReload succ")) // replace old config by newest, if fail, it's ok err = r.fileStore.UpdateDefaultConfDir(ctx, version) if err != nil { - xlog.Default.Info(xlog.ErrLogFormat(ctx, "UpdateDefaultConfDir", err)) + xlog.Default.Error(xlog.ErrLogFormat(ctx, "UpdateDefaultConfDir fail", err)) } + xlog.Default.Info(xlog.InfoLogFormat(ctx, "UpdateDefaultConfDir succ")) - xlog.Default.Info(xlog.InfoLogFormat(ctx, "exit", "update")) + xlog.Default.Info(xlog.InfoLogFormat(ctx, "reload succ", "update")) } diff --git a/docs/zh_cn/README.md b/docs/zh_cn/README.md index ac2519b..4966130 100644 --- a/docs/zh_cn/README.md +++ b/docs/zh_cn/README.md @@ -1,20 +1,22 @@ # conf-agent -## 1. conf-agent 说明 +## conf-agent 说明 conf-agent 从 api-server 获取最新的配置并触发bfe热加载。 -## 2. 获取方式 +## 获取方式 获取 `conf-agent` 工具。获取 `conf-agent` 有多种方式: - 在relase页面下载对应平台的可执行文件 - 通过 `go get` 工具本地编译 - 下载本仓库,执行 `make` (需要go开发环境) -## 3. 配置说明 +## 配置说明 在api-server有对应导出接口的前提下,conf-agent通过配置能够支持所有的module的配置拉取和热加载。 配置详见[配置详情](./config.md) +- 访问 API Server 需要 在配置文件中配置 Token,获取方式见[通过Dashboard获取Token](https://github.com/bfenetworks/dashboard/blob/develop/docs/zh-cn/user-guide/system-view/user-management.md#token%E7%AE%A1%E7%90%86) +- BFECluster 配置为在控制台配置的有效 BFE Cluster,配置方式见[通过Dashboard配置BFECluster](https://github.com/bfenetworks/dashboard/blob/develop/docs/zh-cn/user-guide/system-view/bfe-cluster-and-pool.md#bfe%E9%9B%86%E7%BE%A4%E7%9A%84%E9%85%8D%E7%BD%AE) -## 4. 部署和启动 +## 部署和启动 和 bfe同机部署 启动命令为: @@ -23,5 +25,10 @@ conf-agent 从 api-server 获取最新的配置并触发bfe热加载。 ./conf-agent -c ../conf/ -cf conf-agent.toml ``` -## 5. 实现原理 -详见[实现原理](./implementation.md) \ No newline at end of file +## 实现原理 +详见[实现原理](./implementation.md) + + +## 关于BFE +- 官网:https://www.bfe-networks.net +- 书籍:[《深入理解BFE》](https://github.com/baidu/bfe-book) :介绍网络接入的相关技术原理,说明BFE的设计思想,以及如何基于BFE搭建现代化的网络接入平台。现已开放全文阅读。 diff --git a/docs/zh_cn/config.md b/docs/zh_cn/config.md index 3a9c440..7d3a47c 100644 --- a/docs/zh_cn/config.md +++ b/docs/zh_cn/config.md @@ -28,10 +28,10 @@ | BFEReloadTimeoutMs | int | BFE reload 超时设置 | N | 1500 | | | ReloadIntervalMs | int | 拉取时间间隔 | N | 10000 | | | ConfServer | string | APIServer服务器,用来拉取配置 | Y | - | | -| ConfTaskHeaders | map\string | 静态文件请求Header | N | - | | +| ConfTaskHeaders | map\string | 配置请求Header, Api Server 当前会对请求鉴权,需要设置 Authorization 头, [通过Dashboard获取Token](https://github.com/bfenetworks/dashboard/blob/develop/docs/zh-cn/user-guide/system-view/user-management.md#token%E7%AE%A1%E7%90%86) | N | - | | | ConfTaskTimeoutMs | int | 配置拉取超时 | Y | 2500 | | | ExtraFileServer | string | 静态文件服务器,用来拉取静态文件 | Y | - | | -| ExtraFileTaskHeaders | map\string | 静态文件请求Header | N | - | | +| ExtraFileTaskHeaders | map\string | 静态文件请求Header, Api Server 当前会对请求鉴权,需要设置 Authorization 头, [通过Dashboard获取Token](https://github.com/bfenetworks/dashboard/blob/develop/docs/zh-cn/user-guide/system-view/user-management.md#token%E7%AE%A1%E7%90%86) | N | - | | | ExtraFileTaskTimeoutMs | int | 静态文件拉取超时 | Y | 2500 | | ## 3 Reloaders配置