Coder Social home page Coder Social logo

go-grpc-middleware/providers/openmetrics/v2 v2.0.0-rc.3 dependency of go-grpc-middleware/v2 v2.0.1 broken about go-grpc-middleware HOT 8 CLOSED

RogerioWagner avatar RogerioWagner commented on June 14, 2024
go-grpc-middleware/providers/openmetrics/v2 v2.0.0-rc.3 dependency of go-grpc-middleware/v2 v2.0.1 broken

from go-grpc-middleware.

Comments (8)

johanbrandhorst avatar johanbrandhorst commented on June 14, 2024

I just pushed https://github.com/grpc-ecosystem/go-grpc-middleware/releases/tag/providers%2Fopenmetrics%2Fv2.0.1, does that work?

from go-grpc-middleware.

RogerioWagner avatar RogerioWagner commented on June 14, 2024

@johanbrandhorst Thank You, very much for your help.

I think the package is not available yet, go get failed and at pkg.go.dev still list rc3 as the latest package.

go get go-grpc-middleware-providers-openmetrics-v2.0.1                                                                                          ─╯

go: unrecognized import path "go-grpc-middleware-providers-openmetrics-v2.0.1": https fetch: Get "https://go-grpc-middleware-providers-openmetrics-v2.0.1/?go-get=1": dial tcp: lookup go-grpc-middleware-providers-openmetrics-v2.0.1: no such host

from go-grpc-middleware.

johanbrandhorst avatar johanbrandhorst commented on June 14, 2024

Oops, looks like we removed that folder before tagging v2, I can't see it on the main branch. @bwplotka what happened to openmetrics?

from go-grpc-middleware.

bwplotka avatar bwplotka commented on June 14, 2024

Hey, it got renamed to Prometheus provider: https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/providers/prometheus , calling it open metrics was a mistake there, sorry.

Just replace it with a prometheus provider module should work for you (it has a different version than the main module, see https://github.com/grpc-ecosystem/go-grpc-middleware/releases/tag/providers%2Fprometheus%2Fv1.0.0).

from go-grpc-middleware.

bwplotka avatar bwplotka commented on June 14, 2024

Get and reference the prometheus provider module via go get github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus

from go-grpc-middleware.

RogerioWagner avatar RogerioWagner commented on June 14, 2024

@johanbrandhorst and @bwplotka Thank you very much Guys!

I've changed to prometheus package and referenced v2.0.1 of main package, it build correctly and worked with slog.

from go-grpc-middleware.

bwplotka avatar bwplotka commented on June 14, 2024

Epic! Do you mind sharing your slog integration? How your integrated roughly?

from go-grpc-middleware.

RogerioWagner avatar RogerioWagner commented on June 14, 2024

Sure, I have no credit on the implementation, basically I just followed the other logging interceptors, I may tweak it a little bit later, but for now I'm prioritizing the simplicity.

I've removed some lines to make it clear.

InterceptorLogger implementation

import (
	"context"
	"fmt"
	"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
	log "log/slog"
)

// InterceptorLogger function
func InterceptorLogger(l *log.Logger) logging.Logger {
	return logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) {
		l.Log(ctx, log.Level(lvl), msg, fields...)
	})
}

Logging Options

		loggingOpts := []logging.Option{
			logging.WithLogOnEvents(logging.StartCall, logging.FinishCall, 
                                      logging.PayloadReceived, logging.PayloadSent),

		}

Added it to the Chain of Responsibility, log.Default returns the slog singleton previously configured

		// Create gRPC server with slog, prometheus, and panic recovery middleware
		srv := grpc.NewServer(
			grpc.ChainUnaryInterceptor(
				logging.UnaryServerInterceptor(InterceptorLogger(log.Default()), loggingOpts...),
				promGrpcServerMetrics.UnaryServerInterceptor(),
				recovery.UnaryServerInterceptor(),
			),
			grpc.ChainStreamInterceptor(
				logging.StreamServerInterceptor(InterceptorLogger(log.Default()), loggingOpts...),
				promGrpcServerMetrics.StreamServerInterceptor(),
				recovery.StreamServerInterceptor(),
			),
		)

A call to the Unary rpc method produced the bellow lines (non sensitive data)

{"time":"2023-12-05T16:16:13.460813-03:00","level":"INFO","msg":"started call","protocol":"grpc","grpc.component":"server","grpc.service":"nocloud.authentication.oauth.v1.OpenIdConfiguration","grpc.method":"discovery","grpc.method_type":"unary","peer.address":"[::1]:62072","grpc.start_time":"2023-12-05T16:16:13-03:00","grpc.time_ms":"0.027"}
{"time":"2023-12-05T16:16:13.460865-03:00","level":"INFO","msg":"request received","protocol":"grpc","grpc.component":"server","grpc.service":"nocloud.authentication.oauth.v1.OpenIdConfiguration","grpc.method":"discovery","grpc.method_type":"unary","peer.address":"[::1]:62072","grpc.start_time":"2023-12-05T16:16:13-03:00","grpc.recv.duration":"27.708µs","grpc.request.content":{}}
{"time":"2023-12-05T16:16:13.461066-03:00","level":"INFO","msg":"response sent","protocol":"grpc","grpc.component":"server","grpc.service":"nocloud.authentication.oauth.v1.OpenIdConfiguration","grpc.method":"discovery","grpc.method_type":"unary","peer.address":"[::1]:62072","grpc.start_time":"2023-12-05T16:16:13-03:00","grpc.send.duration":"319.166µs","grpc.response.content":{"jwksUri":"http://localhost:8080/.well-known/openid-configuration/jwks"}}
{"time":"2023-12-05T16:16:13.461301-03:00","level":"INFO","msg":"finished call","protocol":"grpc","grpc.component":"server","grpc.service":"nocloud.authentication.oauth.v1.OpenIdConfiguration","grpc.method":"discovery","grpc.method_type":"unary","peer.address":"[::1]:62072","grpc.start_time":"2023-12-05T16:16:13-03:00","grpc.code":"OK","grpc.time_ms":"0.554"}

from go-grpc-middleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.