use of org.apache.flink.metrics.Counter in project flink by apache.
the class OneInputStreamTask method init.
@Override
public void init() throws Exception {
StreamConfig configuration = getConfiguration();
int numberOfInputs = configuration.getNumberOfNetworkInputs();
if (numberOfInputs > 0) {
CheckpointedInputGate inputGate = createCheckpointedInputGate();
Counter numRecordsIn = setupNumRecordsInCounter(mainOperator);
DataOutput<IN> output = createDataOutput(numRecordsIn);
StreamTaskInput<IN> input = createTaskInput(inputGate);
StreamConfig.InputConfig[] inputConfigs = configuration.getInputs(getUserCodeClassLoader());
StreamConfig.InputConfig inputConfig = inputConfigs[0];
if (requiresSorting(inputConfig)) {
checkState(!configuration.isCheckpointingEnabled(), "Checkpointing is not allowed with sorted inputs.");
input = wrapWithSorted(input);
}
getEnvironment().getMetricGroup().getIOMetricGroup().reuseRecordsInputCounter(numRecordsIn);
inputProcessor = new StreamOneInputProcessor<>(input, output, operatorChain);
}
mainOperator.getMetricGroup().gauge(MetricNames.IO_CURRENT_INPUT_WATERMARK, inputWatermarkGauge);
// wrap watermark gauge since registered metrics must be unique
getEnvironment().getMetricGroup().gauge(MetricNames.IO_CURRENT_INPUT_WATERMARK, inputWatermarkGauge::getValue);
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class TwoInputStreamTaskTest method testOperatorMetricReuse.
@Test
public void testOperatorMetricReuse() throws Exception {
final TwoInputStreamTaskTestHarness<String, String, String> testHarness = new TwoInputStreamTaskTestHarness<>(TwoInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator()).chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).chain(new OperatorID(), new OneInputStreamTaskTest.DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).finish();
final TaskMetricGroup taskMetricGroup = TaskManagerMetricGroup.createTaskManagerMetricGroup(NoOpMetricRegistry.INSTANCE, "host", ResourceID.generate()).addJob(new JobID(), "jobname").addTask(new JobVertexID(), new ExecutionAttemptID(), "task", 0, 0);
final StreamMockEnvironment env = new StreamMockEnvironment(testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {
@Override
public TaskMetricGroup getMetricGroup() {
return taskMetricGroup;
}
};
final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();
testHarness.invoke(env);
testHarness.waitForTaskRunning();
final int numRecords1 = 5;
final int numRecords2 = 3;
for (int x = 0; x < numRecords1; x++) {
testHarness.processElement(new StreamRecord<>("hello"), 0, 0);
}
for (int x = 0; x < numRecords2; x++) {
testHarness.processElement(new StreamRecord<>("hello"), 1, 0);
}
testHarness.waitForInputProcessing();
assertEquals(numRecords1 + numRecords2, numRecordsInCounter.getCount());
assertEquals((numRecords1 + numRecords2) * 2 * 2 * 2, numRecordsOutCounter.getCount());
testHarness.endInput();
testHarness.waitForTaskCompletion();
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class MetricQueryServiceTest method testCreateDump.
@Test
public void testCreateDump() throws Exception {
MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), Long.MAX_VALUE);
queryService.start();
final Counter c = new SimpleCounter();
final Gauge<String> g = () -> "Hello";
final Histogram h = new TestHistogram();
final Meter m = new TestMeter();
final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();
queryService.addMetric("counter", c, tm);
queryService.addMetric("gauge", g, tm);
queryService.addMetric("histogram", h, tm);
queryService.addMetric("meter", m, tm);
MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();
assertTrue(dump.serializedCounters.length > 0);
assertTrue(dump.serializedGauges.length > 0);
assertTrue(dump.serializedHistograms.length > 0);
assertTrue(dump.serializedMeters.length > 0);
queryService.removeMetric(c);
queryService.removeMetric(g);
queryService.removeMetric(h);
queryService.removeMetric(m);
MetricDumpSerialization.MetricSerializationResult emptyDump = queryService.queryMetrics(TIMEOUT).get();
assertEquals(0, emptyDump.serializedCounters.length);
assertEquals(0, emptyDump.serializedGauges.length);
assertEquals(0, emptyDump.serializedHistograms.length);
assertEquals(0, emptyDump.serializedMeters.length);
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class OneInputStreamTaskTest method testOperatorMetricReuse.
@Test
public void testOperatorMetricReuse() throws Exception {
final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>(OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
testHarness.setupOperatorChain(new OperatorID(), new DuplicatingOperator()).chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).chain(new OperatorID(), new DuplicatingOperator(), BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).finish();
final TaskMetricGroup taskMetricGroup = TaskManagerMetricGroup.createTaskManagerMetricGroup(NoOpMetricRegistry.INSTANCE, "host", ResourceID.generate()).addJob(new JobID(), "jobname").addTask(new JobVertexID(), new ExecutionAttemptID(), "task", 0, 0);
final StreamMockEnvironment env = new StreamMockEnvironment(testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, new TestTaskStateManager()) {
@Override
public TaskMetricGroup getMetricGroup() {
return taskMetricGroup;
}
};
final Counter numRecordsInCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsInCounter();
final Counter numRecordsOutCounter = taskMetricGroup.getIOMetricGroup().getNumRecordsOutCounter();
testHarness.invoke(env);
testHarness.waitForTaskRunning();
final int numRecords = 5;
for (int x = 0; x < numRecords; x++) {
testHarness.processElement(new StreamRecord<>("hello"));
}
testHarness.waitForInputProcessing();
assertEquals(numRecords, numRecordsInCounter.getCount());
assertEquals(numRecords * 2 * 2 * 2, numRecordsOutCounter.getCount());
testHarness.endInput();
testHarness.waitForTaskCompletion();
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class InputChannelMetrics method createCounter.
private static Counter createCounter(String name, MetricGroup... parents) {
Counter[] counters = new Counter[parents.length];
for (int i = 0; i < parents.length; i++) {
counters[i] = parents[i].counter(name);
parents[i].meter(name + MetricNames.SUFFIX_RATE, new MeterView(counters[i]));
}
return new MultiCounterWrapper(counters);
}
Aggregations