Search in sources :

Example 1 with Metric

use of com.yahoo.jdisc.Metric in project vespa by vespa-engine.

the class ClusterControllerClusterConfigurerTest method testSimple.

@Test
public void testSimple() throws Exception {
    ClusterController controller = new ClusterController();
    StorDistributionConfig.Builder distributionConfig = new StorDistributionConfig.Builder();
    StorDistributionConfig.Group.Builder group = new StorDistributionConfig.Group.Builder();
    group.index("0").name("foo");
    StorDistributionConfig.Group.Nodes.Builder node = new StorDistributionConfig.Group.Nodes.Builder();
    node.index(0);
    group.nodes.add(node);
    distributionConfig.group.add(group);
    FleetcontrollerConfig.Builder fleetcontrollerConfig = new FleetcontrollerConfig.Builder();
    fleetcontrollerConfig.cluster_name("storage").index(0).zookeeper_server("zoo").min_node_ratio_per_group(0.123);
    SlobroksConfig.Builder slobroksConfig = new SlobroksConfig.Builder();
    SlobroksConfig.Slobrok.Builder slobrok = new SlobroksConfig.Slobrok.Builder();
    slobrok.connectionspec("foo");
    slobroksConfig.slobrok.add(slobrok);
    ZookeepersConfig.Builder zookeepersConfig = new ZookeepersConfig.Builder();
    zookeepersConfig.zookeeperserverlist("foo");
    Metric metric = new Metric() {

        @Override
        public void set(String s, Number number, Context context) {
        }

        @Override
        public void add(String s, Number number, Context context) {
        }

        @Override
        public Context createContext(Map<String, ?> stringMap) {
            return null;
        }
    };
    // Used in standalone modus to get config without a cluster controller instance
    ClusterControllerClusterConfigurer configurer = new ClusterControllerClusterConfigurer(null, new StorDistributionConfig(distributionConfig), new FleetcontrollerConfig(fleetcontrollerConfig), new SlobroksConfig(slobroksConfig), new ZookeepersConfig(zookeepersConfig), metric);
    assertTrue(configurer.getOptions() != null);
    assertEquals(0.123, configurer.getOptions().minNodeRatioPerGroup, 0.01);
    // Oki with no zookeeper if one node
    zookeepersConfig.zookeeperserverlist("");
    new ClusterControllerClusterConfigurer(controller, new StorDistributionConfig(distributionConfig), new FleetcontrollerConfig(fleetcontrollerConfig), new SlobroksConfig(slobroksConfig), new ZookeepersConfig(zookeepersConfig), metric);
    try {
        fleetcontrollerConfig.fleet_controller_count(5);
        new ClusterControllerClusterConfigurer(controller, new StorDistributionConfig(distributionConfig), new FleetcontrollerConfig(fleetcontrollerConfig), new SlobroksConfig(slobroksConfig), new ZookeepersConfig(zookeepersConfig), metric);
        fail("Should not get here");
    } catch (Exception e) {
        assertEquals("Must set zookeeper server with multiple fleetcontrollers", e.getMessage());
    }
}
Also used : StorDistributionConfig(com.yahoo.vespa.config.content.StorDistributionConfig) SlobroksConfig(com.yahoo.cloud.config.SlobroksConfig) ZookeepersConfig(com.yahoo.cloud.config.ZookeepersConfig) Metric(com.yahoo.jdisc.Metric) FleetcontrollerConfig(com.yahoo.vespa.config.content.FleetcontrollerConfig) Map(java.util.Map) Test(org.junit.Test)

Example 2 with Metric

use of com.yahoo.jdisc.Metric in project vespa by vespa-engine.

the class MetricImplTestCase method requireThatConsumerIsCalled.

@Test
public void requireThatConsumerIsCalled() throws InterruptedException {
    final MyConsumer consumer = new MyConsumer();
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricConsumer.class).toInstance(consumer);
        }
    });
    Metric metric = injector.getInstance(Metric.class);
    metric.set("foo", 6, null);
    assertEquals(6, consumer.map.get("foo").intValue());
    metric.add("foo", 9, null);
    assertEquals(15, consumer.map.get("foo").intValue());
    Metric.Context ctx = metric.createContext(null);
    assertEquals(consumer.ctx, ctx);
}
Also used : Injector(com.google.inject.Injector) Metric(com.yahoo.jdisc.Metric) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 3 with Metric

use of com.yahoo.jdisc.Metric in project vespa by vespa-engine.

the class ServiceMonitorMetricsTest method testTryWithResources.

@Test
public void testTryWithResources() {
    Metric metric = mock(Metric.class);
    Timer timer = mock(Timer.class);
    ServiceMonitorMetrics metrics = new ServiceMonitorMetrics(metric, timer);
    when(timer.currentTimeMillis()).thenReturn(Long.valueOf(500), Long.valueOf(1000));
    try (LatencyMeasurement measurement = metrics.startServiceModelSnapshotLatencyMeasurement()) {
        measurement.hashCode();
    }
    verify(metric).set("serviceModel.snapshot.latency", 0.5, null);
}
Also used : Timer(com.yahoo.jdisc.Timer) Metric(com.yahoo.jdisc.Metric) Test(org.junit.Test)

Example 4 with Metric

use of com.yahoo.jdisc.Metric in project vespa by vespa-engine.

the class AthenzIdentityProviderImplTest method metrics_updated_on_refresh.

@Test
public void metrics_updated_on_refresh() {
    IdentityDocumentService identityDocumentService = mock(IdentityDocumentService.class);
    AthenzService athenzService = mock(AthenzService.class);
    ManualClock clock = new ManualClock(Instant.EPOCH);
    Metric metric = mock(Metric.class);
    when(identityDocumentService.getSignedIdentityDocument()).thenReturn(getIdentityDocument());
    when(athenzService.sendInstanceRegisterRequest(any(), any())).then(new Answer<InstanceIdentity>() {

        @Override
        public InstanceIdentity answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new InstanceIdentity(getCertificate(getExpirationSupplier(clock)), "TOKEN");
        }
    });
    when(athenzService.sendInstanceRefreshRequest(anyString(), anyString(), anyString(), anyString(), any(), any(), any(), any())).thenThrow(new RuntimeException("#1")).thenThrow(new RuntimeException("#2")).thenReturn(new InstanceIdentity(getCertificate(getExpirationSupplier(clock)), "TOKEN"));
    AthenzCredentialsService credentialService = new AthenzCredentialsService(IDENTITY_CONFIG, identityDocumentService, athenzService, clock);
    AthenzIdentityProviderImpl identityProvider = new AthenzIdentityProviderImpl(IDENTITY_CONFIG, metric, credentialService, mock(ScheduledExecutorService.class), clock);
    identityProvider.reportMetrics();
    verify(metric).set(eq(AthenzIdentityProviderImpl.CERTIFICATE_EXPIRY_METRIC_NAME), eq(certificateValidity.getSeconds()), any());
    // Advance 1 day, refresh fails, cert is 1 day old
    clock.advance(Duration.ofDays(1));
    identityProvider.refreshCertificate();
    identityProvider.reportMetrics();
    verify(metric).set(eq(AthenzIdentityProviderImpl.CERTIFICATE_EXPIRY_METRIC_NAME), eq(certificateValidity.minus(Duration.ofDays(1)).getSeconds()), any());
    // Advance 1 more day, refresh fails, cert is 2 days old
    clock.advance(Duration.ofDays(1));
    identityProvider.refreshCertificate();
    identityProvider.reportMetrics();
    verify(metric).set(eq(AthenzIdentityProviderImpl.CERTIFICATE_EXPIRY_METRIC_NAME), eq(certificateValidity.minus(Duration.ofDays(2)).getSeconds()), any());
    // Advance 1 more day, refresh succeds, cert is new
    clock.advance(Duration.ofDays(1));
    identityProvider.refreshCertificate();
    identityProvider.reportMetrics();
    verify(metric).set(eq(AthenzIdentityProviderImpl.CERTIFICATE_EXPIRY_METRIC_NAME), eq(certificateValidity.getSeconds()), any());
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ManualClock(com.yahoo.test.ManualClock) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Metric(com.yahoo.jdisc.Metric) Test(org.junit.Test)

Example 5 with Metric

use of com.yahoo.jdisc.Metric in project vespa by vespa-engine.

the class StateHandlerTest method startTestDriver.

@Before
public void startTestDriver() {
    Timer timer = this.currentTimeMillis::get;
    this.driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Timer.class).toInstance(timer);
        }
    });
    ContainerBuilder builder = driver.newContainerBuilder();
    HealthMonitorConfig healthMonitorConfig = new HealthMonitorConfig(new HealthMonitorConfig.Builder().snapshot_interval(TimeUnit.MILLISECONDS.toSeconds(SNAPSHOT_INTERVAL)));
    ThreadFactory threadFactory = ignored -> mock(Thread.class);
    this.monitor = new StateMonitor(healthMonitorConfig, timer, threadFactory);
    builder.guiceModules().install(new AbstractModule() {

        @Override
        protected void configure() {
            bind(StateMonitor.class).toInstance(monitor);
            bind(MetricConsumer.class).toProvider(MetricConsumerProviders.wrap(monitor));
            bind(ApplicationMetadataConfig.class).toInstance(new ApplicationMetadataConfig(new ApplicationMetadataConfig.Builder().generation(META_GENERATION)));
            bind(MetricsPresentationConfig.class).toInstance(new MetricsPresentationConfig(new MetricsPresentationConfig.Builder()));
        }
    });
    builder.serverBindings().bind("http://*/*", builder.getInstance(StateHandler.class));
    driver.activateContainer(builder);
    metric = builder.getInstance(Metric.class);
}
Also used : Metric(com.yahoo.jdisc.Metric) TestDriver(com.yahoo.jdisc.test.TestDriver) Defaults(com.yahoo.vespa.defaults.Defaults) ApplicationMetadataConfig(com.yahoo.container.core.ApplicationMetadataConfig) Vtag(com.yahoo.component.Vtag) HashMap(java.util.HashMap) After(org.junit.After) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ThreadFactory(java.util.concurrent.ThreadFactory) Before(org.junit.Before) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) Response(com.yahoo.jdisc.Response) Assert.assertNotNull(org.junit.Assert.assertNotNull) MetricConsumer(com.yahoo.jdisc.application.MetricConsumer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) TreeMap(java.util.TreeMap) Assert.assertFalse(org.junit.Assert.assertFalse) Timer(com.yahoo.jdisc.Timer) BufferedContentChannel(com.yahoo.jdisc.handler.BufferedContentChannel) MetricsPresentationConfig(com.yahoo.metrics.MetricsPresentationConfig) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AbstractModule(com.google.inject.AbstractModule) HealthMonitorConfig(com.yahoo.container.jdisc.config.HealthMonitorConfig) Mockito.mock(org.mockito.Mockito.mock) ThreadFactory(java.util.concurrent.ThreadFactory) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) HealthMonitorConfig(com.yahoo.container.jdisc.config.HealthMonitorConfig) AbstractModule(com.google.inject.AbstractModule) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) Timer(com.yahoo.jdisc.Timer) ApplicationMetadataConfig(com.yahoo.container.core.ApplicationMetadataConfig) Metric(com.yahoo.jdisc.Metric) MetricsPresentationConfig(com.yahoo.metrics.MetricsPresentationConfig) Before(org.junit.Before)

Aggregations

Metric (com.yahoo.jdisc.Metric)11 Test (org.junit.Test)10 AbstractModule (com.google.inject.AbstractModule)3 Injector (com.google.inject.Injector)3 Timer (com.yahoo.jdisc.Timer)2 MetricConsumer (com.yahoo.jdisc.application.MetricConsumer)2 Map (java.util.Map)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SlobroksConfig (com.yahoo.cloud.config.SlobroksConfig)1 ZookeepersConfig (com.yahoo.cloud.config.ZookeepersConfig)1 Vtag (com.yahoo.component.Vtag)1 ApplicationMetadataConfig (com.yahoo.container.core.ApplicationMetadataConfig)1 HealthMonitorConfig (com.yahoo.container.jdisc.config.HealthMonitorConfig)1 Response (com.yahoo.jdisc.Response)1 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)1 BufferedContentChannel (com.yahoo.jdisc.handler.BufferedContentChannel)1 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)1 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)1 ActiveContainerMetrics (com.yahoo.jdisc.statistics.ActiveContainerMetrics)1