Skip to content

Commit

Permalink
feature:
Browse files Browse the repository at this point in the history
- Prometheus Watch 支持同应用单机多IP
- 带鉴权ETCD auth token失效问题解决,临时方案
  • Loading branch information
kl7sn committed Aug 17, 2020
1 parent 3ca2c33 commit 00481c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 12 additions & 6 deletions pkg/proxy/confProxy/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ var (

// DataSource etcd conf datasource
type DataSource struct {
etcdClient *etcdv3.Client
prefix string
etcdClient *etcdv3.Client
etcdClientReport *etcdv3.Client
prefix string
// 用于记录长轮训的应用信息
jm list.List // *job
}
Expand All @@ -59,8 +60,9 @@ type configNode struct {
// NewETCDDataSource ...
func NewETCDDataSource(prefix string, etcdConfig ConfDataSourceEtcd) *DataSource {
dataSource := &DataSource{
etcdClient: etcdv3.RawConfig("plugin.confProxy.etcd").Build(),
prefix: prefix,
etcdClient: etcdv3.RawConfig("plugin.confProxy.etcd").Build(),
etcdClientReport: etcdv3.RawConfig("plugin.confProxy.etcd").Build(),
prefix: prefix,
}
xgo.Go(dataSource.watch)
return dataSource
Expand Down Expand Up @@ -292,8 +294,12 @@ func (d *DataSource) report(key, value string) error {
IP: ip,
HealthPort: confuKeys.Port,
}
if _, err := d.etcdClient.Put(ctx, reportKey, reportValue.JSONString()); err != nil {
return err
if _, err := d.etcdClientReport.Put(ctx, reportKey, reportValue.JSONString()); err != nil {
//if err == auth.ErrInvalidAuthToken {
d.etcdClientReport = etcdv3.RawConfig("plugin.confProxy.etcd").Build()
if _, err := d.etcdClientReport.Put(ctx, reportKey, reportValue.JSONString()); err != nil {
return err
}
}
return nil
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/proxy/regProxy/etcd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,24 @@ func (d *DataSource) watchPrometheus(path string) {
fmt.Println("key", key, "value", value)
break
}
os.Remove("/tmp/etc/prometheus/conf/" + keyArr[3] + ".yml")
filename := keyArr[3] + "_" + value
os.Remove("/tmp/etc/prometheus/conf/" + filename + ".yml")
case mvccpb.PUT:
key, value := string(event.Kv.Key), string(event.Kv.Value)
keyArr := strings.Split(key, "/")
if len(keyArr) != 5 {
fmt.Println("key", key, "value", value)
break
}
filename := keyArr[3] + "_" + value
content := `
- targets:
- "` + value + `"
labels:
instance: ` + keyArr[4] + `
job: ` + keyArr[3]
util.WriteFile(path+"/"+keyArr[3]+".yml", content)
_ = util.WriteFile(path+"/"+filename+".yml", content)
}
}
}
Expand Down

0 comments on commit 00481c8

Please sign in to comment.