Armeria: `GrpcMeterIdPrefixFunction`?

Created on 2 Jun 2020  路  10Comments  路  Source: line/armeria

Originally suggested by @okue

It'd be nice to have a dedicated MeterIdPrefixFunction implementation for gRPC, so that the tag for grpc-status is added automatically.

new feature

All 10 comments

To make MeterIdPrefixFunction easier to customize,
how about adding some functions to MeterIdPrefixFunction?

static MeterIdPrefixFunction ofDefault(
    String name,
    BiConsumer<MeterRegistry, ? super RequestOnlyLog> consumer
) {
    ...
}

or

default MeterIdPrefixFunction andThen(
    Function3<MeterRegistry, ? super RequestOnlyLog, MeterIdPrefix, MeterIdPrefix> consumer
) {
    ...
}

That's a good idea. I like the latter. What do you think, @line/dx?

I also prefer the andThen version. But Java does not have Function3 or triple function. We might need a customizer interface.

Now, we can set grpc-status to MeterIdPrefix easily using MeterIdPrefixFunction#andThen(MeterIdPrefixFunctionCustomizer).

BTW, is it better to offer GrpcMeterIdPrefixFunction?
If so, should GrpcMeterIdPrefixFunction use andThen, or optimize something..?

That's a good question. I think it will be useful to provide one out of the box. It'd be nice if we have an optimized version, but we will have to refactor a little bit to de-duplicate the common logic from the default prefix function. Alternatively, we could duplicate a little bit and just write some tight test cases.

I prefer GrpcMeterIdPrefixFunction because grpc-status can be gotten from:

  • headers if a response body is empty
  • trailers if a response body is not empty and the protocol is normal gRPC
  • last of bodies if a response body is not empty and the protocol is gRPC-Web

How could we get the grpc-status trailer from a gRPC-Web response?

Probably worth getting this done before 1.0 to solve the gRPC-Web trailer handling problem..

Let me work on this after finishing #2911

When using gRPC with armeria-spring-boot, all services are decorated with MeterIdPrefixFunction.ofDefault.
I'd be happy if GrpcMeterIdPrefixFunction is used for gRPC services.

https://github.com/line/armeria/blob/armeria-1.0.0/spring/boot2-autoconfigure/src/main/java/com/linecorp/armeria/internal/spring/ArmeriaConfigurationUtil.java#L131-L132

Was this page helpful?
0 / 5 - 0 ratings