use of org.apache.flink.metrics.Counter in project flink by apache.
the class AbstractOuterJoinDriver method run.
@Override
public void run() throws Exception {
final Counter numRecordsOut = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();
final FlatJoinFunction<IT1, IT2, OT> joinStub = this.taskContext.getStub();
final Collector<OT> collector = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);
final JoinTaskIterator<IT1, IT2, OT> outerJoinIterator = this.outerJoinIterator;
while (this.running && outerJoinIterator.callWithNextKey(joinStub, collector)) {
}
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class MetricGroupRegistrationTest method testMetricInstantiation.
/**
* Verifies that group methods instantiate the correct metric with the given name.
*/
@Test
public void testMetricInstantiation() throws Exception {
MetricRegistryImpl registry = new MetricRegistryImpl(MetricRegistryTestUtils.defaultMetricRegistryConfiguration(), Collections.singletonList(ReporterSetup.forReporter("test", new TestReporter1())));
MetricGroup root = TaskManagerMetricGroup.createTaskManagerMetricGroup(registry, "host", new ResourceID("id"));
Counter counter = root.counter("counter");
assertEquals(counter, TestReporter1.lastPassedMetric);
assertEquals("counter", TestReporter1.lastPassedName);
Gauge<Object> gauge = root.gauge("gauge", new Gauge<Object>() {
@Override
public Object getValue() {
return null;
}
});
Assert.assertEquals(gauge, TestReporter1.lastPassedMetric);
assertEquals("gauge", TestReporter1.lastPassedName);
Histogram histogram = root.histogram("histogram", new Histogram() {
@Override
public void update(long value) {
}
@Override
public long getCount() {
return 0;
}
@Override
public HistogramStatistics getStatistics() {
return null;
}
});
Assert.assertEquals(histogram, TestReporter1.lastPassedMetric);
assertEquals("histogram", TestReporter1.lastPassedName);
registry.shutdown().get();
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class MetricFetcherTest method createRequestDumpAnswer.
private static MetricDumpSerialization.MetricSerializationResult createRequestDumpAnswer(ResourceID tmRID, JobID jobID) {
Map<Counter, Tuple2<QueryScopeInfo, String>> counters = new HashMap<>();
Map<Gauge<?>, Tuple2<QueryScopeInfo, String>> gauges = new HashMap<>();
Map<Histogram, Tuple2<QueryScopeInfo, String>> histograms = new HashMap<>();
Map<Meter, Tuple2<QueryScopeInfo, String>> meters = new HashMap<>();
SimpleCounter c1 = new SimpleCounter();
SimpleCounter c2 = new SimpleCounter();
c1.inc(1);
c2.inc(2);
counters.put(c1, new Tuple2<>(new QueryScopeInfo.OperatorQueryScopeInfo(jobID.toString(), "taskid", 2, "opname", "abc"), "oc"));
counters.put(c2, new Tuple2<>(new QueryScopeInfo.TaskQueryScopeInfo(jobID.toString(), "taskid", 2, "abc"), "tc"));
meters.put(new Meter() {
@Override
public void markEvent() {
}
@Override
public void markEvent(long n) {
}
@Override
public double getRate() {
return 5;
}
@Override
public long getCount() {
return 10;
}
}, new Tuple2<>(new QueryScopeInfo.JobQueryScopeInfo(jobID.toString(), "abc"), "jc"));
gauges.put(new Gauge<String>() {
@Override
public String getValue() {
return "x";
}
}, new Tuple2<>(new QueryScopeInfo.TaskManagerQueryScopeInfo(tmRID.toString(), "abc"), "gauge"));
histograms.put(new TestHistogram(), new Tuple2<>(new QueryScopeInfo.JobManagerQueryScopeInfo("abc"), "hist"));
MetricDumpSerialization.MetricDumpSerializer serializer = new MetricDumpSerialization.MetricDumpSerializer();
MetricDumpSerialization.MetricSerializationResult dump = serializer.serialize(counters, gauges, histograms, meters);
serializer.close();
return dump;
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class ChainedOperatorsMetricTest method testOperatorIOMetricReuse.
@Test
public void testOperatorIOMetricReuse() throws Exception {
// environment
initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
this.mockEnv = new MockEnvironmentBuilder().setTaskName(HEAD_OPERATOR_NAME).setManagedMemorySize(MEMORY_MANAGER_SIZE).setInputSplitProvider(this.inputSplitProvider).setBufferSize(NETWORK_BUFFER_SIZE).setMetricGroup(TaskManagerMetricGroup.createTaskManagerMetricGroup(NoOpMetricRegistry.INSTANCE, "host", ResourceID.generate()).addJob(new JobID(), "jobName").addTask(new JobVertexID(), new ExecutionAttemptID(), "task", 0, 0)).build();
final int keyCnt = 100;
final int valCnt = 20;
final int numRecords = keyCnt * valCnt;
addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
addOutput(this.outList);
// the chained operator
addChainedOperator();
// creates the head operator and assembles the chain
registerTask(FlatMapDriver.class, DuplicatingFlatMapFunction.class);
final BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(this.mockEnv);
testTask.invoke();
Assert.assertEquals(numRecords * 2 * 2, this.outList.size());
final TaskMetricGroup taskMetricGroup = mockEnv.getMetricGroup();
// verify task-level metrics
{
final TaskIOMetricGroup ioMetricGroup = taskMetricGroup.getIOMetricGroup();
final Counter numRecordsInCounter = ioMetricGroup.getNumRecordsInCounter();
final Counter numRecordsOutCounter = ioMetricGroup.getNumRecordsOutCounter();
Assert.assertEquals(numRecords, numRecordsInCounter.getCount());
Assert.assertEquals(numRecords * 2 * 2, numRecordsOutCounter.getCount());
}
// verify head operator metrics
{
// this only returns the existing group and doesn't create a new one
final OperatorMetricGroup operatorMetricGroup1 = taskMetricGroup.getOrAddOperator(HEAD_OPERATOR_NAME);
final OperatorIOMetricGroup ioMetricGroup = operatorMetricGroup1.getIOMetricGroup();
final Counter numRecordsInCounter = ioMetricGroup.getNumRecordsInCounter();
final Counter numRecordsOutCounter = ioMetricGroup.getNumRecordsOutCounter();
Assert.assertEquals(numRecords, numRecordsInCounter.getCount());
Assert.assertEquals(numRecords * 2, numRecordsOutCounter.getCount());
}
// verify chained operator metrics
{
// this only returns the existing group and doesn't create a new one
final InternalOperatorMetricGroup operatorMetricGroup1 = taskMetricGroup.getOrAddOperator(CHAINED_OPERATOR_NAME);
final InternalOperatorIOMetricGroup ioMetricGroup = operatorMetricGroup1.getIOMetricGroup();
final Counter numRecordsInCounter = ioMetricGroup.getNumRecordsInCounter();
final Counter numRecordsOutCounter = ioMetricGroup.getNumRecordsOutCounter();
Assert.assertEquals(numRecords * 2, numRecordsInCounter.getCount());
Assert.assertEquals(numRecords * 2 * 2, numRecordsOutCounter.getCount());
}
}
use of org.apache.flink.metrics.Counter in project flink by apache.
the class ElasticsearchWriterITCase method testIncrementByteOutMetric.
@Test
void testIncrementByteOutMetric() throws Exception {
final String index = "test-inc-byte-out";
final OperatorIOMetricGroup operatorIOMetricGroup = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup().getIOMetricGroup();
final InternalSinkWriterMetricGroup metricGroup = InternalSinkWriterMetricGroup.mock(metricListener.getMetricGroup(), operatorIOMetricGroup);
final int flushAfterNActions = 2;
final BulkProcessorConfig bulkProcessorConfig = new BulkProcessorConfig(flushAfterNActions, -1, -1, FlushBackoffType.NONE, 0, 0);
try (final ElasticsearchWriter<Tuple2<Integer, String>> writer = createWriter(index, false, bulkProcessorConfig, metricGroup)) {
final Counter numBytesOut = operatorIOMetricGroup.getNumBytesOutCounter();
assertEquals(numBytesOut.getCount(), 0);
writer.write(Tuple2.of(1, buildMessage(1)), null);
writer.write(Tuple2.of(2, buildMessage(2)), null);
writer.blockingFlushAllActions();
long first = numBytesOut.getCount();
assertTrue(first > 0);
writer.write(Tuple2.of(1, buildMessage(1)), null);
writer.write(Tuple2.of(2, buildMessage(2)), null);
writer.blockingFlushAllActions();
assertTrue(numBytesOut.getCount() > first);
}
}
Aggregations