@@ -15,13 +15,13 @@ import (
1515
1616// PrometheusAdapterServer Prometheus Adapter 服务器
1717type PrometheusAdapterServer struct {
18- config * config.Config
19- promConfig * promconfig.PrometheusAdapterConfig
20- promClient * client.PrometheusClient
21- metricService * service.MetricService
22- alertService * service.AlertService
23- alertWebhookService * service.AlertWebhookService
24- api * api.Api
18+ config * config.Config
19+ promConfig * promconfig.PrometheusAdapterConfig
20+ promClient * client.PrometheusClient
21+ metricService * service.MetricService
22+ alertService * service.AlertService
23+ alertmanagerProxyService * service.AlertmanagerService
24+ api * api.Api
2525}
2626
2727// NewPrometheusAdapterServer 创建新的 Prometheus Adapter 服务器
@@ -44,22 +44,16 @@ func NewPrometheusAdapterServer(cfg *config.Config) (*PrometheusAdapterServer, e
4444 // 创建告警服务
4545 alertService := service .NewAlertService (promClient , promConfig )
4646
47- // 创建告警 Webhook 服务
48- alertWebhookService := service .NewAlertWebhookService ( promClient , promConfig )
47+ // 创建 Alertmanager 代理服务
48+ alertmanagerProxyService := service .NewAlertmanagerProxyService ( promConfig )
4949
5050 server := & PrometheusAdapterServer {
51- config : cfg ,
52- promConfig : promConfig ,
53- promClient : promClient ,
54- metricService : metricService ,
55- alertService : alertService ,
56- alertWebhookService : alertWebhookService ,
57- }
58-
59- // 启动告警 Webhook 服务
60- if err := alertWebhookService .Start (); err != nil {
61- log .Error ().Err (err ).Msg ("Failed to start alert webhook service" )
62- // 不返回错误,允许服务继续运行
51+ config : cfg ,
52+ promConfig : promConfig ,
53+ promClient : promClient ,
54+ metricService : metricService ,
55+ alertService : alertService ,
56+ alertmanagerProxyService : alertmanagerProxyService ,
6357 }
6458
6559 log .Info ().Str ("prometheus_address" , promConfig .Prometheus .Address ).Msg ("Prometheus Adapter initialized successfully" )
@@ -69,23 +63,20 @@ func NewPrometheusAdapterServer(cfg *config.Config) (*PrometheusAdapterServer, e
6963// UseApi 设置 API 路由
7064func (s * PrometheusAdapterServer ) UseApi (router * fox.Engine ) error {
7165 var err error
72- s .api , err = api .NewApi (s .metricService , s .alertService , router )
66+ s .api , err = api .NewApi (s .metricService , s .alertService , s . alertmanagerProxyService , router )
7367 if err != nil {
7468 return fmt .Errorf ("failed to initialize API: %w" , err )
7569 }
7670
71+ log .Info ().Msg ("All API endpoints registered" )
72+
7773 return nil
7874}
7975
8076// Close 优雅关闭服务器
8177func (s * PrometheusAdapterServer ) Close (ctx context.Context ) error {
8278 log .Info ().Msg ("Starting shutdown..." )
8379
84- // 停止告警 Webhook 服务
85- if s .alertWebhookService != nil {
86- s .alertWebhookService .Stop ()
87- }
88-
8980 // 调用 alertService 的 Shutdown 方法保存规则
9081 if s .alertService != nil {
9182 if err := s .alertService .Shutdown (); err != nil {
0 commit comments