Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/registry/nacos/v2: panic: duplicate metrics collector registration attempted #3680

Open
LanceAdd opened this issue Jul 12, 2024 · 7 comments · May be fixed by #3729
Open

contrib/registry/nacos/v2: panic: duplicate metrics collector registration attempted #3680

LanceAdd opened this issue Jul 12, 2024 · 7 comments · May be fixed by #3729
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@LanceAdd
Copy link

Go version

go version go1.22.4 darwin/amd64

GoFrame version

2.7.2

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

load remote config from nacos

serverConfig := constant.ServerConfig{
		IpAddr: "172.16.23.99",
		Port:   8848,
	}
	clientConfig := constant.ClientConfig{
		CacheDir:    "/tmp/nacos",
		LogDir:      "/tmp/nacos",
		NamespaceId: "c1e15245-03c1-4cba-9c40-ddc59e4d4167",
	}
	configParam := vo.ConfigParam{
		DataId: "sso.yml",
		Group:  "test",
	}

	adapter, err := nacos.New(ctx, nacos.Config{
		ServerConfigs: []constant.ServerConfig{serverConfig},
		ClientConfig:  clientConfig,
		ConfigParam:   configParam,
	})
	if err != nil {
		g.Log().Fatalf(ctx, `%+v`, err)
	}
	g.Cfg().SetAdapter(adapter)

Register with Nacos

	gsvc.SetRegistry(nacos.New("172.16.23.99:8848",
		constant.WithNamespaceId("c1e15245-03c1-4cba-9c40-ddc59e4d4167"),
		constant.WithUsername("nacos"),
		constant.WithPassword("nacos"),
	).SetGroupName("test"))

When I get the configuration file from Nacos and then register the service with Nacos, I get the following error

panic: duplicate metrics collector registration attempted

goroutine 1 [running]:
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(0xc0000b9db0, {0xc0004a0300, 0x2, 0x2})
        /Users/shanyujie/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/registry.go:403 +0x116
github.com/prometheus/client_golang/prometheus.MustRegister({0xc0004a0300, 0x2, 0x2})
        /Users/shanyujie/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/registry.go:178 +0x3f
github.com/nacos-group/nacos-sdk-go/v2/common/monitor.init.0()
        /Users/shanyujie/go/pkg/mod/github.com/nacos-group/nacos-sdk-go/v2@v2.2.5/common/monitor/monitor.go:34 +0xc5
Exiting.

sso.yml

server:
  address: "0.0.0.0:50001"
  openapiPath: "/api.json"
  swaggerPath: "/doc.html"
  accessLogEnabled: true
  errorLogEnabled: true
  pprofEnabled: false
  logPath: "./log"
  dumpRouterMap: true

What did you see happen?

panic: duplicate metrics collector registration attempted

goroutine 1 [running]:
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(0xc0000b9db0, {0xc0004a0300, 0x2, 0x2})
        /Users/shanyujie/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/registry.go:403 +0x116
github.com/prometheus/client_golang/prometheus.MustRegister({0xc0004a0300, 0x2, 0x2})
        /Users/shanyujie/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/registry.go:178 +0x3f
github.com/nacos-group/nacos-sdk-go/v2/common/monitor.init.0()
        /Users/shanyujie/go/pkg/mod/github.com/nacos-group/nacos-sdk-go/v2@v2.2.5/common/monitor/monitor.go:34 +0xc5
Exiting.

What did you expect to see?

It's okay to just register the service or just get the configuration file, but it can be problematic when both are present

@LanceAdd LanceAdd added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jul 12, 2024
@LanceAdd
Copy link
Author

Why is the nacos sdk referenced differently in "github.com/gogf/gf/contrib/config/nacos/v2" and "github.com/gogf/gf/contrib/registry/nacos/v2"

github.com/gogf/gf/contrib/registry/nacos/v2

github.com/joy999/nacos-sdk-go

github.com/gogf/gf/contrib/config/nacos/v2

github.com/nacos-group/nacos-sdk-go/v2

This leads to duplicate registrations when obtaining remote configuration files and registering services

@wu-weichao
Copy link

Have you solved this problem?

@LanceAdd
Copy link
Author

LanceAdd commented Aug 12, 2024

Have you solved this problem?

I used github.com/nacos-group/nacos-sdk-go/v2 instead of github.com/joy999/nacos-sdk-go, and then combined it with the content of github.com/gogf/gf/contrib/registry/nacos/v2 to write my own library https://github.com/LanceAdd/nacos-gf
I hope it can help you

@LanceAdd LanceAdd reopened this Aug 12, 2024
@wu-weichao
Copy link

Have you solved this problem?

I used github.com/nacos-group/nacos-sdk-go/v2 instead of github.com/joy999/nacos-sdk-go, and then combined it with the content of github.com/gogf/gf/contrib/registry/nacos/v2 to write my own library https://github.com/LanceAdd/nacos-gf I hope it can help you

Thanks

@wilsonliu123
Copy link

Same problem

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Same problem

@LanceAdd
Copy link
Author

Same problem

The reason for this problem is that nacos-sdk-go is used in config and registry, github.com/nacos-group/nacos-sdk-go/v2 is used in config, but github.com/joy999/nacos-sdk-go is used in registry, which causes multiple initializations of monitor.
If you need to, you can use this https://github.com/LanceAdd/nacos-gf temporarily

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
4 participants