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

Question on how to use the library #56

Open
NancyXie2022 opened this issue Dec 8, 2022 · 7 comments
Open

Question on how to use the library #56

NancyXie2022 opened this issue Dec 8, 2022 · 7 comments

Comments

@NancyXie2022
Copy link

Hi,
Our service is a GRPC service, and I am trying to use this library with prometheus to manage the metrics, I have tried to setup my code following the usage example, though it doesn't work, could you give me some suggestions on this?
My grpc server looks like:

var server: Server = null
var httpServer: HTTPServer = null
val pushRegistry = new CollectorRegistry()

def start(): Unit = {
val serverBuilder = if (config.auth.enableTls) {
val certPath = Paths.get(config.auth.serverCertFolder, config.auth.serverCertFilename).toString
val keyPath = Paths.get(config.auth.serverCertFolder, config.auth.serverCertKeyFilename).toString
if (config.auth.enableClientAuth) getSecureServerWithClientAuthBuilder(MuFnServer.port, certPath, keyPath, config.auth.trustStorePath)
else getSecureServerBuilder(MuFnServer.port, certPath, keyPath, config.auth.trustStorePath)
} else getInsecureServerBuilder(MuFnServer.port)

httpServer = new HTTPServer(9090)
server = serverBuilder
  .addService(MuFnServiceGrpc.bindService(new MuFnImpl(config, openTelemetry), executionContext))
  .addService(ProtoReflectionService.newInstance())
  .intercept(MonitoringServerInterceptor.create(Configuration.cheapMetricsOnly()
    .withCollectorRegistry(pushRegistry)))
  .build
  .start
sys.addShutdownHook {
  logger.error("*** shutting down gRPC server since JVM is shutting down")
  self.stop()
  logger.error("*** server shut down")
}

And my prometheus setup in pod-spec is as below:

template:
metadata:
annotations:
"prometheus.io/scrape": "true"
"prometheus.io/port": "8888"
"prometheus.io/path": "/metrics"
labels:
app.kubernetes.io/name: mufn-service
ginku.opentelemetry.onboard: "true"

@dinowernli
Copy link
Member

Hi @NancyXie2022 , I'm having trouble following what you mean by "doesn't work". Could you clarify what behavior you're expecting to see, and what you're seeing instead?

@NancyXie2022
Copy link
Author

hmm, I don't see metric get emitted, that what I mean it doesn't work.
I create a httpServer using port 9090,
I try to do this:
curl -v http://localhost:9090/metrics
there is no result though

curl -v http://localhost:9090/metrics

  • About to connect() to localhost port 9090 (#0)
  • Trying ::1...
  • Connected to localhost (::1) port 9090 (#0)

GET /metrics HTTP/1.1
User-Agent: curl/7.29.0
Host: localhost:9090
Accept: /

< HTTP/1.1 200 OK
< Date: Thu, 08 Dec 2022 21:54:13 GMT
< Transfer-encoding: chunked
< Content-type: text/plain; version=0.0.4; charset=utf-8
<

  • Connection #0 to host localhost left intact

@NancyXie2022
Copy link
Author

@dinowernli thanks for your quick response

@NancyXie2022
Copy link
Author

And also do you think my code is right or do you see anything wrong with it?

@dinowernli
Copy link
Member

Looking at your code, I would expect the RPC server to correctly emit metrics into your pushRegistry object. I don't see you using it anywhere for serving via your metrics endpoint though. So I'm guessing you've got a missing step there to wire that up.

@NancyXie2022
Copy link
Author

Hmm, do you mind how to make it serving via your metrics endpoint? Any example on that?

@dinowernli
Copy link
Member

Assuming your HTTPServer is the one described here [1], then I think the missing piece might be to actually pass in your pushRegistry by calling .withRegistry(pushRegistry), see [2].

[1] https://github.com/prometheus/client_java/tree/7cf0cc9dc58981198be106a27333653bed7bf688#http
[2] https://github.com/prometheus/client_java/blob/7cf0cc9dc58981198be106a27333653bed7bf688/simpleclient_httpserver/src/main/java/io/prometheus/client/exporter/HTTPServer.java#L309

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

No branches or pull requests

2 participants