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

Can I create custom label to metric by GrpcMonitoringInterceptor? #25

Open
kkpolak opened this issue Nov 19, 2020 · 0 comments
Open

Can I create custom label to metric by GrpcMonitoringInterceptor? #25

kkpolak opened this issue Nov 19, 2020 · 0 comments

Comments

@kkpolak
Copy link

kkpolak commented Nov 19, 2020

Hi @dinowernli and other creators.
I want to add custom label "errorCode" to my metric. Is it even possible?
I have such Configuration of GrpcMonitoringInterceptor:

@GRpcGlobalInterceptor
public class GrpcMonitoringInterceptor implements ServerInterceptor {

  private final MonitoringServerInterceptor interceptor;

  public GrpcMonitoringInterceptor(CollectorRegistry collectorRegistry) {
    Configuration configuration = Configuration
        .cheapMetricsOnly().withCollectorRegistry(collectorRegistry);
    interceptor = MonitoringServerInterceptor.create(configuration);
  }

  @Override
  public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
      ServerCallHandler<ReqT, RespT> next) {
    return interceptor.interceptCall(call, headers, next);
  }
}

I have such grpc_server_handled_total metric:

expr: |
              ((sum by (job, namespace, grpc_method) ((grpc_server_handled_total{job=~"wallet.*",code!="OK"}) - (grpc_server_handled_total{job=~"wallet.*",code!="OK"}  offset 5m))) / sum by (job, namespace, grpc_method) ((grpc_server_handled_total{job=~"wallet.*"}) - (grpc_server_handled_total{job=~"wallet.*"} offset 5m)) * 100) > 10 and (sum by (job, namespace, grpc_method) ((grpc_server_handled_total{job=~"wallet.*"}) - (grpc_server_handled_total{job=~"wallet.*"} offset 5m)) > 20)

I want to change the metric to this:

((sum by (job, namespace, grpc_method) ((grpc_server_handled_total{job=~"wallet.*",code!="OK",errorCode!="IP_BLOCKED"}) - (grpc_server_handled_total{job=~"wallet.*",code!="OK",errorCode!="IP_BLOCKED"}  offset 5m))) / sum by (job, namespace, grpc_method) ((grpc_server_handled_total{job=~"wallet.*"}) - (grpc_server_handled_total{job=~"wallet.*"} offset 5m)) * 100) > 10 and (sum by (job, namespace, grpc_method) ((grpc_server_handled_total{job=~"wallet.*"}) - (grpc_server_handled_total{job=~"wallet.*"} offset 5m)) > 20)

I tried to make some changes with collectorRegistry when intercepotr is creating, but it doesn't work.

  public GrpcMonitoringInterceptor(CollectorRegistry collectorRegistry) {
    Counter tmp = Counter.build()
        .namespace("grpc")
        .subsystem("server")
        .name("handled_total")
        .labelNames("grpc_type", "grpc_service", "grpc_method", "code", "errorCode")
        .help("Total number of RPCs completed on the server, regardless of success or failure.").register();
    collectorRegistry.register(tmp);
  public GrpcMonitoringInterceptor(CollectorRegistry collectorRegistry) {
    Counter tmp = Counter.build()
        .namespace("grpc")
        .subsystem("server")
        .name("handled_total")
        .labelNames("grpc_type", "grpc_service", "grpc_method", "code", "errorCode")
        .help("Total number of RPCs completed on the server, regardless of success or failure.").register();
    collectorRegistry.register(tmp);

    Configuration configuration = Configuration
        .cheapMetricsOnly().withCollectorRegistry(collectorRegistry);
    interceptor = MonitoringServerInterceptor.create(configuration);
  }
    Configuration configuration = Configuration
        .cheapMetricsOnly().withCollectorRegistry(collectorRegistry);
    interceptor = MonitoringServerInterceptor.create(configuration);
  }
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

1 participant