Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support config server v2 provider(HeartBeat、FetchPipelineConfig、FetchProcessConfig) #1710

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d9becf2
Support config server v2 provider(HeartBeat、FetchPipelineConfig、Fetch…
ww67652 Aug 21, 2024
10032e8
Merge branch 'alibaba:main' into main
ww67652 Aug 21, 2024
23bfe88
Update file due to changes of 'Process ->Instance' in proto
ww67652 Aug 22, 2024
4dc3434
change the structure of project
ww67652 Aug 22, 2024
d482825
fix:fix the slow sql while creating agent
ww67652 Aug 22, 2024
e3eb7b7
Merge remote-tracking branch 'origin/main'
ww67652 Aug 25, 2024
ccbdc2d
add: Implement support for multiple data sources
ww67652 Aug 26, 2024
838836c
add: Support interaction between user and config-server.
ww67652 Sep 4, 2024
f6aac54
Merge remote-tracking branch 'origin/main'
ww67652 Sep 4, 2024
065744e
fix: Optimized the error handling logic and added error chaining for …
ww67652 Sep 4, 2024
f4f3a20
Merge remote-tracking branch 'origin/main'
ww67652 Sep 4, 2024
56355f1
fix: fix the error of error handler
ww67652 Sep 4, 2024
fec3d7f
fix: fix the bug in backend code
ww67652 Sep 9, 2024
4c7e8b6
init frontend and finish backend
ww67652 Sep 10, 2024
e8237b6
fix:fix the bug in backend and post a demo request with protobuf from…
ww67652 Sep 10, 2024
097b052
fix:fix the bug in backend and post a demo request with protobuf from…
ww67652 Sep 10, 2024
e6810cb
add : add features and functions
ww67652 Sep 15, 2024
10f9102
add : Implemented regular checks on the correspondence between config…
ww67652 Sep 15, 2024
173211c
add: finish basic function
ww67652 Sep 15, 2024
96f9876
finish:finish the all project
ww67652 Sep 16, 2024
db4c001
finish:add document
ww67652 Sep 16, 2024
dd9d368
finish:add document
ww67652 Sep 16, 2024
beee4b6
finish:add document
ww67652 Sep 16, 2024
9b51d72
modify the directory structure
ww67652 Sep 19, 2024
fb2f913
add necessary document
ww67652 Sep 20, 2024
51f12d3
Optimize container startup logic
ww67652 Sep 20, 2024
81fc239
Rollback: Merge exception caused by incorrect file modifications
ww67652 Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Config-server

这是基于阿里巴巴 iLogtail 项目 Config Server v2通信协议的一个前后端实现。

后端使用GO基于gin框架开发,针对https://github.com/alibaba/ilogtail/tree/main/config_server/protocol/v2 中提到的Agent行为进行了V2版本的适配,基本实现了能力报告、心跳压缩、配置状态上报等功能,并包含用户端接口,详情见[service](service/README.md)。

前端使用 Vue + Element plus 组件库 + Vue cli 脚手架工具进行开发,旨在为用户提供一个简单、实用、易嵌入的 Config Server 前端控制台,详情见[ui](ui/README.md)。

本项目提供了docker compose一键部署脚本,帮助用户快速搭建可用可视化与agent连通的config-server应用,详情见[deployment](deployment/README.md)。



6 changes: 6 additions & 0 deletions config_server/deployment/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CONFIG_SERVER=../service
CONFIG_SERVER_UI=../ui

# 需把该目录下的Dockerfile-agent复制到agent对应的目录下,并修改${AGENT}为agent所在目录路径
AGENT=/home/agent/ilogtail-nzh
AGENT_DEV_DOCKERFILE=/home/nzh/ilogtail/config_server/deployment/Dockerfile-Agent
18 changes: 18 additions & 0 deletions config_server/deployment/Dockerfile-Agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM centos:7

RUN curl -L -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& yum update -y \
&& yum upgrade -y \
&& yum -y clean all \
&& rm -fr /var/cache \
&& rm -rf /core.* \
&& yum install -y gettext

WORKDIR /agent
COPY . .

CMD envsubst < ilogtail_config.template.json > ilogtail_config.json \
&& sh -c ./ilogtail > stdout.log 2> stderr.log



41 changes: 41 additions & 0 deletions config_server/deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 部署说明

本项目实现了config-server的后端(config-server)与前端(config-server-ui),并基于docker与docker-compose的方式进行部署

## 快速开始

进入`deployment`目录,运行`deployment-compose.yml`,启动三个容器(`mysql`、`config-server`、`config-server-ui`)

```shell
docker compose -f docker-compose.yml up -d
```

启动成功后,通过`http://{your-ip}:8080`即可实现前端页面的访问

![config-server-ui](../ui/public/config-server-ui.png)

## Agent启动

为了便于使用(测试)`config-server-ui`,本项目提供了基于docker启动Agent的脚本,复制`Dockefile-Agent`与`ilogtail_config.template.json`到Agent的目录下,
修改`.env`中的`${AGENT}`为Agent所在目录路径(Agent安装与启动见[quick-start](https://github.com/alibaba/ilogtail/blob/main/docs/cn/installation/quick-start.md)),并在`docker-compose.yml`添加
```yml
agent:
build:
context: ${AGENT}
dockerfile: Dockerfile-Agent
image: ilogtail:nzh
environment:
CONFIG_SERVER_ADDRESSES: '["config-server:9090"]'
TZ: Asia/Shanghai
deploy:
replicas: 3
networks:
- server
```

再次运行下面的命令,这将会启动3个ilogtail Agent。

```shell
docker compose -f docker-compose.yml up -d
```

65 changes: 65 additions & 0 deletions config_server/deployment/docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
version: '3.8'
services:
mysql:
image: mysql:latest
volumes:
- /var/lib/mysql:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "123456"
cap_add:
- SYS_NICE
networks:
- server

config-server-dev:
build:
context: ${CONFIG_SERVER}
#Dockerfile指定了context后,若不使用全局路径,则为context的相对路径
dockerfile: Dockerfile-dev
image: config-server-dev:nzh
#替换成你代码的位置
volumes:
- ${CONFIG_SERVER}:/backend
ports:
- "9090:9090"
environment:
TZ: Asia/Shanghai
networks:
- server
depends_on:
- mysql

agent-dev:
build:
#确保目录下有agent
context: ${AGENT}
dockerfile: ${AGENT_DEV_DOCKERFILE}
image: ilogtail-dev:nzh
environment:
CONFIG_SERVER_ADDRESSES: '["host.docker.internal:9090"]'
TZ: Asia/Shanghai
extra_hosts:
- "host.docker.internal:host-gateway"
deploy:
replicas: 2
networks:
- server

config-server-ui:
build:
context: ${CONFIG_SERVER_UI}
dockerfile: Dockerfile
image: config-server-ui:nzh
ports:
- "8080:8080"
environment:
TZ: Asia/Shanghai
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- server

networks:
server:
69 changes: 69 additions & 0 deletions config_server/deployment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: '3.8'
services:
mysql:
image: mysql:latest
volumes:
- /var/lib/mysql:/var/lib/mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: "123456"
cap_add:
- SYS_NICE
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
interval: 10s
retries: 5
timeout: 5s
networks:
- server

config-server:
build:
context: ${CONFIG_SERVER}
dockerfile: Dockerfile
# 如果之前构建过镜像,再次docker compose则不会重新构建
image: config-server:nzh
ports:
- "9090:9090"
environment:
TZ: Asia/Shanghai
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- server
depends_on:
mysql:
condition: service_healthy

config-server-ui:
build:
context: ${CONFIG_SERVER_UI}
dockerfile: Dockerfile
image: config-server-ui:nzh
ports:
- "8080:8080"
environment:
TZ: Asia/Shanghai
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- server

# 通过下面的服务启动ilogtail agent的docker版本,并与config-server成功通信,具体配置流程见readme
agent:
build:
context: ${AGENT}
dockerfile: Dockerfile-Agent
image: ilogtail:nzh
environment:
CONFIG_SERVER_ADDRESSES: '["config-server:9090"]'
TZ: Asia/Shanghai
deploy:
replicas: 3
networks:
- server

#替换成你自己的网络
networks:
server:
8 changes: 8 additions & 0 deletions config_server/deployment/ilogtail_config.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"config_server_list" : [
{
"cluster":"community",
"endpoint_list":$CONFIG_SERVER_ADDRESSES
}
]
}
10 changes: 5 additions & 5 deletions config_server/protocol/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
// The Agent can accept pipeline configuration from the Server.
AcceptsPipelineConfig = 0x00000001;
// The Agent can accept process configuration from the Server.
AcceptsProcessConfig = 0x00000002;
AcceptsInstanceConfig = 0x00000002;
// The Agent can accept custom command from the Server.
AcceptsCustomCommand = 0x00000004;

Expand Down Expand Up @@ -127,7 +127,7 @@
// The Server can remember pipeline config status.
RembersPipelineConfigStatus = 0x00000002;
// The Server can remember process config status.
RembersProcessConfigStatus = 0x00000004;
RembersInstanceConfigStatus = 0x00000004;
// The Server can remember custom command status.
RembersCustomCommandStatus = 0x00000008;

Expand All @@ -150,7 +150,7 @@
// restarted and lost state).
ReportFullState = 0x00000001;
FetchPipelineConfigDetail = 0x00000002;
FetchProcessConfigDetail = 0x00000004;
FetchInstanceConfigDetail = 0x00000004;
// bits before 2^16 (inclusive) are reserved for future official fields
}

Expand Down Expand Up @@ -198,9 +198,9 @@ Client:直接从response中获得detail,应用成功后下次心跳需要上

若Server的响应不包含detail

Client:根据process\_config\_updates的信息构造FetchProcessConfigRequest
Client:根据process\_config\_updates的信息构造FetchInstanceConfigRequest

Server:返回FetchProcessConfigResponse
Server:返回FetchInstanceConfigResponse

Client获取到多个进程配置时,自动合并,若产生冲突默认行为是未定义。

Expand Down
40 changes: 20 additions & 20 deletions config_server/protocol/v2/agent.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
syntax = "proto3";
package configserver.proto.v2;
option go_package = "/config_server/service/protov2;configserver_proto_v2";
option go_package = "/protov2;";

message AgentGroupTag {
string name = 1;
Expand Down Expand Up @@ -49,8 +48,8 @@ enum AgentCapabilities {
UnspecifiedAgentCapability = 0;
// The Agent can accept pipeline configuration from the Server.
AcceptsPipelineConfig = 0x00000001;
// The Agent can accept process configuration from the Server.
AcceptsProcessConfig = 0x00000002;
// The Agent can accept instance configuration from the Server.
AcceptsInstanceConfig = 0x00000002;
// The Agent can accept custom command from the Server.
AcceptsCustomCommand = 0x00000004;

Expand Down Expand Up @@ -81,7 +80,7 @@ message HeartbeatRequest {
string running_status = 8; // Human readable running status
int64 startup_time = 9; // Required, Agent's startup time
repeated ConfigInfo pipeline_configs = 10; // Information about the current PIPELINE_CONFIG held by the Agent
repeated ConfigInfo process_configs = 11; // Information about the current AGENT_CONFIG held by the Agent
repeated ConfigInfo instance_configs = 11; // Information about the current AGENT_CONFIG held by the Agent
repeated CommandInfo custom_commands = 12; // Information about command history
uint64 flags = 13; // Predefined command flag
bytes opaque = 14; // Opaque data for extension
Expand All @@ -102,20 +101,15 @@ message CommandDetail {
int64 expire_time = 4; // After which the command can be safely removed from history
}

message ServerErrorResponse {
int32 error_code = 1; // None-zero value indicates error
string error_message = 2; // Error message
}

enum ServerCapabilities {
// The capabilities field is unspecified.
UnspecifiedServerCapability = 0;
// The Server can remember agent attributes.
RembersAttribute = 0x00000001;
// The Server can remember pipeline config status.
RembersPipelineConfigStatus = 0x00000002;
// The Server can remember process config status.
RembersProcessConfigStatus = 0x00000004;
// The Server can remember instance config status.
RembersInstanceConfigStatus = 0x00000004;
// The Server can remember custom command status.
RembersCustomCommandStatus = 0x00000008;

Expand All @@ -133,35 +127,41 @@ enum ResponseFlags {
// restarted and lost state).
ReportFullState = 0x00000001;
FetchPipelineConfigDetail = 0x00000002;
FetchProcessConfigDetail = 0x00000004;
FetchInstanceConfigDetail = 0x00000004;
// bits before 2^16 (inclusive) are reserved for future official fields
}

// ConfigServer's response to Agent's request
message HeartbeatResponse {
bytes request_id = 1;
ServerErrorResponse error_response = 2; // Set value indicates error
bytes request_id = 1;
CommonResponse common_response = 2; // Set common response
uint64 capabilities = 3; // Bitmask of flags defined by ServerCapabilities enum

repeated ConfigDetail pipeline_config_updates = 4; // Agent's pipeline config update status
repeated ConfigDetail process_config_updates = 5; // Agent's process config update status
repeated ConfigDetail instance_config_updates = 5; // Agent's instance config update status
repeated CommandDetail custom_command_updates = 6; // Agent's commands updates
uint64 flags = 7; // Predefined command flag
bytes opaque = 8; // Opaque data for extension
}

// API: /Agent/FetchPipelineConfig/
// API: /Agent/FetchProcessConfig/
// API: /Agent/FetchInstanceConfig/
// Agent request to ConfigServer, pulling details of the config
message FetchConfigRequest {
bytes request_id = 1;
bytes request_id = 1;
bytes instance_id = 2; // Agent's unique identification
repeated ConfigInfo req_configs = 3; // Config's name and version/hash
}

// ConfigServer response to Agent's request
message FetchConfigResponse {
bytes request_id = 1;
ServerErrorResponse error_response = 2;
bytes request_id = 1;
CommonResponse common_response = 2;
repeated ConfigDetail config_details = 3; // config detail
}

message CommonResponse
{
int32 status = 1;
bytes error_message = 2;
}
Loading