Search in sources :

Example 1 with MeterView

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());
        }
    }
}
Also used : Counter(org.apache.flink.metrics.Counter) Meter(org.apache.flink.metrics.Meter) MetricGroup(org.apache.flink.metrics.MetricGroup) MeterView(org.apache.flink.metrics.MeterView)

Example 2 with MeterView

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));
}
Also used : Meter(org.apache.flink.metrics.Meter) MeterView(org.apache.flink.metrics.MeterView) Test(org.junit.jupiter.api.Test)

Example 3 with MeterView

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));
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) SimpleMonitoringInfoBuilder(org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder) Meter(org.apache.flink.metrics.Meter) MeterView(org.apache.flink.metrics.MeterView) MetricGroupTest(org.apache.flink.runtime.metrics.groups.MetricGroupTest) Test(org.junit.Test)

Example 4 with MeterView

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;
        }
    });
}
Also used : LongSerializer(org.apache.flink.api.common.typeutils.base.LongSerializer) Configuration(org.apache.flink.configuration.Configuration) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) WindowTimerServiceImpl(org.apache.flink.table.runtime.operators.window.slicing.WindowTimerServiceImpl) MeterView(org.apache.flink.metrics.MeterView) GeneratedJoinCondition(org.apache.flink.table.runtime.generated.GeneratedJoinCondition) JoinCondition(org.apache.flink.table.runtime.generated.JoinCondition) JoinConditionWithNullFilters(org.apache.flink.table.runtime.operators.join.JoinConditionWithNullFilters) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) InternalListState(org.apache.flink.runtime.state.internal.InternalListState)

Example 5 with MeterView

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;
        }
    });
}
Also used : GeneralWindowProcessFunction(org.apache.flink.table.runtime.operators.window.internal.GeneralWindowProcessFunction) LogicalType(org.apache.flink.table.types.logical.LogicalType) MeterView(org.apache.flink.metrics.MeterView) PanedWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.PanedWindowAssigner) MergingWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.MergingWindowAssigner) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) RowData(org.apache.flink.table.data.RowData) InternalValueState(org.apache.flink.runtime.state.internal.InternalValueState) ValueState(org.apache.flink.api.common.state.ValueState) PerWindowStateDataViewStore(org.apache.flink.table.runtime.dataview.PerWindowStateDataViewStore) PanedWindowProcessFunction(org.apache.flink.table.runtime.operators.window.internal.PanedWindowProcessFunction) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer)

Aggregations

MeterView (org.apache.flink.metrics.MeterView)6 Meter (org.apache.flink.metrics.Meter)3 Counter (org.apache.flink.metrics.Counter)2 RowData (org.apache.flink.table.data.RowData)2 MonitoringInfo (org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo)1 SimpleMonitoringInfoBuilder (org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder)1 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)1 ValueState (org.apache.flink.api.common.state.ValueState)1 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1 LongSerializer (org.apache.flink.api.common.typeutils.base.LongSerializer)1 Configuration (org.apache.flink.configuration.Configuration)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 SimpleCounter (org.apache.flink.metrics.SimpleCounter)1 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)1 InternalListState (org.apache.flink.runtime.state.internal.InternalListState)1 InternalValueState (org.apache.flink.runtime.state.internal.InternalValueState)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)1 PerWindowStateDataViewStore (org.apache.flink.table.runtime.dataview.PerWindowStateDataViewStore)1 GeneratedJoinCondition (org.apache.flink.table.runtime.generated.GeneratedJoinCondition)1