Merge branch 'V5.2' into V5.2

This commit is contained in:
黄润豪 2020-07-24 09:40:43 +08:00 committed by GitHub
commit 72d31526b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 22 deletions

View File

@ -96,6 +96,9 @@ func (m *EventFilePlugin) GetMessages(eventID, level string, length int) (interf
}
eventFile, err := os.Open(apath)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
defer eventFile.Close()

View File

@ -33,6 +33,8 @@ import (
type Etcd struct {
discover.Callback
Prometheus *prometheus.Manager
Scheme string
TLSConfig prometheus.TLSConfig
sortedEndpoints []string
}
@ -66,8 +68,9 @@ func (e *Etcd) toScrape() *prometheus.ScrapeConfig {
ts = append(ts, end)
}
return &prometheus.ScrapeConfig{
sc := &prometheus.ScrapeConfig{
JobName: e.Name(),
Scheme: e.Scheme,
ScrapeInterval: model.Duration(1 * time.Minute),
ScrapeTimeout: model.Duration(30 * time.Second),
MetricsPath: "/metrics",
@ -82,4 +85,10 @@ func (e *Etcd) toScrape() *prometheus.ScrapeConfig {
},
},
}
if e.Scheme == "https" {
sc.HTTPClientConfig = prometheus.HTTPClientConfig{
TLSConfig: e.TLSConfig,
}
}
return sc
}

View File

@ -61,7 +61,20 @@ func (d *Monitor) Start() {
go d.discoverNodes(&callback.Node{Prometheus: d.manager}, &callback.App{Prometheus: d.manager}, d.ctx.Done())
// monitor etcd members
go d.discoverEtcd(&callback.Etcd{Prometheus: d.manager}, d.ctx.Done())
go d.discoverEtcd(&callback.Etcd{
Prometheus: d.manager,
Scheme: func() string {
if d.config.EtcdCertFile != "" {
return "https"
}
return "http"
}(),
TLSConfig: prometheus.TLSConfig{
CAFile: d.config.EtcdCaFile,
CertFile: d.config.EtcdCertFile,
KeyFile: d.config.EtcdKeyFile,
},
}, d.ctx.Done())
// monitor Cadvisor
go d.discoverCadvisor(&callback.Cadvisor{

View File

@ -19,10 +19,11 @@
package prometheus
import (
"github.com/prometheus/common/model"
"net/url"
"regexp"
"time"
"github.com/prometheus/common/model"
)
// Config is the top-level configuration for Prometheus's config files.

View File

@ -187,13 +187,6 @@ func NewRulesManager(config *option.Config) *AlertingRulesManager {
Labels: commonLables,
Annotations: map[string]string{"summary": "mq unhealthy"},
},
&RulesConfig{
Alert: "TeamTaskMany",
Expr: "acp_mq_dequeue_number-acp_mq_enqueue_number > 200",
For: "3m",
Labels: commonLables,
Annotations: map[string]string{"summary": "The number of tasks in the queue is greater than 200"},
},
},
},
&AlertingNameConfig{

View File

@ -33,6 +33,11 @@ import (
func TrimAndSort(endpoints []*config.Endpoint) []string {
arr := make([]string, 0, len(endpoints))
for _, end := range endpoints {
if strings.HasPrefix(end.URL, "https://") {
url := strings.TrimLeft(end.URL, "https://")
arr = append(arr, url)
continue
}
url := strings.TrimLeft(end.URL, "http://")
arr = append(arr, url)
}

View File

@ -158,12 +158,16 @@ func conversionServicePlugin(as *typesv1.AppService, dbmanager db.Manager) ([]v1
func createTCPDefaultPluginContainer(as *typesv1.AppService, pluginID string, envs []v1.EnvVar) v1.Container {
envs = append(envs, v1.EnvVar{Name: "PLUGIN_ID", Value: pluginID})
_, xdsHostPort, apiHostPort := getXDSHostIPAndPort()
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
}})
xdsHost, xdsHostPort, apiHostPort := getXDSHostIPAndPort()
if xdsHost == "" {
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
}})
} else {
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", Value: xdsHost})
}
envs = append(envs, v1.EnvVar{Name: "API_HOST_PORT", Value: apiHostPort})
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_PORT", Value: xdsHostPort})
@ -177,12 +181,16 @@ func createTCPDefaultPluginContainer(as *typesv1.AppService, pluginID string, en
func createProbeMeshInitContainer(as *typesv1.AppService, pluginID, serviceAlias string, envs []v1.EnvVar) v1.Container {
envs = append(envs, v1.EnvVar{Name: "PLUGIN_ID", Value: pluginID})
_, xdsHostPort, apiHostPort := getXDSHostIPAndPort()
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
}})
xdsHost, xdsHostPort, apiHostPort := getXDSHostIPAndPort()
if xdsHost == "" {
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
}})
} else {
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", Value: xdsHost})
}
envs = append(envs, v1.EnvVar{Name: "API_HOST_PORT", Value: apiHostPort})
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_PORT", Value: xdsHostPort})
return v1.Container{