Search in sources :

Example 41 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class SegmentStatusCheckerTest method missingIdealTest.

@Test
public void missingIdealTest() throws Exception {
    final String tableName = "myTable_REALTIME";
    List<String> allTableNames = new ArrayList<String>();
    allTableNames.add(tableName);
    IdealState idealState = null;
    HelixAdmin helixAdmin;
    {
        helixAdmin = mock(HelixAdmin.class);
        when(helixAdmin.getResourceIdealState("StatusChecker", tableName)).thenReturn(null);
        when(helixAdmin.getResourceExternalView("StatusChecker", tableName)).thenReturn(null);
    }
    {
        helixResourceManager = mock(PinotHelixResourceManager.class);
        when(helixResourceManager.isLeader()).thenReturn(true);
        when(helixResourceManager.getAllPinotTableNames()).thenReturn(allTableNames);
        when(helixResourceManager.getHelixClusterName()).thenReturn("StatusChecker");
        when(helixResourceManager.getHelixAdmin()).thenReturn(helixAdmin);
    }
    {
        config = mock(ControllerConf.class);
        when(config.getStatusCheckerFrequencyInSeconds()).thenReturn(300);
        when(config.getStatusCheckerWaitForPushTimeInSeconds()).thenReturn(300);
    }
    metricsRegistry = new MetricsRegistry();
    controllerMetrics = new ControllerMetrics(metricsRegistry);
    segmentStatusChecker = new SegmentStatusChecker(helixResourceManager, config);
    segmentStatusChecker.setMetricsRegistry(controllerMetrics);
    segmentStatusChecker.runSegmentMetrics();
    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);
    segmentStatusChecker.stop();
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) ArrayList(java.util.ArrayList) HelixAdmin(org.apache.helix.HelixAdmin) IdealState(org.apache.helix.model.IdealState) ControllerMetrics(com.linkedin.pinot.common.metrics.ControllerMetrics) Test(org.testng.annotations.Test)

Example 42 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class SegmentStatusCheckerTest method missingEVPartitionPushTest.

@Test
public void missingEVPartitionPushTest() throws Exception {
    final String tableName = "myTable_OFFLINE";
    List<String> allTableNames = new ArrayList<String>();
    allTableNames.add(tableName);
    IdealState idealState = new IdealState(tableName);
    idealState.setPartitionState("myTable_0", "pinot1", "ONLINE");
    idealState.setPartitionState("myTable_1", "pinot1", "ONLINE");
    idealState.setPartitionState("myTable_1", "pinot2", "ONLINE");
    idealState.setReplicas("2");
    idealState.setRebalanceMode(IdealState.RebalanceMode.CUSTOMIZED);
    ExternalView externalView = new ExternalView(tableName);
    externalView.setState("myTable_1", "pinot1", "ONLINE");
    externalView.setState("myTable_1", "pinot2", "ONLINE");
    HelixAdmin helixAdmin;
    {
        helixAdmin = mock(HelixAdmin.class);
        when(helixAdmin.getResourceIdealState("StatusChecker", "myTable_OFFLINE")).thenReturn(idealState);
        when(helixAdmin.getResourceExternalView("StatusChecker", "myTable_OFFLINE")).thenReturn(externalView);
    }
    ZNRecord znrecord = new ZNRecord("myTable_0");
    znrecord.setSimpleField(CommonConstants.Segment.SEGMENT_NAME, "myTable_0");
    znrecord.setSimpleField(CommonConstants.Segment.TABLE_NAME, "myTable_OFFLINE");
    znrecord.setSimpleField(CommonConstants.Segment.INDEX_VERSION, "v1");
    znrecord.setEnumField(CommonConstants.Segment.SEGMENT_TYPE, CommonConstants.Segment.SegmentType.OFFLINE);
    znrecord.setLongField(CommonConstants.Segment.START_TIME, 1000);
    znrecord.setLongField(CommonConstants.Segment.END_TIME, 2000);
    znrecord.setSimpleField(CommonConstants.Segment.TIME_UNIT, TimeUnit.HOURS.toString());
    znrecord.setLongField(CommonConstants.Segment.TOTAL_DOCS, 10000);
    znrecord.setLongField(CommonConstants.Segment.CRC, 1234);
    znrecord.setLongField(CommonConstants.Segment.CREATION_TIME, 3000);
    znrecord.setSimpleField(CommonConstants.Segment.Offline.DOWNLOAD_URL, "http://localhost:8000/myTable_0");
    znrecord.setLongField(CommonConstants.Segment.Offline.PUSH_TIME, System.currentTimeMillis());
    znrecord.setLongField(CommonConstants.Segment.Offline.REFRESH_TIME, System.currentTimeMillis());
    ZkHelixPropertyStore<ZNRecord> propertyStore;
    {
        propertyStore = (ZkHelixPropertyStore<ZNRecord>) mock(ZkHelixPropertyStore.class);
        when(propertyStore.get("/SEGMENTS/myTable_OFFLINE/myTable_0", null, AccessOption.PERSISTENT)).thenReturn(znrecord);
    }
    {
        helixResourceManager = mock(PinotHelixResourceManager.class);
        when(helixResourceManager.isLeader()).thenReturn(true);
        when(helixResourceManager.getAllPinotTableNames()).thenReturn(allTableNames);
        when(helixResourceManager.getHelixClusterName()).thenReturn("StatusChecker");
        when(helixResourceManager.getHelixAdmin()).thenReturn(helixAdmin);
        when(helixResourceManager.getPropertyStore()).thenReturn(propertyStore);
    }
    {
        config = mock(ControllerConf.class);
        when(config.getStatusCheckerFrequencyInSeconds()).thenReturn(300);
        when(config.getStatusCheckerWaitForPushTimeInSeconds()).thenReturn(300);
    }
    metricsRegistry = new MetricsRegistry();
    controllerMetrics = new ControllerMetrics(metricsRegistry);
    segmentStatusChecker = new SegmentStatusChecker(helixResourceManager, config);
    segmentStatusChecker.setMetricsRegistry(controllerMetrics);
    segmentStatusChecker.runSegmentMetrics();
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(), ControllerGauge.SEGMENTS_IN_ERROR_STATE), 0);
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(), ControllerGauge.NUMBER_OF_REPLICAS), 2);
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(), ControllerGauge.PERCENT_OF_REPLICAS), 100);
    Assert.assertEquals(controllerMetrics.getValueOfTableGauge(externalView.getId(), ControllerGauge.PERCENT_SEGMENTS_AVAILABLE), 100);
    segmentStatusChecker.stop();
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) ZkHelixPropertyStore(org.apache.helix.store.zk.ZkHelixPropertyStore) ArrayList(java.util.ArrayList) HelixAdmin(org.apache.helix.HelixAdmin) IdealState(org.apache.helix.model.IdealState) ZNRecord(org.apache.helix.ZNRecord) ControllerMetrics(com.linkedin.pinot.common.metrics.ControllerMetrics) Test(org.testng.annotations.Test)

Example 43 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class RealtimeSegmentImplTest method testDropInvalidRows.

@Test
public void testDropInvalidRows() throws Exception {
    Schema schema = new Schema.SchemaBuilder().setSchemaName("potato").addSingleValueDimension("dimension", FieldSpec.DataType.STRING).addMetric("metric", FieldSpec.DataType.LONG).addTime("time", TimeUnit.SECONDS, FieldSpec.DataType.LONG).build();
    RealtimeSegmentImpl realtimeSegment = createRealtimeSegmentImpl(schema, 100, "noTable", "noSegment", schema.getSchemaName(), new ServerMetrics(new MetricsRegistry()));
    // Segment should be empty
    Assert.assertEquals(realtimeSegment.getRawDocumentCount(), 0);
    Map<String, Object> genericRowContents = new HashMap<>();
    genericRowContents.put("dimension", "potato");
    genericRowContents.put("metric", 1234L);
    genericRowContents.put("time", 4567L);
    GenericRow row = new GenericRow();
    row.init(genericRowContents);
    // Add a valid row
    boolean notFull = realtimeSegment.index(row);
    Assert.assertEquals(notFull, true);
    Assert.assertEquals(realtimeSegment.getRawDocumentCount(), 1);
    // Add an invalid row
    genericRowContents.put("metric", null);
    notFull = realtimeSegment.index(row);
    Assert.assertEquals(notFull, true);
    Assert.assertEquals(realtimeSegment.getRawDocumentCount(), 1);
    // Add another valid row
    genericRowContents.put("metric", 2222L);
    notFull = realtimeSegment.index(row);
    Assert.assertEquals(notFull, true);
    Assert.assertEquals(realtimeSegment.getRawDocumentCount(), 2);
}
Also used : GenericRow(com.linkedin.pinot.core.data.GenericRow) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) HashMap(java.util.HashMap) Schema(com.linkedin.pinot.common.data.Schema) ServerMetrics(com.linkedin.pinot.common.metrics.ServerMetrics) RealtimeSegmentImpl(com.linkedin.pinot.core.realtime.impl.RealtimeSegmentImpl) Test(org.testng.annotations.Test)

Example 44 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project pinot by linkedin.

the class OfflineTableDataManagerTest method makeTestableManager.

private OfflineTableDataManager makeTestableManager() throws Exception {
    OfflineTableDataManager tableDataManager = new OfflineTableDataManager();
    TableDataManagerConfig config;
    {
        config = mock(TableDataManagerConfig.class);
        when(config.getTableName()).thenReturn(tableName);
        when(config.getDataDir()).thenReturn(_tmpDir.getAbsolutePath());
        when(config.getReadMode()).thenReturn(readMode.toString());
        when(config.getIndexLoadingConfigMetadata()).thenReturn(null);
    }
    tableDataManager.init(config, new ServerMetrics(new MetricsRegistry()), null);
    tableDataManager.start();
    Field segsMapField = AbstractTableDataManager.class.getDeclaredField("_segmentsMap");
    segsMapField.setAccessible(true);
    _internalSegMap = (Map<String, OfflineSegmentDataManager>) segsMapField.get(tableDataManager);
    return tableDataManager;
}
Also used : Field(java.lang.reflect.Field) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) OfflineSegmentDataManager(com.linkedin.pinot.core.data.manager.offline.OfflineSegmentDataManager) TableDataManagerConfig(com.linkedin.pinot.core.data.manager.config.TableDataManagerConfig) OfflineTableDataManager(com.linkedin.pinot.core.data.manager.offline.OfflineTableDataManager) ServerMetrics(com.linkedin.pinot.common.metrics.ServerMetrics)

Example 45 with MetricsRegistry

use of com.yammer.metrics.core.MetricsRegistry in project Dempsy by Dempsy.

the class TestStatsCollectorCoda method getStatValue.

@SuppressWarnings("unchecked")
long getStatValue(StatsCollectorCoda statCollector, String metricName) {
    MetricsRegistry metricReg = statCollector.getMetricsRegistry();
    Object meter = metricReg.allMetrics().get(statCollector.createName(metricName));
    if (com.yammer.metrics.core.Gauge.class.isAssignableFrom(meter.getClass()))
        return ((com.yammer.metrics.core.Gauge<Long>) metricReg.allMetrics().get(statCollector.createName(metricName))).value();
    else if (com.yammer.metrics.core.Histogram.class.isAssignableFrom(meter.getClass())) {
        final com.yammer.metrics.core.Histogram h = (com.yammer.metrics.core.Histogram) metricReg.allMetrics().get(statCollector.createName(metricName));
        return Math.round(h.count() * h.mean());
    } else
        return ((Metered) metricReg.allMetrics().get(statCollector.createName(metricName))).count();
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) Metered(com.yammer.metrics.core.Metered) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)45 Test (org.testng.annotations.Test)20 ServerMetrics (com.linkedin.pinot.common.metrics.ServerMetrics)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 ControllerMetrics (com.linkedin.pinot.common.metrics.ControllerMetrics)10 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)9 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)9 HelixAdmin (org.apache.helix.HelixAdmin)9 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)8 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)8 HashedWheelTimer (io.netty.util.HashedWheelTimer)8 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)8 IdealState (org.apache.helix.model.IdealState)8 BrokerMetrics (com.linkedin.pinot.common.metrics.BrokerMetrics)7 FileBasedInstanceDataManager (com.linkedin.pinot.core.data.manager.offline.FileBasedInstanceDataManager)6 NettyClientConnection (com.linkedin.pinot.transport.netty.NettyClientConnection)6 PooledNettyClientResourceManager (com.linkedin.pinot.transport.netty.PooledNettyClientResourceManager)6 EventLoopGroup (io.netty.channel.EventLoopGroup)6 HashMap (java.util.HashMap)6