-
Notifications
You must be signed in to change notification settings - Fork 8
feat(service_manager):将发布系统接入服务管理模块 #92
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
Open
JaD1ng
wants to merge
23
commits into
qiniu:develop
Choose a base branch
from
JaD1ng:feat/issue78
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
23f91e4
feat(observability): 添加HTTP请求时延指标收集功能
JaD1ng d5dc444
feat(observability): 添加HTTP延迟注入功能并优化指标收集
JaD1ng c8ba099
refactor(metrics): 简化HTTP时延指标名称并更新健康检查脚本
JaD1ng 334a81d
feat(prometheus_adapter): 新增prometheus_adapter实现指标查询功能
JaD1ng 48b34b0
fix(prometheus_adapter): 更新默认Prometheus地址并完善文档
JaD1ng 855c514
feat(告警): 实现告警规则同步功能并重构API层
JaD1ng 54b8f4d
feat(prometheus_adapter): 实现告警规则增量更新功能
JaD1ng f6c1ad1
feat(observability): 修复Prometheus告警规则支持并优化规则同步机制
JaD1ng 0b636a1
refactor(prometheus_adapter): 重构告警规则管理API和逻辑
JaD1ng 40d41e8
feat(prometheus_adapter): 实现告警规则持久化与优雅关闭功能
JaD1ng 271763e
feat(prometheus): 实现主动拉取告警的webhook服务
JaD1ng b6e76bd
feat(配置): 支持从多个默认路径加载配置文件
JaD1ng 4bc9b15
feat(prometheus): 实现Alertmanager兼容API并重构告警处理
JaD1ng 285412f
feat(prometheus_adapter): 添加获取绑定地址方法并优化端口配置逻辑
JaD1ng 705363e
fix(prometheus_adapter): 更新告警webhook路径并添加REDACTED字段
JaD1ng 6de1793
feat(告警规则): 添加删除规则模板和元信息的API接口
JaD1ng 4c7dab9
refactor(prometheus_adapter): 合并并扩展告警规则测试脚本
JaD1ng 4555e06
fix(prometheus_adapter): 改进服务进程管理和告警表达式生成
JaD1ng 2166377
feat(部署): 重构部署任务管理功能
JaD1ng bdf837e
feat(deploy): 实现本地部署包支持及部署流程优化
JaD1ng 20c690f
fix(alert_service): 修复表达式重复添加比较操作符的问题
JaD1ng 41ba9ab
feat(grafana): 添加QPS监控面板并配置匿名访问
JaD1ng 22df443
增加一些测试脚本
JaD1ng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/fox-gonic/fox" | ||
"github.com/qiniu/zeroops/internal/config" | ||
prometheusadapter "github.com/qiniu/zeroops/internal/prometheus_adapter" | ||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func main() { | ||
// 配置日志 | ||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) | ||
|
||
log.Info().Msg("Starting Prometheus Adapter server") | ||
|
||
// 加载 Prometheus Adapter 配置 | ||
adapter, err := prometheusadapter.NewPrometheusAdapterServer(&config.Config{}) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("Failed to create Prometheus Adapter server") | ||
} | ||
|
||
// 获取 Prometheus Adapter 内部配置的绑定地址 | ||
bindAddr := ":9999" // 默认端口 | ||
if adapter.GetBindAddr() != "" { | ||
bindAddr = adapter.GetBindAddr() | ||
} | ||
|
||
// 如果有环境变量,优先使用环境变量的端口 | ||
if port := os.Getenv("ADAPTER_PORT"); port != "" { | ||
bindAddr = ":" + port | ||
} | ||
|
||
// 更新配置(虽然已经创建了 adapter,但需要端口信息用于启动服务器) | ||
cfg := &config.Config{ | ||
Server: config.ServerConfig{ | ||
BindAddr: bindAddr, | ||
}, | ||
} | ||
|
||
// 创建路由 | ||
router := fox.New() | ||
|
||
// 启动 API | ||
if err := adapter.UseApi(router); err != nil { | ||
log.Fatal().Err(err).Msg("Failed to setup API routes") | ||
} | ||
|
||
// 设置信号处理 | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
// 创建一个用于优雅关闭的context | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// 在goroutine中启动服务器 | ||
serverErr := make(chan error, 1) | ||
go func() { | ||
log.Info().Msgf("Starting Prometheus Adapter on %s", cfg.Server.BindAddr) | ||
if err := router.Run(cfg.Server.BindAddr); err != nil { | ||
serverErr <- err | ||
} | ||
}() | ||
|
||
// 等待信号或服务器错误 | ||
select { | ||
case sig := <-sigChan: | ||
log.Info().Msgf("Received signal %s, shutting down...", sig) | ||
|
||
// 创建超时context | ||
shutdownCtx, shutdownCancel := context.WithTimeout(ctx, 10*time.Second) | ||
defer shutdownCancel() | ||
|
||
// 调用adapter的Shutdown方法 | ||
if err := adapter.Close(shutdownCtx); err != nil { | ||
log.Error().Err(err).Msg("Error during shutdown") | ||
} | ||
|
||
log.Info().Msg("Shutdown complete") | ||
|
||
case err := <-serverErr: | ||
log.Fatal().Err(err).Msg("Server error") | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
-- Deploy模块数据库架构 | ||
-- 部署相关的主机、实例和版本历史表 | ||
|
||
-- 创建hosts表:主机信息 | ||
CREATE TABLE hosts ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) UNIQUE, | ||
ip_address VARCHAR(45) UNIQUE, | ||
is_stopped BOOLEAN | ||
); | ||
|
||
-- 创建instances表:服务实例信息 | ||
CREATE TABLE instances ( | ||
id VARCHAR(255) NOT NULL PRIMARY KEY, -- VARCHAR类型主键,非自增,不为空 | ||
service_name VARCHAR(255), | ||
service_version VARCHAR(255), | ||
host_id VARCHAR(255), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
host_ip_address VARCHAR(45), | ||
ip_address VARCHAR(45), | ||
port INT, | ||
status VARCHAR(50), | ||
is_stopped BOOLEAN, | ||
-- 保留ip_address和port的组合唯一约束 | ||
CONSTRAINT unique_ip_port UNIQUE (ip_address, port) | ||
); | ||
|
||
-- 1. 创建service_name和service_version的联合索引 | ||
CREATE INDEX idx_instances_service_name_version | ||
ON instances (service_name, service_version); | ||
|
||
-- 2. 创建service_name和ip_address的联合索引 | ||
CREATE INDEX idx_instances_service_name_ip | ||
ON instances (service_name, ip_address); | ||
|
||
-- 3. 创建version_histories表:版本历史记录 | ||
CREATE TABLE version_histories ( | ||
id SERIAL PRIMARY KEY, | ||
instance_id VARCHAR(255), | ||
service_name VARCHAR(255), | ||
service_version VARCHAR(255), | ||
status VARCHAR(50) | ||
); | ||
|
||
-- 初始化主机数据 | ||
-- 插入 jfcs1021 主机数据 | ||
INSERT INTO hosts (name, ip_address, is_stopped) | ||
VALUES ('jfcs1021', '10.210.10.33', false); | ||
|
||
-- 插入 jfcs1022 主机数据 | ||
INSERT INTO hosts (name, ip_address, is_stopped) | ||
VALUES ('jfcs1022', '10.210.10.30', false); | ||
|
||
-- 插入 jfcs1023 主机数据 | ||
INSERT INTO hosts (name, ip_address, is_stopped) | ||
VALUES ('jfcs1023', '10.210.10.31', false); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的配置加载和使用方式比较混乱,可能会导致潜在的 bug。
NewPrometheusAdapterServer
使用了一个空的config.Config{}
进行初始化,这意味着adapter
实例内部没有获取到任何有效的配置信息。cfg
变量,它只包含了bindAddr
,并且仅用于第67行的router.Run()
。这种分离的配置处理方式,使得
adapter
实例在创建时无法获取到完整的配置,如果后续adapter
的其他方法需要依赖配置,就会出问题。建议重构此处的逻辑,确保配置只加载一次,并在初始化时就传递给所有需要它的组件。