Search in sources :

Example 6 with AppType

use of com.quorum.tessera.config.AppType in project tessera by ConsenSys.

the class MetricsEnquirerTest method oneMBeanOneMetricUnsupportedApp.

@Test
public void oneMBeanOneMetricUnsupportedApp() {
    AppType appType = null;
    Throwable ex = catchThrowable(() -> metricsEnquirer.getMBeanMetrics(appType));
    assertThat(ex).isEqualToComparingFieldByField(new MonitoringNotSupportedException(appType));
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) AppType(com.quorum.tessera.config.AppType) Test(org.junit.Test)

Example 7 with AppType

use of com.quorum.tessera.config.AppType in project tessera by ConsenSys.

the class MetricsResource method getMetrics.

@GET
@Produces("text/plain")
public Response getMetrics() {
    MetricsEnquirer metricsEnquirer = new MetricsEnquirer(mbs);
    final StringBuilder formattedMetrics = new StringBuilder();
    for (AppType type : AppType.values()) {
        List<MBeanMetric> metrics = metricsEnquirer.getMBeanMetrics(type);
        PrometheusProtocolFormatter formatter = new PrometheusProtocolFormatter();
        formattedMetrics.append(formatter.format(metrics, type));
    }
    return Response.status(Response.Status.OK).header(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN).entity(formattedMetrics.toString()).build();
}
Also used : AppType(com.quorum.tessera.config.AppType) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Example 8 with AppType

use of com.quorum.tessera.config.AppType in project tessera by ConsenSys.

the class MetricsEnquirerTest method oneMBeanOneMetricQ2TApp.

@Test
public void oneMBeanOneMetricQ2TApp() throws MalformedObjectNameException, IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException, InstanceNotFoundException {
    ObjectName mBeanName = new ObjectName("domain", "key", "value");
    names.add(mBeanName);
    AppType appType = AppType.Q2T;
    ObjectName objName = new ObjectName("org.glassfish.jersey:type=Q2TRestApp,subType=Resources,resource=com.quorum.tessera.*,executionTimes=RequestTimes,detail=methods,method=*");
    when(mBeanServer.queryNames(objName, null)).thenReturn(names);
    String attributeName = "name_total";
    MBeanAttributeInfo[] mBeanAttributes = { new MBeanAttributeInfo(attributeName, "type", "desc", true, false, false) };
    MBeanInfo mBeanInfo = new MBeanInfo(null, null, mBeanAttributes, null, null, null);
    when(mBeanServer.getMBeanInfo(mBeanName)).thenReturn(mBeanInfo);
    when(mBeanServer.getAttribute(any(ObjectName.class), any(String.class))).thenReturn(1);
    List<MBeanMetric> metrics = metricsEnquirer.getMBeanMetrics(appType);
    assertThat(metrics.size()).isEqualTo(1);
    assertThat(metrics.get(0).getName()).isEqualTo("name_total");
}
Also used : AppType(com.quorum.tessera.config.AppType) Test(org.junit.Test)

Example 9 with AppType

use of com.quorum.tessera.config.AppType in project tessera by ConsenSys.

the class MetricsEnquirerTest method oneMBeanOneMetricThirdPartyApp.

@Test
public void oneMBeanOneMetricThirdPartyApp() throws MalformedObjectNameException, IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException, InstanceNotFoundException {
    ObjectName mBeanName = new ObjectName("domain", "key", "value");
    names.add(mBeanName);
    AppType appType = AppType.THIRD_PARTY;
    ObjectName objName = new ObjectName("org.glassfish.jersey:type=ThirdPartyRestApp,subType=Resources,resource=com.quorum.tessera.*,executionTimes=RequestTimes,detail=methods,method=*");
    when(mBeanServer.queryNames(objName, null)).thenReturn(names);
    String attributeName = "name_total";
    MBeanAttributeInfo[] mBeanAttributes = { new MBeanAttributeInfo(attributeName, "type", "desc", true, false, false) };
    MBeanInfo mBeanInfo = new MBeanInfo(null, null, mBeanAttributes, null, null, null);
    when(mBeanServer.getMBeanInfo(mBeanName)).thenReturn(mBeanInfo);
    when(mBeanServer.getAttribute(any(ObjectName.class), any(String.class))).thenReturn(1);
    List<MBeanMetric> metrics = metricsEnquirer.getMBeanMetrics(appType);
    assertThat(metrics.size()).isEqualTo(1);
    assertThat(metrics.get(0).getName()).isEqualTo("name_total");
}
Also used : AppType(com.quorum.tessera.config.AppType) Test(org.junit.Test)

Example 10 with AppType

use of com.quorum.tessera.config.AppType in project tessera by ConsenSys.

the class MetricsEnquirerTest method oneMBeanOneMetricP2PApp.

@Test
public void oneMBeanOneMetricP2PApp() throws MalformedObjectNameException, IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException, InstanceNotFoundException {
    ObjectName mBeanName = new ObjectName("domain", "key", "value");
    names.add(mBeanName);
    AppType appType = AppType.P2P;
    ObjectName objName = new ObjectName("org.glassfish.jersey:type=P2PRestApp,subType=Resources,resource=com.quorum.tessera.*,executionTimes=RequestTimes,detail=methods,method=*");
    when(mBeanServer.queryNames(objName, null)).thenReturn(names);
    String attributeName = "name_total";
    MBeanAttributeInfo[] mBeanAttributes = { new MBeanAttributeInfo(attributeName, "type", "desc", true, false, false) };
    MBeanInfo mBeanInfo = new MBeanInfo(null, null, mBeanAttributes, null, null, null);
    when(mBeanServer.getMBeanInfo(mBeanName)).thenReturn(mBeanInfo);
    when(mBeanServer.getAttribute(any(ObjectName.class), any(String.class))).thenReturn(1);
    List<MBeanMetric> metrics = metricsEnquirer.getMBeanMetrics(appType);
    assertThat(metrics.size()).isEqualTo(1);
    assertThat(metrics.get(0).getName()).isEqualTo("name_total");
}
Also used : AppType(com.quorum.tessera.config.AppType) Test(org.junit.Test)

Aggregations

AppType (com.quorum.tessera.config.AppType)18 Test (org.junit.Test)16 ServerConfig (com.quorum.tessera.config.ServerConfig)1 ConstraintValidatorContext (jakarta.validation.ConstraintValidatorContext)1 GET (jakarta.ws.rs.GET)1 Produces (jakarta.ws.rs.Produces)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 Before (org.junit.Before)1