Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Document how to register Server or change init() to register the same way #73

Open
cstockton opened this issue Mar 29, 2019 · 1 comment

Comments

@cstockton
Copy link

I needed to change the namespace so I checked here first and found #29. It took a few minutes to figure out because all the metrics are private on *Server and the init() registers them explicitly, and my grep found no other calls to MustRegister for a *Server type. I realized after digging into *Server that it was itself a collector so registering that worked.

To give this hint to users I propose changing:

func init() {
	prom.MustRegister(DefaultServerMetrics.serverStartedCounter)
	prom.MustRegister(DefaultServerMetrics.serverHandledCounter)
	prom.MustRegister(DefaultServerMetrics.serverStreamMsgReceived)
	prom.MustRegister(DefaultServerMetrics.serverStreamMsgSent)
}

To:

func init() {
	prom.MustRegister(DefaultServerMetrics)
}

Or adding a basic custom namespace example in the README if there is a technical reason the above would be incorrect:

myCustomMetrics := grpcprom.NewServerMetrics(
  grpcprom.CounterOption(func(o *prometheus.CounterOpts) {
    o.Namespace = "my_custom_namespace"
  }),
)
prom.MustRegister(myCustomMetrics)
srv := grpc.NewServer(...)
myCustomMetrics.InitializeMetrics(srv)
@brancz
Copy link
Collaborator

brancz commented Apr 1, 2019

I think we should generally recommend not to use the globals/init, so the latter sounds good to me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants