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());
}
}
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);
}
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);
}
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());
}
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);
}
Aggregations