com.yammer.metrics.core.MetricsRegistry Java Examples

The following examples show how to use com.yammer.metrics.core.MetricsRegistry. 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: BaseTableDataManagerTest.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private TableDataManager makeTestableManager()
    throws Exception {
  TableDataManager tableDataManager = new OfflineTableDataManager();
  TableDataManagerConfig config;
  {
    config = mock(TableDataManagerConfig.class);
    when(config.getTableName()).thenReturn(TABLE_NAME);
    when(config.getDataDir()).thenReturn(_tmpDir.getAbsolutePath());
  }
  tableDataManager
      .init(config, "dummyInstance", mock(ZkHelixPropertyStore.class), new ServerMetrics(new MetricsRegistry()));
  tableDataManager.start();
  Field segsMapField = BaseTableDataManager.class.getDeclaredField("_segmentDataManagerMap");
  segsMapField.setAccessible(true);
  _internalSegMap = (Map<String, ImmutableSegmentDataManager>) segsMapField.get(tableDataManager);
  return tableDataManager;
}
 
Example #2
Source File: YammerExample.java    From signalfx-java with Apache License 2.0 6 votes vote down vote up
private static Metric getCumulativeCounter(MetricsRegistry metricsRegistry,
                                           MetricMetadata metricMetadata) {
    MetricName counterCallbackName = new MetricName(YammerExample.class, "yammer.test.cumulativeCounter");
    Metric cumulativeCounter = SfUtil.cumulativeCounter(
            metricsRegistry,
            counterCallbackName,
            metricMetadata,
            new Gauge<Long>() {

                private long i = 0;

                @Override
                public Long value() {
                    return i++;
                }

            });

    metricMetadata.forMetric(cumulativeCounter)
            .withSourceName(SIGNAL_FX)
            .withDimension(LIBRARY_VERSION, YAMMER);

    return cumulativeCounter;
}
 
Example #3
Source File: LeadControllerManagerTest.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void setup() {
  _controllerMetrics = new ControllerMetrics(new MetricsRegistry());
  _helixManager = mock(HelixManager.class);
  HelixDataAccessor helixDataAccessor = mock(HelixDataAccessor.class);
  when(_helixManager.getHelixDataAccessor()).thenReturn(helixDataAccessor);

  PropertyKey.Builder keyBuilder = mock(PropertyKey.Builder.class);
  when(helixDataAccessor.keyBuilder()).thenReturn(keyBuilder);

  PropertyKey controllerLeader = mock(PropertyKey.class);
  when(keyBuilder.controllerLeader()).thenReturn(controllerLeader);
  _liveInstance = mock(LiveInstance.class);
  when(helixDataAccessor.getProperty(controllerLeader)).thenReturn(_liveInstance);

  String instanceId = LeadControllerUtils.generateParticipantInstanceId(CONTROLLER_HOST, CONTROLLER_PORT);
  when(_helixManager.getInstanceName()).thenReturn(instanceId);

  ConfigAccessor configAccessor = mock(ConfigAccessor.class);
  when(_helixManager.getConfigAccessor()).thenReturn(configAccessor);
  _resourceConfig = mock(ResourceConfig.class);
  when(configAccessor.getResourceConfig(any(), anyString())).thenReturn(_resourceConfig);
}
 
Example #4
Source File: LiteralOnlyBrokerRequestTest.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Test
public void testBrokerRequestHandler()
    throws Exception {
  SingleConnectionBrokerRequestHandler requestHandler =
      new SingleConnectionBrokerRequestHandler(new PropertiesConfiguration(), null, null, null,
          new BrokerMetrics("", new MetricsRegistry(), false), null);
  long randNum = RANDOM.nextLong();
  byte[] randBytes = new byte[12];
  RANDOM.nextBytes(randBytes);
  String ranStr = BytesUtils.toHexString(randBytes);
  JsonNode request = new ObjectMapper().readTree(String.format("{\"sql\":\"SELECT %d, '%s'\"}", randNum, ranStr));
  RequestStatistics requestStats = new RequestStatistics();
  BrokerResponseNative brokerResponse =
      (BrokerResponseNative) requestHandler.handleRequest(request, null, requestStats);
  Assert.assertEquals(brokerResponse.getResultTable().getDataSchema().getColumnName(0), String.format("%d", randNum));
  Assert.assertEquals(brokerResponse.getResultTable().getDataSchema().getColumnDataType(0),
      DataSchema.ColumnDataType.LONG);
  Assert.assertEquals(brokerResponse.getResultTable().getDataSchema().getColumnName(1), ranStr);
  Assert.assertEquals(brokerResponse.getResultTable().getDataSchema().getColumnDataType(1),
      DataSchema.ColumnDataType.STRING);
  Assert.assertEquals(brokerResponse.getResultTable().getRows().size(), 1);
  Assert.assertEquals(brokerResponse.getResultTable().getRows().get(0).length, 2);
  Assert.assertEquals(brokerResponse.getResultTable().getRows().get(0)[0], randNum);
  Assert.assertEquals(brokerResponse.getResultTable().getRows().get(0)[1], ranStr);
  Assert.assertEquals(brokerResponse.getTotalDocs(), 0);
}
 
Example #5
Source File: CustomReporter.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link CustomReporter} for a given metrics registry.
 */
public CustomReporter(final MetricsRegistry metricsRegistry,
        final PrintStream out, final MetricPredicate predicate,
        final Clock clock, final TimeZone timeZone) {
    this(metricsRegistry, out, predicate, clock, timeZone, Locale
            .getDefault());
}
 
Example #6
Source File: MemoryReporter.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  try {
    MetricsRegistry registry = getMetricsRegistry();
    Map<MetricName, Metric> allMetrics = registry.allMetrics();
    for (Entry<MetricName, Metric> entry : allMetrics.entrySet()) {
      entry.getValue().processWith(this, entry.getKey(), _metrics);
    }
  } catch (Exception e) {
    LOG.error("Unknown error during metrics processing.", e);
  }
}
 
Example #7
Source File: CustomReporter.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link CustomReporter} for a given metrics registry.
 */
public CustomReporter(final MetricsRegistry metricsRegistry,
        final PrintStream out, final MetricPredicate predicate,
        final Clock clock, final TimeZone timeZone, final Locale locale) {
    super(metricsRegistry, "console-reporter");
    this.out = out;
    this.predicate = predicate;
    this.clock = clock;
    this.timeZone = timeZone;
    this.locale = locale;
}
 
Example #8
Source File: ScheduledReporter.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link ScheduledReporter} instance.
 *
 * @param registry
 *          the {@link com.codahale.metrics.MetricRegistry} containing the
 *          metrics this reporter will report
 * @param executor
 *          the executor to use while scheduling reporting of metrics.
 */
protected ScheduledReporter(MetricsRegistry registry, TimeUnit rateUnit, TimeUnit durationUnit,
    ScheduledExecutorService executor) {
  this.registry = registry;
  this.executor = executor;
  this.rateFactor = rateUnit.toSeconds(1);
  this.rateUnit = calculateRateUnit(rateUnit);
  this.durationFactor = 1.0 / durationUnit.toNanos(1);
  this.durationUnit = durationUnit.toString().toLowerCase(Locale.US);
}
 
Example #9
Source File: LLRealtimeSegmentDataManagerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private RealtimeTableDataManager createTableDataManager() {
  final String instanceId = "server-1";
  SegmentBuildTimeLeaseExtender.create(instanceId, new ServerMetrics(new MetricsRegistry()), _tableName);
  RealtimeTableDataManager tableDataManager = mock(RealtimeTableDataManager.class);
  when(tableDataManager.getServerInstance()).thenReturn(instanceId);
  RealtimeSegmentStatsHistory statsHistory = mock(RealtimeSegmentStatsHistory.class);
  when(statsHistory.getEstimatedCardinality(anyString())).thenReturn(200);
  when(statsHistory.getEstimatedAvgColSize(anyString())).thenReturn(32);
  when(tableDataManager.getStatsHistory()).thenReturn(statsHistory);
  return tableDataManager;
}
 
Example #10
Source File: CustomReporter.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link CustomReporter} for a given metrics registry.
 */
public CustomReporter(final MetricsRegistry metricsRegistry,
        final PrintStream out, final MetricPredicate predicate,
        final Clock clock, final TimeZone timeZone) {
    this(metricsRegistry, out, predicate, clock, timeZone, Locale
            .getDefault());
}
 
Example #11
Source File: CustomReporter.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link CustomReporter} for a given metrics registry.
 */
public CustomReporter(final MetricsRegistry metricsRegistry,
        final PrintStream out, final MetricPredicate predicate,
        final Clock clock, final TimeZone timeZone, final Locale locale) {
    super(metricsRegistry, "console-reporter");
    this.out = out;
    this.predicate = predicate;
    this.clock = clock;
    this.timeZone = timeZone;
    this.locale = locale;
}
 
Example #12
Source File: CustomReporter.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
/**
 * Enables the console reporter for the given metrics registry, and causes
 * it to print to STDOUT with the specified period and unrestricted output.
 */
public static void enable(final MetricsRegistry metricsRegistry,
        final long period, final TimeUnit unit) {
    final CustomReporter reporter = new CustomReporter(
            metricsRegistry, System.out, MetricPredicate.ALL);
    reporter.start(period, unit);
}
 
Example #13
Source File: SegmentGenerationWithNullValueVectorTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private void setupQueryServer()
    throws ConfigurationException {
  _segmentNames.add(_segment.getSegmentName());
  // Mock the instance data manager
  _serverMetrics = new ServerMetrics(new MetricsRegistry());
  TableDataManagerConfig tableDataManagerConfig = mock(TableDataManagerConfig.class);
  when(tableDataManagerConfig.getTableDataManagerType()).thenReturn("OFFLINE");
  when(tableDataManagerConfig.getTableName()).thenReturn(TABLE_NAME);
  when(tableDataManagerConfig.getDataDir()).thenReturn(FileUtils.getTempDirectoryPath());
  @SuppressWarnings("unchecked")
  TableDataManager tableDataManager = TableDataManagerProvider
      .getTableDataManager(tableDataManagerConfig, "testInstance", mock(ZkHelixPropertyStore.class),
          mock(ServerMetrics.class));
  tableDataManager.start();
  tableDataManager.addSegment(_segment);
  _instanceDataManager = mock(InstanceDataManager.class);
  when(_instanceDataManager.getTableDataManager(TABLE_NAME)).thenReturn(tableDataManager);

  // Set up the query executor
  URL resourceUrl = getClass().getClassLoader().getResource(QUERY_EXECUTOR_CONFIG_PATH);
  Assert.assertNotNull(resourceUrl);
  PropertiesConfiguration queryExecutorConfig = new PropertiesConfiguration();
  queryExecutorConfig.setDelimiterParsingDisabled(false);
  queryExecutorConfig.load(new File(resourceUrl.getFile()));
  _queryExecutor = new ServerQueryExecutorV1Impl();
  _queryExecutor.init(queryExecutorConfig, _instanceDataManager, _serverMetrics);
}
 
Example #14
Source File: YammerExample.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
private static Counter getCounter(MetricsRegistry metricsRegistry,
                                  MetricMetadata metricMetadata) {
    Counter counter = metricsRegistry.newCounter(YammerExample.class, "yammer.test.counter");
    metricMetadata.forMetric(counter)
            .withSourceName("signalFx")
            .withDimension(LIBRARY_VERSION, YAMMER);
    return counter;
}
 
Example #15
Source File: YammerExample.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
private static Timer getTimer(MetricsRegistry metricsRegistry, MetricMetadata metricMetadata) {
    Timer timer = metricsRegistry
            .newTimer(YammerExample.class, "yammer.test.timer", TimeUnit.MILLISECONDS, TimeUnit.SECONDS);
    metricMetadata.forMetric(timer)
            .withSourceName(SIGNAL_FX)
            .withDimension(LIBRARY_VERSION, YAMMER);
    return timer;
}
 
Example #16
Source File: YammerExample.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
private static Gauge getGauge(MetricsRegistry metricsRegistry, MetricMetadata metricMetadata) {
    Gauge gauge = metricsRegistry.newGauge(YammerExample.class, "yammer.test.gauge",
            new Gauge<Double>() {
                @Override
                public Double value() {
                    return Math.sin(System.currentTimeMillis() * 0.001 * 2 * Math.PI / 60);
                }
            });

    metricMetadata.forMetric(gauge)
            .withSourceName(SIGNAL_FX)
            .withDimension(LIBRARY_VERSION, YAMMER);
    return gauge;
}
 
Example #17
Source File: PinotQueryClient.java    From presto with Apache License 2.0 5 votes vote down vote up
public PinotQueryClient(PinotConfig config)
{
    requireNonNull(config, "config is null");
    prestoHostId = getDefaultPrestoId();
    MetricsRegistry registry = new MetricsRegistry();
    this.brokerMetrics = new BrokerMetrics(registry, DEFAULT_EMIT_TABLE_LEVEL_METRICS);
    brokerMetrics.initializeGlobalMeters();
    queryRouter = new QueryRouter(prestoHostId, brokerMetrics);
}
 
Example #18
Source File: SignalFxReporter.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
protected SignalFxReporter(MetricsRegistry registry, String name, MetricPredicate filter,
                             TimeUnit rateUnit, TimeUnit durationUnit,
                             AggregateMetricSender aggregateMetricSender,
                             Set<MetricDetails> detailsToAdd,
                             MetricMetadata metricMetadata) {
    this(registry, name, filter, rateUnit, durationUnit, aggregateMetricSender, detailsToAdd,
            metricMetadata, false, false, Collections.<String, String> emptyMap());
}
 
Example #19
Source File: SignalFxReporter.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
public SignalFxReporter(MetricsRegistry registry, String name, MetricPredicate filter,
                          TimeUnit rateUnit, TimeUnit durationUnit,
                          AggregateMetricSender aggregateMetricSender,
                          Set<MetricDetails> detailsToAdd, MetricMetadata metricMetadata,
                          boolean useLocalTime,
                          boolean sendExtraMetricDimensions,
                          Map<String, String> defaultDimensions) {
    super(registry, name, filter, rateUnit, durationUnit);
    this.aggregateMetricSender = aggregateMetricSender;
    this.useLocalTime = useLocalTime;
    this.detailsToAdd = detailsToAdd;
    this.metricMetadata = metricMetadata;
    this.sendExtraMetricDimensions = sendExtraMetricDimensions;
    this.defaultDimensions = ImmutableMap.copyOf(defaultDimensions);
}
 
Example #20
Source File: ControllerStarter.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public ControllerStarter(ControllerConf conf) {
  _config = conf;
  inferHostnameIfNeeded(_config);
  setupHelixSystemProperties();

  _controllerMode = conf.getControllerMode();
  // Helix related settings.
  _helixZkURL = HelixConfig.getAbsoluteZkPathForHelix(_config.getZkStr());
  _helixClusterName = _config.getHelixClusterName();
  _listenerConfigs = ListenerConfigUtil.buildListenerConfigs(_config);
  
  String host = conf.getControllerHost();
  int port = inferPort();
  
  _helixControllerInstanceId = host + "_" + port;
  _helixParticipantInstanceId = LeadControllerUtils.generateParticipantInstanceId(host, port);
  _isUpdateStateModel = _config.isUpdateSegmentStateModel();
  _enableBatchMessageMode = _config.getEnableBatchMessageMode();

  _metricsRegistry = new MetricsRegistry();
  _controllerMetrics = new ControllerMetrics(conf.getMetricsPrefix(), _metricsRegistry);
  _serviceStatusCallbackList = new ArrayList<>();
  if (_controllerMode == ControllerConf.ControllerMode.HELIX_ONLY) {
    _adminApp = null;
    _helixResourceManager = null;
    _executorService = null;
  } else {
    // Initialize FunctionRegistry before starting the admin application (PinotQueryResource requires it to compile
    // queries)
    FunctionRegistry.init();
    _adminApp = new ControllerAdminApiApplication();
    // Do not use this before the invocation of {@link PinotHelixResourceManager::start()}, which happens in {@link ControllerStarter::start()}
    _helixResourceManager = new PinotHelixResourceManager(_config);
    _executorService =
        Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("restapi-multiget-thread-%d").build());
  }
}
 
Example #21
Source File: StorageQuotaCheckerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() {
  _tableConfig =
      new TableConfigBuilder(TableType.OFFLINE).setTableName(OFFLINE_TABLE_NAME).setNumReplicas(NUM_REPLICAS).build();
  _tableSizeReader = mock(TableSizeReader.class);
  _controllerMetrics = new ControllerMetrics(new MetricsRegistry());
  _storageQuotaChecker = new StorageQuotaChecker(_tableConfig, _tableSizeReader, _controllerMetrics, true);
}
 
Example #22
Source File: SegmentStatusCheckerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Test
public void missingIdealTest()
    throws Exception {
  final String tableName = "myTable_REALTIME";
  List<String> allTableNames = new ArrayList<>();
  allTableNames.add(tableName);

  {
    helixResourceManager = mock(PinotHelixResourceManager.class);
    when(helixResourceManager.getAllTables()).thenReturn(allTableNames);
    when(helixResourceManager.getTableIdealState(tableName)).thenReturn(null);
    when(helixResourceManager.getTableExternalView(tableName)).thenReturn(null);
  }
  {
    config = mock(ControllerConf.class);
    when(config.getStatusCheckerFrequencyInSeconds()).thenReturn(300);
    when(config.getStatusCheckerWaitForPushTimeInSeconds()).thenReturn(300);
  }
  {
    leadControllerManager = mock(LeadControllerManager.class);
    when(leadControllerManager.isLeaderForTable(anyString())).thenReturn(true);
  }
  metricsRegistry = new MetricsRegistry();
  controllerMetrics = new ControllerMetrics(metricsRegistry);
  segmentStatusChecker =
      new SegmentStatusChecker(helixResourceManager, leadControllerManager, config, controllerMetrics);
  segmentStatusChecker.start();
  segmentStatusChecker.run();
  Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.SEGMENTS_IN_ERROR_STATE),
      Long.MIN_VALUE);
  Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.NUMBER_OF_REPLICAS),
      Long.MIN_VALUE);
  Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.PERCENT_OF_REPLICAS),
      Long.MIN_VALUE);
}
 
Example #23
Source File: SegmentStatusCheckerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Test
public void noReplicas()
    throws Exception {
  final String tableName = "myTable_REALTIME";
  List<String> allTableNames = new ArrayList<String>();
  allTableNames.add(tableName);
  IdealState idealState = new IdealState(tableName);
  idealState.setPartitionState("myTable_0", "pinot1", "OFFLINE");
  idealState.setPartitionState("myTable_0", "pinot2", "OFFLINE");
  idealState.setPartitionState("myTable_0", "pinot3", "OFFLINE");
  idealState.setReplicas("0");
  idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);

  {
    helixResourceManager = mock(PinotHelixResourceManager.class);
    when(helixResourceManager.getAllTables()).thenReturn(allTableNames);
    when(helixResourceManager.getTableIdealState(tableName)).thenReturn(idealState);
    when(helixResourceManager.getTableExternalView(tableName)).thenReturn(null);
  }
  {
    config = mock(ControllerConf.class);
    when(config.getStatusCheckerFrequencyInSeconds()).thenReturn(300);
    when(config.getStatusCheckerWaitForPushTimeInSeconds()).thenReturn(300);
  }
  {
    leadControllerManager = mock(LeadControllerManager.class);
    when(leadControllerManager.isLeaderForTable(anyString())).thenReturn(true);
  }
  metricsRegistry = new MetricsRegistry();
  controllerMetrics = new ControllerMetrics(metricsRegistry);
  segmentStatusChecker =
      new SegmentStatusChecker(helixResourceManager, leadControllerManager, config, controllerMetrics);
  segmentStatusChecker.start();
  segmentStatusChecker.run();
  Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.SEGMENTS_IN_ERROR_STATE), 0);
  Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.NUMBER_OF_REPLICAS), 1);
  Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.PERCENT_OF_REPLICAS), 100);
  Assert.assertEquals(controllerMetrics.getValueOfTableGauge(tableName, ControllerGauge.PERCENT_SEGMENTS_AVAILABLE),
      100);
}
 
Example #24
Source File: SegmentStatusCheckerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Test
public void disabledEmptyTableTest()
    throws Exception {

  final String tableName = "myTable_OFFLINE";
  List<String> allTableNames = Lists.newArrayList(tableName);
  IdealState idealState = new IdealState(tableName);
  // disable table in idealstate
  idealState.enable(false);
  idealState.setReplicas("1");
  idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);

  {
    helixResourceManager = mock(PinotHelixResourceManager.class);
    when(helixResourceManager.getAllTables()).thenReturn(allTableNames);
    when(helixResourceManager.getTableIdealState(tableName)).thenReturn(idealState);
    when(helixResourceManager.getTableExternalView(tableName)).thenReturn(null);
  }
  {
    config = mock(ControllerConf.class);
    when(config.getStatusCheckerFrequencyInSeconds()).thenReturn(300);
    when(config.getStatusCheckerWaitForPushTimeInSeconds()).thenReturn(300);
  }
  {
    leadControllerManager = mock(LeadControllerManager.class);
    when(leadControllerManager.isLeaderForTable(anyString())).thenReturn(true);
  }
  metricsRegistry = new MetricsRegistry();
  controllerMetrics = new ControllerMetrics(metricsRegistry);
  segmentStatusChecker =
      new SegmentStatusChecker(helixResourceManager, leadControllerManager, config, controllerMetrics);
  // verify state before test
  Assert.assertEquals(controllerMetrics.getValueOfGlobalGauge(ControllerGauge.DISABLED_TABLE_COUNT), 0);
  // update metrics
  segmentStatusChecker.start();
  segmentStatusChecker.run();
  Assert.assertEquals(controllerMetrics.getValueOfGlobalGauge(ControllerGauge.DISABLED_TABLE_COUNT), 1);
}
 
Example #25
Source File: RetentionManagerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Test
public void testRealtimeLLCCleanup()
    throws Exception {
  final int initialNumSegments = 8;
  final long now = System.currentTimeMillis();

  final int replicaCount = 1;

  TableConfig tableConfig = createRealtimeTableConfig1(replicaCount);
  List<String> removedSegments = new ArrayList<>();
  PinotHelixResourceManager pinotHelixResourceManager =
      setupSegmentMetadata(tableConfig, now, initialNumSegments, removedSegments);
  setupPinotHelixResourceManager(tableConfig, removedSegments, pinotHelixResourceManager);

  LeadControllerManager leadControllerManager = mock(LeadControllerManager.class);
  when(leadControllerManager.isLeaderForTable(anyString())).thenReturn(true);

  ControllerConf conf = new ControllerConf();
  ControllerMetrics controllerMetrics = new ControllerMetrics(new MetricsRegistry());
  conf.setRetentionControllerFrequencyInSeconds(0);
  conf.setDeletedSegmentsRetentionInDays(0);
  RetentionManager retentionManager =
      new RetentionManager(pinotHelixResourceManager, leadControllerManager, conf, controllerMetrics);
  retentionManager.start();
  retentionManager.run();

  SegmentDeletionManager deletionManager = pinotHelixResourceManager.getSegmentDeletionManager();

  // Verify that the removeAgedDeletedSegments() method in deletion manager is actually called.
  verify(deletionManager, times(1)).removeAgedDeletedSegments(anyInt());

  // Verify that the deleteSegments method is actually called.
  verify(pinotHelixResourceManager, times(1)).deleteSegments(anyString(), anyList());
}
 
Example #26
Source File: MetricsHelper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a metrics registry registration listener. When adding a metrics registry registration listener, events are
 * fired to add all previously registered metrics registries to the newly added metrics registry registration
 * listener.
 *
 * @param listener The listener to add
 */
public static void addMetricsRegistryRegistrationListener(MetricsRegistryRegistrationListener listener) {
  synchronized (MetricsHelper.class) {
    metricsRegistryRegistrationListenersMap.put(listener, null);

    // Fire events to register all previously registered metrics registries
    Set<MetricsRegistry> metricsRegistries = metricsRegistryMap.keySet();
    for (MetricsRegistry metricsRegistry : metricsRegistries) {
      listener.onMetricsRegistryRegistered(metricsRegistry);
    }
  }
}
 
Example #27
Source File: MetricsHelper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the metrics registry with the metrics helper.
 *
 * @param registry The registry to register
 */
public static void registerMetricsRegistry(MetricsRegistry registry) {
  synchronized (MetricsHelper.class) {
    metricsRegistryMap.put(registry, null);

    // Fire event to all registered listeners
    Set<MetricsRegistryRegistrationListener> metricsRegistryRegistrationListeners =
        metricsRegistryRegistrationListenersMap.keySet();
    for (MetricsRegistryRegistrationListener metricsRegistryRegistrationListener : metricsRegistryRegistrationListeners) {
      metricsRegistryRegistrationListener.onMetricsRegistryRegistered(registry);
    }
  }
}
 
Example #28
Source File: MetricsHelper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Removes an existing metric
 */
public static void removeMetric(MetricsRegistry registry, MetricName name) {
  if (registry != null) {
    registry.removeMetric(name);
  } else {
    Metrics.defaultRegistry().removeMetric(name);
  }
}
 
Example #29
Source File: CustomReporter.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Enables the console reporter for the given metrics registry, and causes
 * it to print to STDOUT with the specified period and unrestricted output.
 */
public static void enable(final MetricsRegistry metricsRegistry,
        final long period, final TimeUnit unit) {
    final CustomReporter reporter = new CustomReporter(
            metricsRegistry, System.out, MetricPredicate.ALL);
    reporter.start(period, unit);
}
 
Example #30
Source File: HelixBrokerStarter.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public MetricsRegistry getMetricsRegistry() {
  return _metricsRegistry;
}