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());
}
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);
}
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()));
}
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());
}
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());
}
Aggregations