fix: prometheus

This commit is contained in:
icey-yu
2025-09-26 15:27:46 +08:00
parent 15d7129c46
commit 909f3a4a24
5 changed files with 9 additions and 5 deletions
+5 -1
View File
@@ -17,10 +17,14 @@ type RespTarget struct {
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)
}
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 {
return Target{
Target: fmt.Sprintf("%s:%d", host, ip),
+1 -1
View File
@@ -166,7 +166,7 @@ func Start[T any](ctx context.Context, discovery *conf.Discovery, prometheusConf
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 {
return errs.WrapMsg(err, "etcd put err")
}