Search in sources :

Example 1 with Metric

use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.

the class ZMSUtilsTest method testEmitMonmetricError.

@Test
public void testEmitMonmetricError() {
    Metric savedMetric = ZMSImpl.metric;
    assertFalse(ZMSUtils.emitMonmetricError(-1, "unittest"));
    assertFalse(ZMSUtils.emitMonmetricError(400, null));
    assertFalse(ZMSUtils.emitMonmetricError(400, ""));
    ZMSImpl.metric = null;
    assertFalse(ZMSUtils.emitMonmetricError(400, "unittest"));
    ZMSImpl.metric = savedMetric;
}
Also used : Metric(com.yahoo.athenz.common.metrics.Metric) Test(org.testng.annotations.Test)

Example 2 with Metric

use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.

the class MetricsTest method testMetricInterfaceNonDefaults.

@Test
public void testMetricInterfaceNonDefaults() {
    Metric metric = new Metric() {

        @Override
        public void increment(String metric) {
        }

        @Override
        public void increment(String metric, String requestDomainName) {
        }

        @Override
        public void increment(String metric, String requestDomainName, int count) {
        }

        @Override
        public Object startTiming(String metric, String requestDomainName) {
            return null;
        }

        @Override
        public void stopTiming(Object timerMetric) {
        }

        @Override
        public void flush() {
        }

        @Override
        public void quit() {
        }
    };
    metric.increment("metric1");
    metric.increment("metric1", "athenz", 3);
    metric.increment("metric1", "athenz", "sports");
    metric.increment("metric1", "athenz", "sports", 3);
    metric.increment("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
    String[] attributes = new String[] { "tag1", "value1", "tag2", "value2", "tag3", "value3" };
    metric.increment("metric1", attributes);
    assertNull(metric.startTiming("metric1", "athenz", "sports"));
    assertNull(metric.startTiming("apiRquestsMetric", "athenz", "sports", "POST", "caller"));
    metric.stopTiming("metric1", "athenz", "sports");
    metric.stopTiming("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
    metric.flush();
    metric.quit();
}
Also used : Metric(com.yahoo.athenz.common.metrics.Metric) Test(org.testng.annotations.Test)

Example 3 with Metric

use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.

the class MetricsTest method testFactoryNoOpMetric.

@Test
public void testFactoryNoOpMetric() throws Exception {
    MetricFactory factory = new NoOpMetricFactory();
    Metric metric = factory.create();
    assertEquals(metric.getClass().getName(), Class.forName("com.yahoo.athenz.common.metrics.impl.NoOpMetric").getName());
    metric.increment("metric1");
    metric.increment("metric1", "athenz");
    metric.increment("metric1", "athenz", 3);
    metric.increment("metric1", "athenz", "sports");
    metric.increment("metric1", "athenz", "sports", 3);
    metric.increment("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
    String[] attributes = new String[] { "tag1", "value1", "tag2", "value2", "tag3", "value3" };
    metric.increment("metric1", attributes);
    assertNull(metric.startTiming("metric1", "athenz"));
    assertNull(metric.startTiming("metric1", "athenz", "sports"));
    assertNull(metric.startTiming("apiRquestsMetric", "athenz", "sports", "POST", "caller"));
    metric.stopTiming("metric1");
    metric.stopTiming("metric1", "athenz", "sports");
    metric.stopTiming("apiRquestsMetric", "athenz", "sports", "POST", 200, "caller");
    metric.flush();
    metric.quit();
}
Also used : MetricFactory(com.yahoo.athenz.common.metrics.MetricFactory) Metric(com.yahoo.athenz.common.metrics.Metric) Test(org.testng.annotations.Test)

Example 4 with Metric

use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.

the class ZTSImplTest method testEmitMonmetricError.

@Test
public void testEmitMonmetricError() {
    int errorCode = 403;
    String caller = "forbiddenError";
    boolean isEmitMonmetricError;
    com.yahoo.athenz.common.metrics.Metric metric = getMetric();
    // negative tests
    isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, null, ZTSConsts.ZTS_UNKNOWN_DOMAIN, "principal-domain", metric);
    assertFalse(isEmitMonmetricError);
    isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, "", ZTSConsts.ZTS_UNKNOWN_DOMAIN, "principal-domain", metric);
    assertFalse(isEmitMonmetricError);
    isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, "", null, "principal-domain", metric);
    assertFalse(isEmitMonmetricError);
    isEmitMonmetricError = ZTSUtils.emitMonmetricError(0, caller, null, "principal-domain", metric);
    assertFalse(isEmitMonmetricError);
    isEmitMonmetricError = ZTSUtils.emitMonmetricError(-100, caller, null, "principal-domain", metric);
    assertFalse(isEmitMonmetricError);
    // positive tests
    isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, caller, null, "principal-domain", metric);
    assertTrue(isEmitMonmetricError);
    isEmitMonmetricError = ZTSUtils.emitMonmetricError(errorCode, " " + caller + " ", null, "principal-domain", metric);
    assertTrue(isEmitMonmetricError);
}
Also used : Metric(com.yahoo.athenz.common.metrics.Metric) Test(org.testng.annotations.Test)

Example 5 with Metric

use of com.yahoo.athenz.common.metrics.Metric in project athenz by yahoo.

the class ZTSImplTest method getMetric.

private Metric getMetric() {
    com.yahoo.athenz.common.metrics.MetricFactory metricFactory;
    com.yahoo.athenz.common.metrics.Metric metric;
    try {
        metricFactory = (com.yahoo.athenz.common.metrics.MetricFactory) Class.forName(System.getProperty(ZTSConsts.ZTS_PROP_METRIC_FACTORY_CLASS)).newInstance();
        metric = metricFactory.create();
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException exc) {
        System.out.println("Invalid MetricFactory class: " + METRIC_DEFAULT_FACTORY_CLASS + " error: " + exc.getMessage());
        metric = new com.yahoo.athenz.common.metrics.impl.NoOpMetric();
    }
    return metric;
}
Also used : Metric(com.yahoo.athenz.common.metrics.Metric)

Aggregations

Metric (com.yahoo.athenz.common.metrics.Metric)21 Test (org.testng.annotations.Test)19 Authorizer (com.yahoo.athenz.auth.Authorizer)11 AuthorityList (com.yahoo.athenz.common.server.rest.Http.AuthorityList)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)11 Authority (com.yahoo.athenz.auth.Authority)7 PrincipalAuthority (com.yahoo.athenz.auth.impl.PrincipalAuthority)7 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)6 Principal (com.yahoo.athenz.auth.Principal)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 SslConnection (org.eclipse.jetty.io.ssl.SslConnection)2 SslHandshakeListener (org.eclipse.jetty.io.ssl.SslHandshakeListener)2 DomainChangeMessage (com.yahoo.athenz.common.messaging.DomainChangeMessage)1 MetricFactory (com.yahoo.athenz.common.metrics.MetricFactory)1 Notification (com.yahoo.athenz.common.server.notification.Notification)1 NotificationMetric (com.yahoo.athenz.common.server.notification.NotificationMetric)1 NotificationToMetricConverter (com.yahoo.athenz.common.server.notification.NotificationToMetricConverter)1