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));
}
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));
}
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));
}
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);
}
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();
}
Aggregations