Skip to content

Commit

Permalink
cluster: support alertmanager configuration Listen Host (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
srstack authored Dec 13, 2021
1 parent 0de8baf commit b01e507
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion embed/templates/scripts/run_alertmanager.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
3 changes: 2 additions & 1 deletion pkg/cluster/spec/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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))

Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ func AlertManagerEndpoints(alertmanager []*AlertmanagerSpec, user string, enable

script := scripts.NewAlertManagerScript(
spec.Host,
spec.ListenHost,
deployDir,
dataDir,
logDir,
Expand Down
7 changes: 6 additions & 1 deletion pkg/cluster/template/scripts/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit b01e507

Please sign in to comment.