Skip to content

Commit

Permalink
fix when ngm not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar committed Mar 24, 2022
1 parent 8d62bdd commit fa35a72
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
48 changes: 29 additions & 19 deletions pkg/cluster/spec/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,11 @@ func (i *MonitorInstance) InitConfig(
}
uniqueHosts := set.NewStringSet()

ngcfg := config.NewNgMonitoringConfig(clusterName, clusterVersion, enableTLS)

if servers, found := topoHasField("PDServers"); found {
for i := 0; i < servers.Len(); i++ {
pd := servers.Index(i).Interface().(*PDSpec)
uniqueHosts.Insert(pd.Host)
cfig.AddPD(pd.Host, uint64(pd.ClientPort))
ngcfg.AddPD(pd.Host, uint64(pd.ClientPort))
}
}
if servers, found := topoHasField("TiKVServers"); found {
Expand Down Expand Up @@ -258,7 +255,6 @@ func (i *MonitorInstance) InitConfig(
for i := 0; i < servers.Len(); i++ {
monitoring := servers.Index(i).Interface().(*PrometheusSpec)
uniqueHosts.Insert(monitoring.Host)
cfig.AddNGMonitoring(monitoring.Host, uint64(monitoring.NgPort))
}
}
if servers, found := topoHasField("Grafanas"); found {
Expand Down Expand Up @@ -305,14 +301,13 @@ func (i *MonitorInstance) InitConfig(
if err != nil {
return err
}
cfig.SetRemoteConfig(string(remoteCfg))

// doesn't work
if _, err := i.setTLSConfig(ctx, false, nil, paths); err != nil {
return err
}

cfig.SetRemoteConfig(string(remoteCfg))

for _, alertmanager := range spec.ExternalAlertmanagers {
cfig.AddAlertmanager(alertmanager.Host, uint64(alertmanager.WebPort))
}
Expand All @@ -336,19 +331,34 @@ func (i *MonitorInstance) InitConfig(
return err
}

ngcfg.AddIP(i.GetHost())
ngcfg.AddPort(spec.NgPort)
ngcfg.AddDeployDir(paths.Deploy)
ngcfg.AddDataDir(paths.Data[0])
ngcfg.AddLog(paths.Log)

fp = filepath.Join(paths.Cache, fmt.Sprintf("ngmonitoring_%s_%d.toml", i.GetHost(), i.GetPort()))
if err := ngcfg.ConfigToFile(fp); err != nil {
return err
}
dst = filepath.Join(paths.Deploy, "conf", "ngmonitoring.toml")
if err := e.Transfer(ctx, fp, dst, false, 0, false); err != nil {
return err
if spec.NgPort > 0 {
ngcfg := config.NewNgMonitoringConfig(clusterName, clusterVersion, enableTLS)
if servers, found := topoHasField("PDServers"); found {
for i := 0; i < servers.Len(); i++ {
pd := servers.Index(i).Interface().(*PDSpec)
ngcfg.AddPD(pd.Host, uint64(pd.ClientPort))
}
}
ngcfg.AddIP(i.GetHost()).
AddPort(spec.NgPort).
AddDeployDir(paths.Deploy).
AddDataDir(paths.Data[0]).
AddLog(paths.Log)

if servers, found := topoHasField("Monitors"); found {
for i := 0; i < servers.Len(); i++ {
monitoring := servers.Index(i).Interface().(*PrometheusSpec)
cfig.AddNGMonitoring(monitoring.Host, uint64(monitoring.NgPort))
}
}
fp = filepath.Join(paths.Cache, fmt.Sprintf("ngmonitoring_%s_%d.toml", i.GetHost(), i.GetPort()))
if err := ngcfg.ConfigToFile(fp); err != nil {
return err
}
dst = filepath.Join(paths.Deploy, "conf", "ngmonitoring.toml")
if err := e.Transfer(ctx, fp, dst, false, 0, false); err != nil {
return err
}
}

fp = filepath.Join(paths.Cache, fmt.Sprintf("prometheus_%s_%d.yml", i.GetHost(), i.GetPort()))
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/template/config/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (c *PrometheusConfig) AddNGMonitoring(ip string, port uint64) *PrometheusCo
return c
}

// AddGrafana add an Grafana exporter address
// AddGrafana add an Grafana address
func (c *PrometheusConfig) AddGrafana(ip string, port uint64) *PrometheusConfig {
c.GrafanaAddr = fmt.Sprintf("%s:%d", ip, port)
return c
Expand Down

0 comments on commit fa35a72

Please sign in to comment.