com.netflix.spectator.api.NoopRegistry Java Examples

The following examples show how to use com.netflix.spectator.api.NoopRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CanaryAnalysisPrometheusMetricsMixerServiceIntegrationTest.java    From kayenta with Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
  initMocks(this);
  prometheusResponseConverter = new PrometheusResponseConverter(new ObjectMapper());
  prometheusMetricsService =
      spy(
          PrometheusMetricsService.builder()
              .scopeLabel("instance")
              .accountCredentialsRepository(accountCredentialsRepository)
              .registry(new NoopRegistry())
              .build());

  metricSetMixerService = new MetricSetMixerService();

  when(accountCredentialsRepository.getRequiredOne(anyString())).thenReturn(credentials);
  when(credentials.getPrometheusRemoteService()).thenReturn(prometheusRemoteService);
}
 
Example #2
Source File: AtlasRegistryTest.java    From spectator with Apache License 2.0 6 votes vote down vote up
private AtlasConfig newConfig() {
  Map<String, String> props = new LinkedHashMap<>();
  props.put("atlas.enabled", "false");
  props.put("atlas.step", "PT10S");
  props.put("atlas.batchSize", "3");

  return new AtlasConfig() {
    @Override public String get(String k) {
      return props.get(k);
    }

    @Override public Registry debugRegistry() {
      return new NoopRegistry();
    }
  };
}
 
Example #3
Source File: LongTaskTimer.java    From spectator with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a timer for tracking long running tasks.
 *
 * @param registry
 *     Registry to use.
 * @param id
 *     Identifier for the metric being registered.
 * @return
 *     Timer instance.
 */
public static LongTaskTimer get(Registry registry, Id id) {
  ConcurrentMap<Id, Object> state = registry.state();
  Object obj = Utils.computeIfAbsent(state, id, i -> {
    LongTaskTimer timer = new LongTaskTimer(registry, id);
    PolledMeter.using(registry)
        .withId(id)
        .withTag(Statistic.activeTasks)
        .monitorValue(timer, LongTaskTimer::activeTasks);
    PolledMeter.using(registry)
        .withId(id)
        .withTag(Statistic.duration)
        .monitorValue(timer, t -> t.duration() / NANOS_PER_SECOND);
    return timer;
  });
  if (!(obj instanceof LongTaskTimer)) {
    Utils.propagateTypeError(registry, id, LongTaskTimer.class, obj.getClass());
    obj = new LongTaskTimer(new NoopRegistry(), id);
  }
  return (LongTaskTimer) obj;
}
 
Example #4
Source File: BaseZuulChannelInitializerTest.java    From zuul with Apache License 2.0 6 votes vote down vote up
@Test
public void tcpHandlersAdded() {
    ChannelConfig channelConfig = new ChannelConfig();
    ChannelConfig channelDependencies = new ChannelConfig();
    channelDependencies.set(ZuulDependencyKeys.registry, new NoopRegistry());
    channelDependencies.set(
            ZuulDependencyKeys.rateLimitingChannelHandlerProvider, new NullChannelHandlerProvider());
    channelDependencies.set(
            ZuulDependencyKeys.sslClientCertCheckChannelHandlerProvider, new NullChannelHandlerProvider());
    ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    BaseZuulChannelInitializer init =
            new BaseZuulChannelInitializer("1234", channelConfig, channelDependencies, channelGroup) {

        @Override
        protected void initChannel(Channel ch) {}
    };
    EmbeddedChannel channel = new EmbeddedChannel();

    init.addTcpRelatedHandlers(channel.pipeline());

    assertNotNull(channel.pipeline().context(SourceAddressChannelHandler.class));
    assertNotNull(channel.pipeline().context(ServerChannelMetrics.class));
    assertNotNull(channel.pipeline().context(PerEventLoopMetricsChannelHandler.Connections.class));
    assertNotNull(channel.pipeline().context(ElbProxyProtocolChannelHandler.NAME));
    assertNotNull(channel.pipeline().context(MaxInboundConnectionsHandler.class));
}
 
Example #5
Source File: RollupsTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void before() {
  clock = new ManualClock();
  AtlasConfig config = new AtlasConfig() {
    @Override public String get(String k) {
      return "atlas.step".equals(k) ? "PT5S" : null;
    }

    @Override public Registry debugRegistry() {
      return new NoopRegistry();
    }
  };
  registry = new AtlasRegistry(clock, config);
}
 
Example #6
Source File: BaseZuulChannelInitializerTest.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Test
public void tcpHandlersAdded_withProxyProtocol() {
    ChannelConfig channelConfig = new ChannelConfig();
    channelConfig.set(CommonChannelConfigKeys.withProxyProtocol, true);
    ChannelConfig channelDependencies = new ChannelConfig();
    channelDependencies.set(ZuulDependencyKeys.registry, new NoopRegistry());
    channelDependencies.set(
            ZuulDependencyKeys.rateLimitingChannelHandlerProvider, new NullChannelHandlerProvider());
    channelDependencies.set(
            ZuulDependencyKeys.sslClientCertCheckChannelHandlerProvider, new NullChannelHandlerProvider());
    ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    BaseZuulChannelInitializer init =
            new BaseZuulChannelInitializer("1234", channelConfig, channelDependencies, channelGroup) {

                @Override
                protected void initChannel(Channel ch) {}
            };
    EmbeddedChannel channel = new EmbeddedChannel();

    init.addTcpRelatedHandlers(channel.pipeline());

    assertNotNull(channel.pipeline().context(SourceAddressChannelHandler.class));
    assertNotNull(channel.pipeline().context(ServerChannelMetrics.class));
    assertNotNull(channel.pipeline().context(PerEventLoopMetricsChannelHandler.Connections.class));
    assertNotNull(channel.pipeline().context(ElbProxyProtocolChannelHandler.NAME));
    assertNotNull(channel.pipeline().context(MaxInboundConnectionsHandler.class));
}
 
Example #7
Source File: AWSAppAutoScalingClientTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Test
public void deleteScalingPolicyIsIdempotent() {
    String jobId = UUID.randomUUID().toString();
    String policyId = UUID.randomUUID().toString();

    AWSApplicationAutoScalingAsync clientAsync = mock(AWSApplicationAutoScalingAsync.class);
    AWSAppScalingConfig config = mock(AWSAppScalingConfig.class);
    AWSAppAutoScalingClient autoScalingClient = new AWSAppAutoScalingClient(clientAsync, config, new NoopRegistry());

    // delete happens successfully on the first attempt
    AtomicBoolean isDeleted = new AtomicBoolean(false);
    when(clientAsync.deleteScalingPolicyAsync(any(), any())).thenAnswer(invocation -> {
        DeleteScalingPolicyRequest request = invocation.getArgument(0);
        AsyncHandler<DeleteScalingPolicyRequest, DeleteScalingPolicyResult> handler = invocation.getArgument(1);

        if (isDeleted.get()) {
            ObjectNotFoundException notFoundException = new ObjectNotFoundException(policyId + " does not exist");
            handler.onError(notFoundException);
            return Future.failed(notFoundException);
        }

        DeleteScalingPolicyResult resultSuccess = new DeleteScalingPolicyResult();
        HttpResponse successResponse = new HttpResponse(null, null);
        successResponse.setStatusCode(200);
        resultSuccess.setSdkHttpMetadata(SdkHttpMetadata.from(successResponse));

        isDeleted.set(true);
        handler.onSuccess(request, resultSuccess);
        return Future.successful(resultSuccess);
    });

    AssertableSubscriber<Void> firstCall = autoScalingClient.deleteScalingPolicy(policyId, jobId).test();
    firstCall.awaitTerminalEvent(2, TimeUnit.SECONDS);
    firstCall.assertNoErrors();
    firstCall.assertCompleted();
    verify(clientAsync, times(1)).deleteScalingPolicyAsync(any(), any());

    // second should complete fast when NotFound and not retry with exponential backoff
    AssertableSubscriber<Void> secondCall = autoScalingClient.deleteScalingPolicy(policyId, jobId).test();
    secondCall.awaitTerminalEvent(2, TimeUnit.SECONDS);
    secondCall.assertNoErrors();
    secondCall.assertCompleted();
    verify(clientAsync, times(2)).deleteScalingPolicyAsync(any(), any());
}
 
Example #8
Source File: AWSAppAutoScalingClientTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
@Test
public void deleteScalableTargetIsIdempotent() {
    String jobId = UUID.randomUUID().toString();
    String policyId = UUID.randomUUID().toString();

    AWSApplicationAutoScalingAsync clientAsync = mock(AWSApplicationAutoScalingAsync.class);
    AWSAppScalingConfig config = mock(AWSAppScalingConfig.class);
    AWSAppAutoScalingClient autoScalingClient = new AWSAppAutoScalingClient(clientAsync, config, new NoopRegistry());

    AtomicBoolean isDeleted = new AtomicBoolean(false);
    when(clientAsync.deregisterScalableTargetAsync(any(), any())).thenAnswer(invocation -> {
        DeregisterScalableTargetRequest request = invocation.getArgument(0);
        AsyncHandler<DeregisterScalableTargetRequest, DeregisterScalableTargetResult> handler = invocation.getArgument(1);
        if (isDeleted.get()) {
            ObjectNotFoundException notFoundException = new ObjectNotFoundException(policyId + " does not exist");
            handler.onError(notFoundException);
            return Future.failed(notFoundException);
        }

        DeregisterScalableTargetResult resultSuccess = new DeregisterScalableTargetResult();
        HttpResponse successResponse = new HttpResponse(null, null);
        successResponse.setStatusCode(200);
        resultSuccess.setSdkHttpMetadata(SdkHttpMetadata.from(successResponse));

        isDeleted.set(true);
        handler.onSuccess(request, resultSuccess);
        return Future.successful(resultSuccess);
    });

    AssertableSubscriber<Void> firstCall = autoScalingClient.deleteScalableTarget(jobId).test();
    firstCall.awaitTerminalEvent(2, TimeUnit.SECONDS);
    firstCall.assertNoErrors();
    firstCall.assertCompleted();
    verify(clientAsync, times(1)).deregisterScalableTargetAsync(any(), any());

    // second should complete fast when NotFound and not retry with exponential backoff
    AssertableSubscriber<Void> secondCall = autoScalingClient.deleteScalableTarget(jobId).test();
    secondCall.awaitTerminalEvent(2, TimeUnit.SECONDS);
    secondCall.assertNoErrors();
    secondCall.assertCompleted();
    verify(clientAsync, times(2)).deregisterScalableTargetAsync(any(), any());
}
 
Example #9
Source File: RateLimitedBatcherTest.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private RateLimitedBatcher<BatchableOperationMock, String> buildBatcher(long initialDelayMs, long maxDelayMs) {
    return RateLimitedBatcher.create(tokenBucket, initialDelayMs, maxDelayMs,
            BatchableOperationMock::getResourceId, strategy, "testBatcher", new NoopRegistry(), testScheduler);
}
 
Example #10
Source File: JedisPoolFactory.java    From kork with Apache License 2.0 4 votes vote down vote up
public JedisPoolFactory() {
  this(new NoopRegistry());
}
 
Example #11
Source File: InitTestModule.java    From zuul with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    bind(AbstractConfiguration.class).toInstance(ConfigurationManager.getConfigInstance());
    bind(FilenameFilter.class).toInstance((dir, name) -> false);
    bind(Registry.class).to(NoopRegistry.class);
}
 
Example #12
Source File: Evaluator.java    From spectator with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param commonTags
 *     Common tags that should be applied to all datapoints.
 * @param idMapper
 *     Function to convert an id to a map of key/value pairs.
 * @param step
 *     Step size used for the raw measurements.
 */
public Evaluator(Map<String, String> commonTags, Function<Id, Map<String, String>> idMapper, long step) {
  this.commonTags = commonTags;
  this.idMapper = idMapper;
  this.step = step;
  this.index = QueryIndex.newInstance(new NoopRegistry());
  this.subscriptions = new ConcurrentHashMap<>();
  this.consumers = new ThreadLocal<>();
}
 
Example #13
Source File: IntervalCounter.java    From spectator with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param registry
 *    Registry to use.
 * @param id
 *    Identifier for the metric being registered.
 * @return
 *    Counter instance.
 */
public static IntervalCounter get(Registry registry, Id id) {
  ConcurrentMap<Id, Object> state = registry.state();
  Object c = Utils.computeIfAbsent(state, id, i -> new IntervalCounter(registry, i));
  if (!(c instanceof IntervalCounter)) {
    Utils.propagateTypeError(registry, id, IntervalCounter.class, c.getClass());
    c = new IntervalCounter(new NoopRegistry(), id);
  }
  return (IntervalCounter) c;
}
 
Example #14
Source File: MetacatHMSHandler.java    From metacat with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param name client name
 * @param conf hive configurations
 * @throws MetaException exception
 */
public MetacatHMSHandler(final String name, final HiveConf conf) throws MetaException {
    this(name, conf, new NoopRegistry(), true);
}