Search in sources :

Example 1 with GenericMetricGroup

use of org.apache.flink.runtime.metrics.groups.GenericMetricGroup in project flink by apache.

the class RocksDBNativeMetricMonitorTest method testReturnsUnsigned.

@Test
public void testReturnsUnsigned() throws Throwable {
    RocksDBResource localRocksDBResource = new RocksDBResource();
    localRocksDBResource.before();
    SimpleMetricRegistry registry = new SimpleMetricRegistry();
    GenericMetricGroup group = new GenericMetricGroup(registry, UnregisteredMetricGroups.createUnregisteredTaskMetricGroup(), OPERATOR_NAME);
    RocksDBNativeMetricOptions options = new RocksDBNativeMetricOptions();
    options.enableSizeAllMemTables();
    RocksDBNativeMetricMonitor monitor = new RocksDBNativeMetricMonitor(options, group, localRocksDBResource.getRocksDB());
    ColumnFamilyHandle handle = rocksDBResource.createNewColumnFamily(COLUMN_FAMILY_NAME);
    monitor.registerColumnFamily(COLUMN_FAMILY_NAME, handle);
    RocksDBNativeMetricMonitor.RocksDBNativeMetricView view = registry.metrics.get(0);
    view.setValue(-1);
    BigInteger result = view.getValue();
    localRocksDBResource.after();
    Assert.assertEquals("Failed to interpret RocksDB result as an unsigned long", 1, result.signum());
}
Also used : BigInteger(java.math.BigInteger) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) Test(org.junit.Test)

Example 2 with GenericMetricGroup

use of org.apache.flink.runtime.metrics.groups.GenericMetricGroup in project flink by apache.

the class LatencyStatsTest method testLatencyStats.

private static void testLatencyStats(final LatencyStats.Granularity granularity, final Consumer<List<Tuple2<String, Histogram>>> verifier) {
    final AbstractMetricGroup<?> dummyGroup = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup();
    final List<Tuple2<String, Histogram>> latencyHistograms = new ArrayList<>(4);
    final TestingMetricRegistry registry = TestingMetricRegistry.builder().setRegisterConsumer((metric, metricName, group) -> {
        if (metric instanceof Histogram) {
            latencyHistograms.add(Tuple2.of(group.getMetricIdentifier(metricName), (Histogram) metric));
        }
    }).build();
    final MetricGroup parentGroup = new GenericMetricGroup(registry, dummyGroup, PARENT_GROUP_NAME);
    final LatencyStats latencyStats = new LatencyStats(parentGroup, MetricOptions.LATENCY_HISTORY_SIZE.defaultValue(), OPERATOR_SUBTASK_INDEX, OPERATOR_ID, granularity);
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 1));
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 2));
    latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 3));
    verifier.accept(latencyHistograms);
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) Test(org.junit.Test) MetricOptions(org.apache.flink.configuration.MetricOptions) Histogram(org.apache.flink.metrics.Histogram) ArrayList(java.util.ArrayList) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) Consumer(java.util.function.Consumer) MetricGroup(org.apache.flink.metrics.MetricGroup) List(java.util.List) UnregisteredMetricGroups(org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) TestLogger(org.apache.flink.util.TestLogger) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) Assert(org.junit.Assert) Histogram(org.apache.flink.metrics.Histogram) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) ArrayList(java.util.ArrayList) AbstractMetricGroup(org.apache.flink.runtime.metrics.groups.AbstractMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup)

Example 3 with GenericMetricGroup

use of org.apache.flink.runtime.metrics.groups.GenericMetricGroup in project flink by apache.

the class FlinkMetricContainerTest method testRegisterMetricGroup.

@Test
public void testRegisterMetricGroup() {
    MetricKey key = MetricKey.create("step", MetricName.named(DEFAULT_NAMESPACE, "name"));
    MetricRegistry registry = NoOpMetricRegistry.INSTANCE;
    GenericMetricGroup root = new GenericMetricGroup(registry, new MetricGroupTest.DummyAbstractMetricGroup(registry), "root");
    MetricGroup metricGroup = FlinkMetricContainer.registerMetricGroup(key, root);
    assertThat(metricGroup.getScopeComponents(), is(Arrays.asList("root", "key", "value").toArray()));
}
Also used : MetricKey(org.apache.beam.sdk.metrics.MetricKey) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) NoOpMetricRegistry(org.apache.flink.runtime.metrics.NoOpMetricRegistry) OperatorMetricGroup(org.apache.flink.metrics.groups.OperatorMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) Test(org.junit.Test)

Example 4 with GenericMetricGroup

use of org.apache.flink.runtime.metrics.groups.GenericMetricGroup in project flink by apache.

the class RocksDBNativeMetricMonitorTest method testClosedGaugesDontRead.

@Test
public void testClosedGaugesDontRead() {
    SimpleMetricRegistry registry = new SimpleMetricRegistry();
    GenericMetricGroup group = new GenericMetricGroup(registry, UnregisteredMetricGroups.createUnregisteredTaskMetricGroup(), OPERATOR_NAME);
    RocksDBNativeMetricOptions options = new RocksDBNativeMetricOptions();
    options.enableSizeAllMemTables();
    RocksDBNativeMetricMonitor monitor = new RocksDBNativeMetricMonitor(options, group, rocksDBResource.getRocksDB());
    ColumnFamilyHandle handle = rocksDBResource.createNewColumnFamily(COLUMN_FAMILY_NAME);
    monitor.registerColumnFamily(COLUMN_FAMILY_NAME, handle);
    RocksDBNativeMetricMonitor.RocksDBNativeMetricView view = registry.metrics.get(0);
    view.close();
    view.update();
    Assert.assertEquals("Closed gauge still queried RocksDB", BigInteger.ZERO, view.getValue());
}
Also used : GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) Test(org.junit.Test)

Example 5 with GenericMetricGroup

use of org.apache.flink.runtime.metrics.groups.GenericMetricGroup in project flink by apache.

the class RocksDBNativeMetricMonitorTest method testMetricMonitorLifecycle.

@Test
public void testMetricMonitorLifecycle() throws Throwable {
    // We use a local variable here to manually control the life-cycle.
    // This allows us to verify that metrics do not try to access
    // RocksDB after the monitor was closed.
    RocksDBResource localRocksDBResource = new RocksDBResource();
    localRocksDBResource.before();
    SimpleMetricRegistry registry = new SimpleMetricRegistry();
    GenericMetricGroup group = new GenericMetricGroup(registry, UnregisteredMetricGroups.createUnregisteredTaskMetricGroup(), OPERATOR_NAME);
    RocksDBNativeMetricOptions options = new RocksDBNativeMetricOptions();
    // always returns a non-zero
    // value since empty memtables
    // have overhead.
    options.enableSizeAllMemTables();
    RocksDBNativeMetricMonitor monitor = new RocksDBNativeMetricMonitor(options, group, localRocksDBResource.getRocksDB());
    ColumnFamilyHandle handle = localRocksDBResource.createNewColumnFamily(COLUMN_FAMILY_NAME);
    monitor.registerColumnFamily(COLUMN_FAMILY_NAME, handle);
    Assert.assertEquals("Failed to register metrics for column family", 1, registry.metrics.size());
    RocksDBNativeMetricMonitor.RocksDBNativeMetricView view = registry.metrics.get(0);
    view.update();
    Assert.assertNotEquals("Failed to pull metric from RocksDB", BigInteger.ZERO, view.getValue());
    view.setValue(0L);
    // After the monitor is closed no metric should be accessing RocksDB anymore.
    // If they do, then this test will likely fail with a segmentation fault.
    monitor.close();
    localRocksDBResource.after();
    view.update();
    Assert.assertEquals("Failed to release RocksDB reference", BigInteger.ZERO, view.getValue());
}
Also used : GenericMetricGroup(org.apache.flink.runtime.metrics.groups.GenericMetricGroup) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) Test(org.junit.Test)

Aggregations

GenericMetricGroup (org.apache.flink.runtime.metrics.groups.GenericMetricGroup)5 Test (org.junit.Test)5 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)3 MetricGroup (org.apache.flink.metrics.MetricGroup)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 MetricKey (org.apache.beam.sdk.metrics.MetricKey)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 MetricOptions (org.apache.flink.configuration.MetricOptions)1 Histogram (org.apache.flink.metrics.Histogram)1 OperatorMetricGroup (org.apache.flink.metrics.groups.OperatorMetricGroup)1 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)1 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)1 NoOpMetricRegistry (org.apache.flink.runtime.metrics.NoOpMetricRegistry)1 AbstractMetricGroup (org.apache.flink.runtime.metrics.groups.AbstractMetricGroup)1 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)1 UnregisteredMetricGroups (org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups)1 TestingMetricRegistry (org.apache.flink.runtime.metrics.util.TestingMetricRegistry)1