From 3e537442c121d547e2bfc12a3176abde67b19e49 Mon Sep 17 00:00:00 2001 From: srstack Date: Fri, 10 Dec 2021 18:34:59 +0800 Subject: [PATCH 1/2] support alertmanager configuration Listen Host --- embed/templates/scripts/run_alertmanager.sh.tpl | 2 +- pkg/cluster/spec/alertmanager.go | 3 ++- pkg/cluster/spec/spec.go | 1 + pkg/cluster/template/scripts/alertmanager.go | 7 ++++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/embed/templates/scripts/run_alertmanager.sh.tpl b/embed/templates/scripts/run_alertmanager.sh.tpl index 19a362f905..e7925035fc 100644 --- a/embed/templates/scripts/run_alertmanager.sh.tpl +++ b/embed/templates/scripts/run_alertmanager.sh.tpl @@ -26,4 +26,4 @@ exec bin/alertmanager/alertmanager \ --cluster.peer="{{$am.IP}}:{{$am.ClusterPort}}" \ {{- end}} {{- end}} - --cluster.listen-address="{{.IP}}:{{.ClusterPort}}" + --cluster.listen-address="{{.ListenHost}}:{{.ClusterPort}}" diff --git a/pkg/cluster/spec/alertmanager.go b/pkg/cluster/spec/alertmanager.go index a3324a89d8..1453e0cc33 100644 --- a/pkg/cluster/spec/alertmanager.go +++ b/pkg/cluster/spec/alertmanager.go @@ -43,6 +43,7 @@ type AlertmanagerSpec struct { Arch string `yaml:"arch,omitempty"` OS string `yaml:"os,omitempty"` ConfigFilePath string `yaml:"config_file,omitempty" validate:"config_file:editable"` + ListenHost string `yaml:"listen_host,omitempty" validate:"listen_host:editable"` } // Role returns the component role of the instance @@ -144,7 +145,7 @@ func (i *AlertManagerInstance) InitConfig( enableTLS := gOpts.TLSEnabled // Transfer start script spec := i.InstanceSpec.(*AlertmanagerSpec) - cfg := scripts.NewAlertManagerScript(spec.Host, paths.Deploy, paths.Data[0], paths.Log, enableTLS). + cfg := scripts.NewAlertManagerScript(spec.Host, spec.ListenHost, paths.Deploy, paths.Data[0], paths.Log, enableTLS). WithWebPort(spec.WebPort).WithClusterPort(spec.ClusterPort).WithNumaNode(spec.NumaNode). AppendEndpoints(AlertManagerEndpoints(alertmanagers, deployUser, enableTLS)) diff --git a/pkg/cluster/spec/spec.go b/pkg/cluster/spec/spec.go index 73a6533f0c..6d3e73afae 100644 --- a/pkg/cluster/spec/spec.go +++ b/pkg/cluster/spec/spec.go @@ -773,6 +773,7 @@ func AlertManagerEndpoints(alertmanager []*AlertmanagerSpec, user string, enable script := scripts.NewAlertManagerScript( spec.Host, + spec.ListenHost, deployDir, dataDir, logDir, diff --git a/pkg/cluster/template/scripts/alertmanager.go b/pkg/cluster/template/scripts/alertmanager.go index ba6667dd23..70bab93015 100644 --- a/pkg/cluster/template/scripts/alertmanager.go +++ b/pkg/cluster/template/scripts/alertmanager.go @@ -25,6 +25,7 @@ import ( // AlertManagerScript represent the data to generate AlertManager start script type AlertManagerScript struct { IP string + ListenHost string WebPort int ClusterPort int DeployDir string @@ -36,9 +37,13 @@ type AlertManagerScript struct { } // NewAlertManagerScript returns a AlertManagerScript with given arguments -func NewAlertManagerScript(ip, deployDir, dataDir, logDir string, enableTLS bool) *AlertManagerScript { +func NewAlertManagerScript(ip, listenHost, deployDir, dataDir, logDir string, enableTLS bool) *AlertManagerScript { + if listenHost == "" { + listenHost = ip + } return &AlertManagerScript{ IP: ip, + ListenHost: listenHost, WebPort: 9093, ClusterPort: 9094, DeployDir: deployDir, From fc030c8756bc83eb254f449ca4bd3d2ee3bbee15 Mon Sep 17 00:00:00 2001 From: srstack Date: Mon, 13 Dec 2021 11:33:45 +0800 Subject: [PATCH 2/2] perfect tips --- pkg/cluster/spec/alertmanager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/spec/alertmanager.go b/pkg/cluster/spec/alertmanager.go index 1453e0cc33..14c5dc528e 100644 --- a/pkg/cluster/spec/alertmanager.go +++ b/pkg/cluster/spec/alertmanager.go @@ -35,6 +35,7 @@ type AlertmanagerSpec struct { IgnoreExporter bool `yaml:"ignore_exporter,omitempty"` WebPort int `yaml:"web_port" default:"9093"` ClusterPort int `yaml:"cluster_port" default:"9094"` + ListenHost string `yaml:"listen_host,omitempty" validate:"listen_host:editable"` DeployDir string `yaml:"deploy_dir,omitempty"` DataDir string `yaml:"data_dir,omitempty"` LogDir string `yaml:"log_dir,omitempty"` @@ -43,7 +44,6 @@ type AlertmanagerSpec struct { Arch string `yaml:"arch,omitempty"` OS string `yaml:"os,omitempty"` ConfigFilePath string `yaml:"config_file,omitempty" validate:"config_file:editable"` - ListenHost string `yaml:"listen_host,omitempty" validate:"listen_host:editable"` } // Role returns the component role of the instance