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

Middlewares not working #447

Open
iseekyouu opened this issue Sep 18, 2023 · 2 comments
Open

Middlewares not working #447

iseekyouu opened this issue Sep 18, 2023 · 2 comments

Comments

@iseekyouu
Copy link

trying to implement prometheus-middlewares and got nothing

//server

import { createServer } from 'nice-grpc';
import { prometheusServerMiddleware } from 'nice-grpc-prometheus';
...
    this.grpcServer = createServer(options);
    this.grpcServer.use(prometheusServerMiddleware());

  start(opts: { port: number } = { port: 50501 }) {
    this.grpcServer.listen(`0.0.0.0:${opts.port}`);
  }

// metrics endpoint

import { register as globalRegistry, Registry } from 'prom-client';
import { registry as niceGrpcRegistry } from 'nice-grpc-prometheus';
...
  async function promMw(app: FastifyInstance) {
    app.get(
      '/',
      async function (req, res) {
        const mergedRegistry = Registry.merge([globalRegistry, niceGrpcRegistry]);
        res.code(200).send(await mergedRegistry.metrics());
      });
  }

  fastify.register(promMw, { prefix: 'api/v1/prom' });

after that i called my rpc with BloomRPC and got nothing in metrics

# HELP grpc_server_started_total Total number of RPCs started on the server.
# TYPE grpc_server_started_total counter

# HELP grpc_server_handled_total Total number of RPCs completed on the server, regardless of success or failure.
# TYPE grpc_server_handled_total counter

# HELP grpc_server_msg_received_total Total number of RPC stream messages received by the server.
# TYPE grpc_server_msg_received_total counter

# HELP grpc_server_msg_sent_total Total number of gRPC stream messages sent by the server.
# TYPE grpc_server_msg_sent_total counter

# HELP grpc_server_handling_seconds Histogram of response latency (seconds) of gRPC that had been application-level handled by the server.
# TYPE grpc_server_handling_seconds histogram

# HELP grpc_client_started_total Total number of RPCs started on the client.
# TYPE grpc_client_started_total counter

# HELP grpc_client_handled_total Total number of RPCs completed on the client, regardless of success or failure.
# TYPE grpc_client_handled_total counter

# HELP grpc_client_msg_received_total Total number of RPC stream messages received by the client.
# TYPE grpc_client_msg_received_total counter

# HELP grpc_client_msg_sent_total Total number of gRPC stream messages sent by the client.
# TYPE grpc_client_msg_sent_total counter

# HELP grpc_client_handling_seconds Histogram of response latency (seconds) of the gRPC until it is finished by the application.
# TYPE grpc_client_handling_seconds histogram
@iseekyouu
Copy link
Author

Also i tried get yours test middleware

export function createTestServerMiddleware<Ext>(
  contextExt: Ext,
  actions: any[],
  actionTypePrefix = '',
): ServerMiddleware<Ext> {

and put it into my server

    this.grpcServer.use(createTestServerMiddleware(
      { test1: 'test-value-1' },
      actions,
      'middleware1-',
    ));

after that done some calls throught BloomRPC and actions array still empty

@aikoven
Copy link
Contributor

aikoven commented Sep 18, 2023

The server.use method does not mutate the server instance, but creates a new instance with the middleware attached.

Try to change this:

this.grpcServer.use(prometheusServerMiddleware());

to this:

this.grpcServer = this.grpcServer.use(prometheusServerMiddleware());

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