Search in sources :

Example 1 with MethodDescriptor

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

the class GrpcMetricsInterceptorIT method shouldApplyTags.

@Test
public void shouldApplyTags() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("barTags", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("barTags");
    Map<String, String> tags = Map.of("one", "t1", "two", "t2");
    GrpcMetrics metrics = GrpcMetrics.counted().tags(tags);
    ServerCall<String, String> call = call(metrics, methodDescriptor);
    call.close(Status.OK, new Metadata());
    Map<MetricID, Metric> matchingMetrics = appRegistry.get().getMetrics().entrySet().stream().filter(entry -> entry.getKey().getName().equals("Foo.barTags")).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    assertThat(matchingMetrics.size(), not(0));
    Map.Entry<MetricID, Metric> match = matchingMetrics.entrySet().stream().findFirst().orElse(null);
    assertVendorMetrics();
    Map<String, String> expected = new HashMap<>();
    expected.put("one", "t1");
    expected.put("two", "t2");
    /*
         * We expect the tags to be on the ID in the version-neutral (and 2.0)
         * metrics programming model.
         */
    assertThat(match.getKey().getTags(), is(expected));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Histogram(org.eclipse.microprofile.metrics.Histogram) Context(io.grpc.Context) ServerCallHandler(io.grpc.ServerCallHandler) Metric(org.eclipse.microprofile.metrics.Metric) CoreMatchers.not(org.hamcrest.CoreMatchers.not) HashMap(java.util.HashMap) Meter(org.eclipse.microprofile.metrics.Meter) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) ConcurrentGauge(org.eclipse.microprofile.metrics.ConcurrentGauge) SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) StreamObserver(io.grpc.stub.StreamObserver) ArgumentCaptor(org.mockito.ArgumentCaptor) Counter(org.eclipse.microprofile.metrics.Counter) LazyValue(io.helidon.common.LazyValue) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) MetricsSupport(io.helidon.metrics.MetricsSupport) Status(io.grpc.Status) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MetricUnits(org.eclipse.microprofile.metrics.MetricUnits) Mockito.when(org.mockito.Mockito.when) MetricID(org.eclipse.microprofile.metrics.MetricID) Collectors(java.util.stream.Collectors) Timer(org.eclipse.microprofile.metrics.Timer) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) GrpcService(io.helidon.grpc.server.GrpcService) ServerCall(io.grpc.ServerCall) Metadata(io.grpc.Metadata) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Routing(io.helidon.webserver.Routing) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) Metadata(io.grpc.Metadata) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MethodDescriptor(io.helidon.grpc.server.MethodDescriptor) MetricID(org.eclipse.microprofile.metrics.MetricID) ServiceDescriptor(io.helidon.grpc.server.ServiceDescriptor) Metric(org.eclipse.microprofile.metrics.Metric) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with MethodDescriptor

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

the class GrpcMetricsInterceptorIT method shouldUseTimerMetric.

@Test
public void shouldUseTimerMetric() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("barTimed", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("barTimed");
    GrpcMetrics metrics = GrpcMetrics.timed();
    ServerCall<String, String> call = call(metrics, methodDescriptor);
    call.close(Status.OK, new Metadata());
    Timer appTimer = appRegistry.get().timer("Foo.barTimed");
    assertVendorMetrics();
    assertThat(appTimer.getCount(), is(1L));
}
Also used : SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) Timer(org.eclipse.microprofile.metrics.Timer) 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 3 with MethodDescriptor

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

the class GrpcMetricsInterceptorIT method shouldUseCountedMetric.

@Test
public void shouldUseCountedMetric() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).unary("testCounted", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("testCounted");
    GrpcMetrics metrics = GrpcMetrics.counted();
    ServerCall<String, String> call = call(metrics, methodDescriptor);
    call.close(Status.OK, new Metadata());
    Counter appCounter = appRegistry.get().counter("Foo.testCounted");
    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 4 with MethodDescriptor

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

the class GrpcMetricsInterceptorIT method shouldUseConcurrentGaugeMetric.

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

Example 5 with MethodDescriptor

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

the class GrpcMetricsInterceptorIT method shouldHaveCorrectNameWithDotsForSlashes.

@Test
public void shouldHaveCorrectNameWithDotsForSlashes() throws Exception {
    ServiceDescriptor descriptor = ServiceDescriptor.builder(createMockService()).name("My/Service").unary("bar", this::dummyUnary).build();
    MethodDescriptor methodDescriptor = descriptor.method("bar");
    GrpcMetrics metrics = GrpcMetrics.counted();
    ServerCall<String, String> call = call(metrics, descriptor, methodDescriptor);
    call.close(Status.OK, new Metadata());
    Counter appCounter = appRegistry.get().counter("My.Service.bar");
    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)

Aggregations

MethodDescriptor (io.helidon.grpc.server.MethodDescriptor)14 ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)14 Metadata (io.grpc.Metadata)12 Test (org.junit.jupiter.api.Test)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 Counter (org.eclipse.microprofile.metrics.Counter)6 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)3 ServerCall (io.grpc.ServerCall)2 ServerCallHandler (io.grpc.ServerCallHandler)2 ConcurrentGauge (org.eclipse.microprofile.metrics.ConcurrentGauge)2 Histogram (org.eclipse.microprofile.metrics.Histogram)2 Meter (org.eclipse.microprofile.metrics.Meter)2 Timer (org.eclipse.microprofile.metrics.Timer)2 Context (io.grpc.Context)1 Status (io.grpc.Status)1 StreamObserver (io.grpc.stub.StreamObserver)1 LazyValue (io.helidon.common.LazyValue)1 GrpcService (io.helidon.grpc.server.GrpcService)1 MetricsSupport (io.helidon.metrics.MetricsSupport)1 Routing (io.helidon.webserver.Routing)1