grpc-ecosystem / go-grpc-middleware

Golang gRPC Middlewares: interceptor chaining, auth, logging, retries and more.
Apache License 2.0
6.29k stars 693 forks source link

Support for namespace in grpc prometheus counter and histogram metrics #718

Closed hyungi closed 5 months ago

hyungi commented 5 months ago

Changes

Introduction of apis: WithNamespace() and WithHistogramNamespace()

Verification

Test cases are newly added in client side and server side.

$ cd providers/prometheus
$ go test -v -race ./...
=== RUN   TestClientInterceptorSuite
=== RUN   TestClientInterceptorSuite/TestStartedStreamingIncrementsStarted
=== RUN   TestClientInterceptorSuite/TestStreamingIncrementsMetrics
=== RUN   TestClientInterceptorSuite/TestUnaryIncrementsMetrics
=== RUN   TestClientInterceptorSuite/TestWithNamespace
=== RUN   TestClientInterceptorSuite/TestWithSubsystem
=== NAME  TestClientInterceptorSuite
    interceptor_suite.go:155: stopped grpc.Server at: 127.0.0.1:46203
--- PASS: TestClientInterceptorSuite (0.31s)
    --- PASS: TestClientInterceptorSuite/TestStartedStreamingIncrementsStarted (0.00s)
    --- PASS: TestClientInterceptorSuite/TestStreamingIncrementsMetrics (0.00s)
    --- PASS: TestClientInterceptorSuite/TestUnaryIncrementsMetrics (0.00s)
    --- PASS: TestClientInterceptorSuite/TestWithNamespace (0.00s)
    --- PASS: TestClientInterceptorSuite/TestWithSubsystem (0.00s)
=== RUN   TestServerInterceptorSuite
=== RUN   TestServerInterceptorSuite/TestContextCancelledTreatedAsStatus
=== RUN   TestServerInterceptorSuite/TestRegisterPresetsStuff
=== RUN   TestServerInterceptorSuite/TestStartedStreamingIncrementsStarted
=== RUN   TestServerInterceptorSuite/TestStreamingIncrementsMetrics
=== RUN   TestServerInterceptorSuite/TestUnaryIncrementsMetrics
=== RUN   TestServerInterceptorSuite/TestWithSubsystem
=== NAME  TestServerInterceptorSuite
    interceptor_suite.go:155: stopped grpc.Server at: 127.0.0.1:36147
--- PASS: TestServerInterceptorSuite (0.66s)
    --- PASS: TestServerInterceptorSuite/TestContextCancelledTreatedAsStatus (0.10s)
    --- PASS: TestServerInterceptorSuite/TestRegisterPresetsStuff (0.02s)
    --- PASS: TestServerInterceptorSuite/TestStartedStreamingIncrementsStarted (0.20s)
    --- PASS: TestServerInterceptorSuite/TestStreamingIncrementsMetrics (0.10s)
    --- PASS: TestServerInterceptorSuite/TestUnaryIncrementsMetrics (0.00s)
    --- PASS: TestServerInterceptorSuite/TestWithSubsystem (0.00s)
PASS
ok      github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus       1.982s
hyungi commented 5 months ago

I've updated comment as you mentioned. Thanks @johanbrandhorst :-)