Search in sources :

Example 1 with Measurement

use of com.alipay.lookout.api.Measurement in project sofa-rpc by sofastack.

the class RestLookoutTest method assertMethod.

/**
 * assert method
 *
 * @param metric       the metric
 * @param isProvider   is it the provider
 * @param totalCount   the total invoke count
 * @param method       the method name
 * @param requestSize  the request size
 * @param responseSize the response size
 */
private void assertMethod(Metric metric, boolean isProvider, int totalCount, String method, int requestSize, int responseSize) {
    // tag
    boolean tagAssert = false;
    for (Tag tag : metric.id().tags()) {
        String key = tag.key();
        String value = tag.value();
        LOGGER.info(this.getClass().getName() + ",key=" + key + ",value=" + value);
        if (key.equals("service")) {
            assertEquals("service not equal", RestService.class.getCanonicalName() + ":1.0", value);
            tagAssert = true;
        }
        if (key.equals("protocol")) {
            assertEquals("protocol not equal", "rest", value);
            tagAssert = true;
        }
        if (key.equals("method")) {
            assertEquals("method not equal", method, value);
            tagAssert = true;
        }
        if (isProvider) {
            if (key.equals("app")) {
                assertEquals("app not equal in provider", "TestLookOutServer", value);
                tagAssert = true;
            }
            if (key.equals("caller_app")) {
                assertEquals("caller_app not equal in provider", "TestLookOutClient", value);
                tagAssert = true;
            }
        } else {
            if (key.equals("app")) {
                assertEquals("app not equal in consumer", "TestLookOutClient", value);
                tagAssert = true;
            }
            if (key.equals("target_app")) {
                assertEquals("target_app not equal in consumer", "TestLookOutServer", value);
                tagAssert = true;
            }
            if (key.equals("invoke_type")) {
                assertEquals("invoke_type not equal in consumer", "sync", value);
            }
        }
    }
    if (!tagAssert) {
        Assert.fail("no tag assert");
    }
    // invoke info
    Collection<Measurement> measurements = metric.measure().measurements();
    if (isProvider) {
        assertEquals("measurements is not equals in provider", 3, measurements.size());
    } else {
        assertEquals("measurements is not equals in consumer", 4, measurements.size());
    }
    boolean invokeInfoAssert = false;
    for (Measurement measurement : measurements) {
        String name = measurement.name();
        int value = ((Long) measurement.value()).intValue();
        LOGGER.info(this.getClass().getName() + ",name=" + name + ",value=" + value);
        if (name.equals("total_count")) {
            assertEquals("total_count is not equal", totalCount, value);
            invokeInfoAssert = true;
        }
        if (name.equals("total_time.totalTime")) {
            assertTrue("totalTime is not equal", value < 3000);
            invokeInfoAssert = true;
        }
        if (name.equals("total_time.count")) {
            assertEquals("count is not equal", totalCount, value);
            invokeInfoAssert = true;
        }
        if (name.equals("fail_count")) {
            assertEquals("fail_count is not equal", 1, value);
            invokeInfoAssert = true;
        }
        if (name.equals("fail_time.totalTime")) {
            assertTrue("fail_time.totalTime is not equal", value > 3000);
            invokeInfoAssert = true;
        }
        if (name.equals("fail_time.count")) {
            assertEquals("fail_time.count is not equal", 1, value);
            invokeInfoAssert = true;
        }
        if (!isProvider) {
            if (name.equals("request_size.count")) {
                LOGGER.info("request_size.count,value={},requestSize={},totalCount={}", value, requestSize, totalCount);
                assertTrue("request_size.count is smaller than 0", requestSize > 0);
                invokeInfoAssert = true;
            }
            if (name.equals("response_size.count")) {
                LOGGER.info("response_size.count,value={},responseSize={},totalCount={}", value, responseSize, totalCount);
                assertTrue("response_size.count is smaller than 0", requestSize > 0);
                invokeInfoAssert = true;
            }
        }
    }
    if (!invokeInfoAssert) {
        Assert.fail("no invoke info assert");
    }
}
Also used : Measurement(com.alipay.lookout.api.Measurement) Tag(com.alipay.lookout.api.Tag)

Example 2 with Measurement

use of com.alipay.lookout.api.Measurement in project sofa-rpc by sofastack.

the class RpcLookoutTest method assertMethod.

/**
 * assert method
 *
 * @param metric       the metric
 * @param isProvider   is it the provider
 * @param totalCount   the total invoke count
 * @param method       the method name
 * @param requestSize  the request size
 * @param responseSize the response size
 */
private void assertMethod(Metric metric, boolean isProvider, int totalCount, String method, int requestSize, int responseSize) {
    // tag
    boolean tagAssert = false;
    for (Tag tag : metric.id().tags()) {
        String key = tag.key();
        String value = tag.value();
        LOGGER.info(this.getClass().getName() + ",key=" + key + ",value=" + value);
        if (key.equals("service")) {
            assertEquals("service not equal", LookoutService.class.getCanonicalName() + ":1.0", value);
            tagAssert = true;
        }
        if (key.equals("protocol")) {
            assertEquals("protocol not equal", "bolt", value);
            tagAssert = true;
        }
        if (key.equals("method")) {
            assertEquals("method not equal", method, value);
            tagAssert = true;
        }
        if (isProvider) {
            if (key.equals("app")) {
                assertEquals("app not equal in provider", "TestLookOutServer", value);
                tagAssert = true;
            }
            if (key.equals("caller_app")) {
                assertEquals("caller_app not equal in provider", "TestLookOutClient", value);
                tagAssert = true;
            }
        } else {
            if (key.equals("app")) {
                assertEquals("app not equal in consumer", "TestLookOutClient", value);
                tagAssert = true;
            }
            if (key.equals("target_app")) {
                assertEquals("target_app not equal in consumer", "TestLookOutServer", value);
                tagAssert = true;
            }
            if (key.equals("invoke_type")) {
                assertEquals("invoke_type not equal in consumer", method.substring(3).toLowerCase(), value);
            }
        }
    }
    if (!tagAssert) {
        Assert.fail("tag assert not executed");
    }
    // invoke info
    Collection<Measurement> measurements = metric.measure().measurements();
    if (isProvider) {
        assertEquals("measurements size is not equal", 6, measurements.size());
    } else {
        if (method.equals("sayOneway")) {
            assertEquals("measurements is not equal in sayOneway", 5, measurements.size());
        } else {
            assertEquals("measurements is not equal in others", 10, measurements.size());
        }
    }
    boolean invokeInfoAssert = false;
    for (Measurement measurement : measurements) {
        String name = measurement.name();
        int value = ((Long) measurement.value()).intValue();
        LOGGER.info(this.getClass().getName() + ",name=" + name + ",value=" + value);
        if (name.equals("total_count")) {
            assertEquals("total_count is not equal", totalCount, value);
            invokeInfoAssert = true;
        }
        if (name.equals("total_time.totalTime")) {
            if (method.equals("sayOneway") && !isProvider) {
                assertTrue("totalTime is not equal in consumer", value < 3000);
            } else {
                assertTrue("totalTime is not equal in provider", value > 3000);
            }
            invokeInfoAssert = true;
        }
        if (name.equals("total_time.count")) {
            assertEquals("count is not equal", totalCount, value);
            invokeInfoAssert = true;
        }
        if (name.equals("fail_count")) {
            assertEquals("fail_count is not equal", 1, value);
            invokeInfoAssert = true;
        }
        if (name.equals("fail_time.totalTime")) {
            assertTrue("fail_time.totalTime is not equal", value > 3000);
            invokeInfoAssert = true;
        }
        if (name.equals("fail_time.count")) {
            assertEquals("fail_time.count is not equal", 1, value);
            invokeInfoAssert = true;
        }
        if (!isProvider) {
            if (name.equals("request_size.count")) {
                LOGGER.info("request_size.count,value={},requestSize={},totalCount={}", value, requestSize, totalCount);
                assertTrue("request_size.count is smaller than 0", requestSize > 0);
                invokeInfoAssert = true;
            }
            if (name.equals("response_size.count")) {
                LOGGER.info("response_size.count,value={},responseSize={},totalCount={}", value, responseSize, totalCount);
                assertTrue("response_size.count is smaller than 0", responseSize > 0);
                invokeInfoAssert = true;
            }
        }
    }
    if (!invokeInfoAssert) {
        Assert.fail("invoke assert not executed");
    }
}
Also used : Measurement(com.alipay.lookout.api.Measurement) Tag(com.alipay.lookout.api.Tag)

Example 3 with Measurement

use of com.alipay.lookout.api.Measurement in project sofa-rpc by sofastack.

the class RpcLookoutTest method testThreadPoolQueueSize.

/**
 * test thread pool queue size
 */
@Test
public void testThreadPoolQueueSize() {
    Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.queue.size", "");
    Collection<Measurement> measurements = metric.measure().measurements();
    assertTrue(measurements.size() == 1);
    for (Measurement measurement : measurements) {
        assertEquals(0, ((Number) measurement.value()).intValue());
    }
}
Also used : Measurement(com.alipay.lookout.api.Measurement) Metric(com.alipay.lookout.api.Metric) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Example 4 with Measurement

use of com.alipay.lookout.api.Measurement in project sofa-rpc by sofastack.

the class RpcLookoutTest method testThreadPoolIdleCount.

/**
 * test thread pool idle count
 */
@Test
public void testThreadPoolIdleCount() {
    // sync invoke some time
    for (int i = 0; i < 3; i++) {
        try {
            lookoutService.saySync("lookout_sync");
        } catch (Exception e) {
            LOGGER.error("sync error", e);
        }
    }
    try {
        TimeUnit.SECONDS.sleep(10);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.idle.count", "");
    Collection<Measurement> measurements = metric.measure().measurements();
    assertTrue(measurements.size() == 1);
    for (Measurement measurement : measurements) {
        assertEquals(3, ((Number) measurement.value()).intValue());
    }
}
Also used : Measurement(com.alipay.lookout.api.Measurement) Metric(com.alipay.lookout.api.Metric) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Example 5 with Measurement

use of com.alipay.lookout.api.Measurement in project sofa-rpc by sofastack.

the class RpcLookoutTest method testThreadPoolActiveCount.

/**
 * test thread pool active count
 *
 * @throws Exception Exception
 */
@Test
public void testThreadPoolActiveCount() throws Exception {
    Metric metric = fetchWithNameAndMethod("rpc.bolt.threadpool.active.count", "");
    Collection<Measurement> measurements = metric.measure().measurements();
    assertTrue(measurements.size() == 1);
    for (Measurement measurement : measurements) {
        assertEquals(0, ((Number) measurement.value()).intValue());
    }
}
Also used : Measurement(com.alipay.lookout.api.Measurement) Metric(com.alipay.lookout.api.Metric) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Aggregations

Measurement (com.alipay.lookout.api.Measurement)6 Metric (com.alipay.lookout.api.Metric)4 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)4 Test (org.junit.Test)4 Tag (com.alipay.lookout.api.Tag)2 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)1