mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-19 12:47:06 +08:00
resolve the prometheus discovery issue of multiple instances with same service
This commit is contained in:
parent
47e916aebe
commit
48928d7d84
@ -109,7 +109,7 @@ func Start(ctx context.Context, index int, config *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, registerIP, prometheusPort), 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))
|
||||||
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"))
|
||||||
|
|||||||
@ -194,7 +194,7 @@ func (m *MsgTransfer) Start(index int, config *Config, client discovery.SvcDisco
|
|||||||
|
|
||||||
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, registerIP, prometheusPort), 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,8 +17,12 @@ 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, host string, port int) string {
|
||||||
|
return fmt.Sprintf("%s/%s/%s/%s:%d", "openim", "prometheus_discovery", name, host, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildDefaultTarget(host string, ip int) Target {
|
func BuildDefaultTarget(host string, ip int) Target {
|
||||||
|
|||||||
@ -128,7 +128,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, registerIP, prometheusPort), 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