Search in sources :

Example 26 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcMetricsInterceptorIT method shouldUseSimpleTimerMetric.

@Test
public void shouldUseSimpleTimerMetric() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("barSimplyTimed", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("barSimplyTimed");
    GrpcMetrics metrics = GrpcMetrics.simplyTimed();
    ServerCall<String, String> call = call(metrics, methodDescriptor);
    call.close(Status.OK, new Metadata());
    SimpleTimer appSimpleTimer = appRegistry.get().simpleTimer("Foo.barSimplyTimed");
    assertVendorMetrics();
    assertThat(appSimpleTimer.getCount(), is(1L));
}
Also used : SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Metadata(io.grpc.Metadata) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) Test(org.junit.jupiter.api.Test)

Example 27 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcMetricsInterceptorIT method shouldUseHistogramMetric.

@Test
public void shouldUseHistogramMetric() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("barHistogram", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("barHistogram");
    GrpcMetrics metrics = GrpcMetrics.histogram();
    ServerCall<String, String> call = call(metrics, methodDescriptor);
    call.close(Status.OK, new Metadata());
    Histogram appHistogram = appRegistry.get().histogram("Foo.barHistogram");
    assertVendorMetrics();
    assertThat(appHistogram.getCount(), is(1L));
}
Also used : Histogram(org.eclipse.microprofile.metrics.Histogram) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Metadata(io.grpc.Metadata) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) Test(org.junit.jupiter.api.Test)

Example 28 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcMetricsInterceptorIT method shouldUseNameFunction.

@Test
public void shouldUseNameFunction() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("barUnits", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("barUnits");
    GrpcMetrics metrics = GrpcMetrics.counted().nameFunction((svc, method, type) -> "overridden");
    ServerCall<String, String> call = call(metrics, methodDescriptor);
    call.close(Status.OK, new Metadata());
    Counter appCounter = appRegistry.get().counter("overridden");
    assertVendorMetrics();
    assertThat(appCounter.getCount(), is(1L));
}
Also used : Counter(org.eclipse.microprofile.metrics.Counter) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Metadata(io.grpc.Metadata) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) Test(org.junit.jupiter.api.Test)

Example 29 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcMetrics method interceptCall.

@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
    MetricsRules rules = Context.keyWithDefault(KEY_STRING, metricRule).get();
    MetricType type = rules.type();
    String fullMethodName = call.getMethodDescriptor().getFullMethodName();
    String methodName = GrpcHelper.extractMethodName(fullMethodName);
    ServiceDescriptor service = ServiceDescriptor.SERVICE_DESCRIPTOR_KEY.get();
    ServerCall<ReqT, RespT> serverCall;
    switch(type) {
        case COUNTER:
            serverCall = new CountedServerCall<>(APP_REGISTRY.get().counter(rules.metadata(service, methodName), rules.toTags()), call);
            break;
        case METERED:
            serverCall = new MeteredServerCall<>(APP_REGISTRY.get().meter(rules.metadata(service, methodName), rules.toTags()), call);
            break;
        case HISTOGRAM:
            serverCall = new HistogramServerCall<>(APP_REGISTRY.get().histogram(rules.metadata(service, methodName), rules.toTags()), call);
            break;
        case TIMER:
            serverCall = new TimedServerCall<>(APP_REGISTRY.get().timer(rules.metadata(service, methodName), rules.toTags()), call);
            break;
        case SIMPLE_TIMER:
            serverCall = new SimplyTimedServerCall<>(APP_REGISTRY.get().simpleTimer(rules.metadata(service, methodName), rules.toTags()), call);
            break;
        case CONCURRENT_GAUGE:
            serverCall = new ConcurrentGaugeServerCall<>(APP_REGISTRY.get().concurrentGauge(rules.metadata(service, methodName), rules.toTags()), call);
            break;
        case GAUGE:
        case INVALID:
        default:
            serverCall = call;
    }
    serverCall = new MeteredServerCall<>(VENDOR_REGISTRY.get().meter(GRPC_METER), serverCall);
    return next.startCall(serverCall, headers);
}
Also used : MetricType(org.eclipse.microprofile.metrics.MetricType) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor)

Example 30 with ServiceDescriptor

use of io.helidon.grpc.server.ServiceDescriptor in project helidon by oracle.

the class GrpcServiceBuilder method build.

/**
 * Create a {@link ServiceDescriptor.Builder} introspected class.
 *
 * @return a {@link ServiceDescriptor.Builder} for the introspected class.
 */
@Override
public ServiceDescriptor build() {
    checkForNonPublicMethodIssues();
    Class<?> annotatedServiceClass = annotatedServiceClass();
    AnnotatedMethodList methodList = AnnotatedMethodList.create(annotatedServiceClass);
    String name = determineServiceName(annotatedServiceClass);
    ServiceDescriptor.Builder builder = ServiceDescriptor.builder(serviceClass(), name).marshallerSupplier(getMarshallerSupplier());
    addServiceMethods(builder, methodList, beanManager);
    configureServiceInterceptors(builder, beanManager);
    Class<?> serviceClass = serviceClass();
    Class<?> annotatedClass = annotatedServiceClass();
    HelidonServiceLoader.create(ServiceLoader.load(AnnotatedServiceConfigurer.class)).forEach(configurer -> configurer.accept(serviceClass, annotatedClass, builder));
    return builder.build();
}
Also used : AnnotatedMethodList(io.helidon.microprofile.grpc.core.AnnotatedMethodList) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor)

Aggregations

ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)45 Test (org.junit.jupiter.api.Test)37 ServerInterceptor (io.grpc.ServerInterceptor)17 MethodDescriptor (io.helidon.grpc.server.MethodDescriptor)14 Metadata (io.grpc.Metadata)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 BeanManager (jakarta.enterprise.inject.spi.BeanManager)8 MetricID (org.eclipse.microprofile.metrics.MetricID)7 Counter (org.eclipse.microprofile.metrics.Counter)6 LogConfig (io.helidon.common.LogConfig)4 GrpcRouting (io.helidon.grpc.server.GrpcRouting)4 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)4 Security (io.helidon.security.Security)4 Config (io.helidon.config.Config)3 GrpcServer (io.helidon.grpc.server.GrpcServer)3 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 Channel (io.grpc.Channel)2 ServerCall (io.grpc.ServerCall)2 ServerCallHandler (io.grpc.ServerCallHandler)2