mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-10-25 04:32:10 +08:00
fix: prometheus
This commit is contained in:
parent
15d7129c46
commit
909f3a4a24
@ -96,7 +96,7 @@ func Start(ctx context.Context, index int, cfg *Config) error {
|
|||||||
|
|
||||||
etcdClient := client.(*etcd.SvcDiscoveryRegistryImpl).GetClient()
|
etcdClient := client.(*etcd.SvcDiscoveryRegistryImpl).GetClient()
|
||||||
|
|
||||||
_, err = etcdClient.Put(ctx, prommetrics.BuildDiscoveryKey(prommetrics.APIKeyName), jsonutil.StructToJsonString(prommetrics.BuildDefaultTarget(registerIP, prometheusPort)))
|
_, err = etcdClient.Put(ctx, prommetrics.BuildDiscoveryKey(prommetrics.APIKeyName, index), jsonutil.StructToJsonString(prommetrics.BuildDefaultTarget(registerIP, prometheusPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.WrapMsg(err, "etcd put err")
|
return errs.WrapMsg(err, "etcd put err")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ func (p *PrometheusDiscoveryApi) Enable(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrometheusDiscoveryApi) discovery(c *gin.Context, key string) {
|
func (p *PrometheusDiscoveryApi) discovery(c *gin.Context, key string) {
|
||||||
eResp, err := p.client.Get(c, prommetrics.BuildDiscoveryKey(key))
|
eResp, err := p.client.Get(c, prommetrics.BuildDiscoveryKeyPrefix(key), clientv3.WithPrefix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log and respond with an error if preparation fails.
|
// Log and respond with an error if preparation fails.
|
||||||
apiresp.GinError(c, errs.WrapMsg(err, "etcd get err"))
|
apiresp.GinError(c, errs.WrapMsg(err, "etcd get err"))
|
||||||
|
|||||||
@ -178,7 +178,7 @@ func (m *MsgTransfer) Start(index int, cfg *Config) error {
|
|||||||
|
|
||||||
etcdClient := client.(*etcd.SvcDiscoveryRegistryImpl).GetClient()
|
etcdClient := client.(*etcd.SvcDiscoveryRegistryImpl).GetClient()
|
||||||
|
|
||||||
_, err = etcdClient.Put(context.TODO(), prommetrics.BuildDiscoveryKey(prommetrics.MessageTransferKeyName), jsonutil.StructToJsonString(prommetrics.BuildDefaultTarget(registerIP, prometheusPort)))
|
_, err = etcdClient.Put(context.TODO(), prommetrics.BuildDiscoveryKey(prommetrics.MessageTransferKeyName, index), jsonutil.StructToJsonString(prommetrics.BuildDefaultTarget(registerIP, prometheusPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.WrapMsg(err, "etcd put err")
|
return errs.WrapMsg(err, "etcd put err")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,10 +17,14 @@ type RespTarget struct {
|
|||||||
Labels map[string]string `json:"labels"`
|
Labels map[string]string `json:"labels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildDiscoveryKey(name string) string {
|
func BuildDiscoveryKeyPrefix(name string) string {
|
||||||
return fmt.Sprintf("%s/%s/%s", "openim", "prometheus_discovery", name)
|
return fmt.Sprintf("%s/%s/%s", "openim", "prometheus_discovery", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BuildDiscoveryKey(name string, index int) string {
|
||||||
|
return fmt.Sprintf("%s/%s/%s/%d", "openim", "prometheus_discovery", name, index)
|
||||||
|
}
|
||||||
|
|
||||||
func BuildDefaultTarget(host string, ip int) Target {
|
func BuildDefaultTarget(host string, ip int) Target {
|
||||||
return Target{
|
return Target{
|
||||||
Target: fmt.Sprintf("%s:%d", host, ip),
|
Target: fmt.Sprintf("%s:%d", host, ip),
|
||||||
|
|||||||
@ -166,7 +166,7 @@ func Start[T any](ctx context.Context, discovery *conf.Discovery, prometheusConf
|
|||||||
|
|
||||||
etcdClient := client.(*etcd.SvcDiscoveryRegistryImpl).GetClient()
|
etcdClient := client.(*etcd.SvcDiscoveryRegistryImpl).GetClient()
|
||||||
|
|
||||||
_, err = etcdClient.Put(ctx, prommetrics.BuildDiscoveryKey(rpcRegisterName), jsonutil.StructToJsonString(prommetrics.BuildDefaultTarget(registerIP, prometheusPort)))
|
_, err = etcdClient.Put(ctx, prommetrics.BuildDiscoveryKey(rpcRegisterName, index), jsonutil.StructToJsonString(prommetrics.BuildDefaultTarget(registerIP, prometheusPort)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errs.WrapMsg(err, "etcd put err")
|
return errs.WrapMsg(err, "etcd put err")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user