use of org.apache.flink.metrics.MeterView in project flink by apache.
the class FlinkMetricContainer method updateCounterOrMeter.
private void updateCounterOrMeter(Iterable<MetricResult<Long>> counters) {
for (MetricResult<Long> metricResult : counters) {
if (!isUserMetric(metricResult)) {
continue;
}
// get identifier
String flinkMetricIdentifier = getFlinkMetricIdentifierString(metricResult.getKey());
// get metric type
ArrayList<String> scopeComponents = getNameSpaceArray(metricResult.getKey());
if ((scopeComponents.size() % 2) != 0) {
Meter meter = flinkMeterCache.get(flinkMetricIdentifier);
if (null == meter) {
int timeSpanInSeconds = Integer.parseInt(scopeComponents.get(scopeComponents.size() - 1));
MetricGroup metricGroup = registerMetricGroup(metricResult.getKey(), baseMetricGroup);
meter = metricGroup.meter(metricResult.getKey().metricName().getName(), new MeterView(timeSpanInSeconds));
flinkMeterCache.put(flinkMetricIdentifier, meter);
}
Long update = metricResult.getAttempted();
meter.markEvent(update - meter.getCount());
} else {
Counter counter = flinkCounterCache.get(flinkMetricIdentifier);
if (null == counter) {
MetricGroup metricGroup = registerMetricGroup(metricResult.getKey(), baseMetricGroup);
counter = metricGroup.counter(metricResult.getKey().metricName().getName());
flinkCounterCache.put(flinkMetricIdentifier, counter);
}
Long update = metricResult.getAttempted();
counter.inc(update - counter.getCount());
}
}
}
use of org.apache.flink.metrics.MeterView in project flink by apache.
the class Slf4jReporterTest method testAddMeter.
@Test
void testAddMeter() throws Exception {
String meterName = "meter";
Meter meter = new MeterView(5);
reporter.notifyOfAddedMetric(meter, meterName, metricGroup);
assertThat(reporter.getMeters()).containsKey(meter);
String expectedMeterReport = reporter.filterCharacters(SCOPE) + delimiter + reporter.filterCharacters(meterName) + ": 0.0";
reporter.report();
assertThat(testLoggerResource.getMessages()).anyMatch(logOutput -> logOutput.contains(expectedMeterReport));
}
use of org.apache.flink.metrics.MeterView in project flink by apache.
the class FlinkMetricContainerTest method testMeterMonitoringInfoUpdate.
@Test
public void testMeterMonitoringInfoUpdate() {
MeterView userMeter = new MeterView(new SimpleCounter());
when(metricGroup.meter(eq("myMeter"), any(Meter.class))).thenReturn(userMeter);
String namespace = "[\"key\", \"value\", \"MetricGroupType.key\", \"MetricGroupType.value\", \"60\"]";
MonitoringInfo userMonitoringInfo = new SimpleMonitoringInfoBuilder().setUrn(MonitoringInfoConstants.Urns.USER_SUM_INT64).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, namespace).setLabel(MonitoringInfoConstants.Labels.NAME, "myMeter").setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "anyPTransform").setInt64SumValue(111).build();
assertThat(userMeter.getCount(), is(0L));
assertThat(userMeter.getRate(), is(0.0));
container.updateMetrics("step", ImmutableList.of(userMonitoringInfo));
userMeter.update();
assertThat(userMeter.getCount(), is(111L));
// 111 div 60 = 1.85
assertThat(userMeter.getRate(), is(1.85));
}
use of org.apache.flink.metrics.MeterView in project flink by apache.
the class WindowJoinOperator method open.
@Override
public void open() throws Exception {
super.open();
this.collector = new TimestampedCollector<>(output);
collector.eraseTimestamp();
final LongSerializer windowSerializer = LongSerializer.INSTANCE;
InternalTimerService<Long> internalTimerService = getInternalTimerService("window-timers", windowSerializer, this);
this.windowTimerService = new WindowTimerServiceImpl(internalTimerService, shiftTimeZone);
// init join condition
JoinCondition condition = generatedJoinCondition.newInstance(getRuntimeContext().getUserCodeClassLoader());
this.joinCondition = new JoinConditionWithNullFilters(condition, filterNullKeys, this);
this.joinCondition.setRuntimeContext(getRuntimeContext());
this.joinCondition.open(new Configuration());
// init state
ListStateDescriptor<RowData> leftRecordStateDesc = new ListStateDescriptor<>(LEFT_RECORDS_STATE_NAME, leftSerializer);
ListState<RowData> leftListState = getOrCreateKeyedState(windowSerializer, leftRecordStateDesc);
this.leftWindowState = new WindowListState<>((InternalListState<RowData, Long, RowData>) leftListState);
ListStateDescriptor<RowData> rightRecordStateDesc = new ListStateDescriptor<>(RIGHT_RECORDS_STATE_NAME, rightSerializer);
ListState<RowData> rightListState = getOrCreateKeyedState(windowSerializer, rightRecordStateDesc);
this.rightWindowState = new WindowListState<>((InternalListState<RowData, Long, RowData>) rightListState);
// metrics
this.leftNumLateRecordsDropped = metrics.counter(LEFT_LATE_ELEMENTS_DROPPED_METRIC_NAME);
this.leftLateRecordsDroppedRate = metrics.meter(LEFT_LATE_ELEMENTS_DROPPED_RATE_METRIC_NAME, new MeterView(leftNumLateRecordsDropped));
this.rightNumLateRecordsDropped = metrics.counter(RIGHT_LATE_ELEMENTS_DROPPED_METRIC_NAME);
this.rightLateRecordsDroppedRate = metrics.meter(RIGHT_LATE_ELEMENTS_DROPPED_RATE_METRIC_NAME, new MeterView(rightNumLateRecordsDropped));
this.watermarkLatency = metrics.gauge(WATERMARK_LATENCY_METRIC_NAME, () -> {
long watermark = windowTimerService.currentWatermark();
if (watermark < 0) {
return 0L;
} else {
return windowTimerService.currentProcessingTime() - watermark;
}
});
}
use of org.apache.flink.metrics.MeterView in project flink by apache.
the class WindowOperator method open.
@Override
public void open() throws Exception {
super.open();
collector = new TimestampedCollector<>(output);
collector.eraseTimestamp();
internalTimerService = getInternalTimerService("window-timers", windowSerializer, this);
triggerContext = new TriggerContext();
triggerContext.open();
StateDescriptor<ValueState<RowData>, RowData> windowStateDescriptor = new ValueStateDescriptor<>("window-aggs", new RowDataSerializer(accumulatorTypes));
this.windowState = (InternalValueState<K, W, RowData>) getOrCreateKeyedState(windowSerializer, windowStateDescriptor);
if (produceUpdates) {
LogicalType[] valueTypes = ArrayUtils.addAll(aggResultTypes, windowPropertyTypes);
StateDescriptor<ValueState<RowData>, RowData> previousStateDescriptor = new ValueStateDescriptor<>("previous-aggs", new RowDataSerializer(valueTypes));
this.previousState = (InternalValueState<K, W, RowData>) getOrCreateKeyedState(windowSerializer, previousStateDescriptor);
}
compileGeneratedCode();
WindowContext windowContext = new WindowContext();
windowAggregator.open(new PerWindowStateDataViewStore(getKeyedStateBackend(), windowSerializer, getRuntimeContext()));
if (windowAssigner instanceof MergingWindowAssigner) {
this.windowFunction = new MergingWindowProcessFunction<>((MergingWindowAssigner<W>) windowAssigner, windowAggregator, windowSerializer, allowedLateness);
} else if (windowAssigner instanceof PanedWindowAssigner) {
this.windowFunction = new PanedWindowProcessFunction<>((PanedWindowAssigner<W>) windowAssigner, windowAggregator, allowedLateness);
} else {
this.windowFunction = new GeneralWindowProcessFunction<>(windowAssigner, windowAggregator, allowedLateness);
}
windowFunction.open(windowContext);
// metrics
this.numLateRecordsDropped = metrics.counter(LATE_ELEMENTS_DROPPED_METRIC_NAME);
this.lateRecordsDroppedRate = metrics.meter(LATE_ELEMENTS_DROPPED_RATE_METRIC_NAME, new MeterView(numLateRecordsDropped));
this.watermarkLatency = metrics.gauge(WATERMARK_LATENCY_METRIC_NAME, () -> {
long watermark = internalTimerService.currentWatermark();
if (watermark < 0) {
return 0L;
} else {
return internalTimerService.currentProcessingTime() - watermark;
}
});
}
Aggregations