Search in sources :

Example 96 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project cruise-control by linkedin.

the class SessionManagerTest method testSkipStep.

@Test(expected = IllegalArgumentException.class)
public void testSkipStep() {
    TestContext context = prepareRequests(false, 1);
    SessionManager sessionManager = new SessionManager(1, 1000, context.time(), new MetricRegistry());
    HttpServletRequest request = context.request(0);
    sessionManager.getAndCreateSessionIfNotExist(request, () -> null, 1);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 97 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project cruise-control by linkedin.

the class SessionManagerTest method testCreateSessionReachingCapacity.

@Test
public void testCreateSessionReachingCapacity() {
    TestContext context = prepareRequests(false, 2);
    SessionManager sessionManager = new SessionManager(1, 1000, context.time(), new MetricRegistry());
    sessionManager.getAndCreateSessionIfNotExist(context.request(0), () -> new OperationFuture<>("testCreateSession"), 0);
    assertEquals(1, sessionManager.numSessions());
    assertNull(sessionManager.getFuture(context.request(1)));
    // Adding same request again should have no impact
    sessionManager.getAndCreateSessionIfNotExist(context.request(0), () -> new OperationFuture<>("testCreateSession"), 1);
    assertEquals(1, sessionManager.numSessions());
    try {
        sessionManager.getAndCreateSessionIfNotExist(context.request(1), () -> new OperationFuture<>("testCreateSession"), 0);
        fail("Should have thrown exception due to session capacity reached.");
    } catch (RuntimeException e) {
    // let it go.
    }
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 98 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project cruise-control by linkedin.

the class ExecutionTaskManagerTest method testStateChangeSequences.

@Test
public void testStateChangeSequences() {
    TopicPartition tp = new TopicPartition("topic", 0);
    ExecutionTaskManager taskManager = new ExecutionTaskManager(1, 1, new MetricRegistry());
    List<List<ExecutionTask.State>> testSequences = new ArrayList<>();
    // Completed successfully.
    testSequences.add(Arrays.asList(IN_PROGRESS, COMPLETED));
    // Rollback succeeded.
    testSequences.add(Arrays.asList(IN_PROGRESS, ABORTING, ABORTED));
    // Rollback failed.
    testSequences.add(Arrays.asList(IN_PROGRESS, ABORTING, DEAD));
    // Cannot rollback.
    testSequences.add(Arrays.asList(IN_PROGRESS, DEAD));
    for (List<ExecutionTask.State> sequence : testSequences) {
        taskManager.clear();
        // Make sure the proposal does not involve leader movement.
        ExecutionProposal proposal = new ExecutionProposal(tp, 0, 2, Arrays.asList(0, 2), Arrays.asList(2, 1));
        taskManager.addExecutionProposals(Collections.singletonList(proposal), Collections.emptySet(), generateExpectedCluster(proposal, tp));
        List<ExecutionTask> tasks = taskManager.getReplicaMovementTasks();
        assertEquals(1, tasks.size());
        ExecutionTask task = tasks.get(0);
        verifyStateChangeSequence(sequence, task, taskManager);
    }
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) State(com.linkedin.kafka.cruisecontrol.executor.ExecutionTask.State) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 99 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project Singularity by HubSpot.

the class GuicePropertyFilteringMessageBodyWriter method getMetricRegistry.

private MetricRegistry getMetricRegistry() {
    MetricRegistry registry = environment.metrics();
    if (registry == null) {
        LOG.warn("No environment metrics found!");
        registry = SharedMetricRegistries.getOrCreate("com.hubspot");
    }
    return registry;
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry)

Example 100 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project Singularity by HubSpot.

the class SingularityRunnerBaseModule method configure.

@Override
protected void configure() {
    bind(ObjectMapper.class).toInstance(JavaUtils.newObjectMapper());
    bind(MetricRegistry.class).toInstance(new MetricRegistry());
    SingularityRunnerBaseLogging.quietEagerLogging();
    bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator());
    bind(SingularityRunnerExceptionNotifier.class).in(Scopes.SINGLETON);
    final Optional<String> consolidatedConfigFilename = Optional.fromNullable(Strings.emptyToNull(System.getProperty(CONFIG_PROPERTY)));
    final ConfigurationBinder configurationBinder = ConfigurationBinder.newBinder(binder());
    configurationBinder.bindPrimaryConfiguration(primaryConfigurationClass, consolidatedConfigFilename);
    for (Class<? extends BaseRunnerConfiguration> additionalConfigurationClass : additionalConfigurationClasses) {
        configurationBinder.bindConfiguration(additionalConfigurationClass, consolidatedConfigFilename);
    }
    if (!additionalConfigurationClasses.contains(SingularityRunnerBaseConfiguration.class)) {
        configurationBinder.bindConfiguration(SingularityRunnerBaseConfiguration.class, consolidatedConfigFilename);
    }
    bind(SingularityRunnerBaseLogging.class).asEagerSingleton();
    bind(new TypeLiteral<Optional<String>>() {
    }).annotatedWith(Names.named(CONSOLIDATED_CONFIG_FILENAME)).toInstance(consolidatedConfigFilename);
}
Also used : SingularityRunnerExceptionNotifier(com.hubspot.singularity.runner.base.sentry.SingularityRunnerExceptionNotifier) Optional(com.google.common.base.Optional) MetricRegistry(com.codahale.metrics.MetricRegistry) SingularityRunnerBaseConfiguration(com.hubspot.singularity.runner.base.configuration.SingularityRunnerBaseConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validator(javax.validation.Validator)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)505 Test (org.junit.Test)177 Before (org.junit.Before)61 Test (org.junit.jupiter.api.Test)45 VerifiableProperties (com.github.ambry.config.VerifiableProperties)42 ArrayList (java.util.ArrayList)33 Counter (com.codahale.metrics.Counter)30 File (java.io.File)29 Properties (java.util.Properties)28 List (java.util.List)23 Metric (com.codahale.metrics.Metric)22 Map (java.util.Map)22 IOException (java.io.IOException)21 HashMap (java.util.HashMap)20 Size (com.github.joschi.jadconfig.util.Size)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 TimeUnit (java.util.concurrent.TimeUnit)17 Timer (com.codahale.metrics.Timer)15 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)15