/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.beam.runners.flink;

import java.util.Map;
import org.apache.beam.model.jobmanagement.v1.JobApi;
import org.apache.beam.runners.fnexecution.jobsubmission.PortablePipelineResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Result of executing a portable {@link org.apache.beam.sdk.Pipeline} with Flink. */
public class FlinkPortableRunnerResult extends FlinkRunnerResult implements PortablePipelineResult {

  private static final Logger LOG = LoggerFactory.getLogger(FlinkPortableRunnerResult.class);

  FlinkPortableRunnerResult(Map<String, Object> accumulators, long runtime) {
    super(accumulators, runtime);
  }

  @Override
  public JobApi.MetricResults portableMetrics() throws UnsupportedOperationException {
    LOG.warn("Collecting monitoring infos is not implemented yet in Flink portable runner.");
    return JobApi.MetricResults.newBuilder().build();
  }

  static class Detached extends FlinkDetachedRunnerResult implements PortablePipelineResult {

    @Override
    public JobApi.MetricResults portableMetrics() throws UnsupportedOperationException {
      LOG.warn(
          "Collecting monitoring infos is not implemented yet in Flink portable runner (detached mode).");
      return JobApi.MetricResults.newBuilder().build();
    }
  }
}

@@ -915,16 +915,69 @@
 JobApi;%0A
+import org.apache.beam.model.pipeline.v1.MetricsApi;%0A
 import o
@@ -1615,28 +1615,43 @@
     
-LOG.warn(%22Collecting
+Iterable%3CMetricsApi.MonitoringInfo%3E
  mon
@@ -1661,67 +1661,81 @@
 ring
- i
+I
 nfos 
-is not implemented yet in Flink portable runner.%22
+=%0A        this.getMetricsContainerStepMap().getMonitoringInfos(
 );%0A
+%0A
     
@@ -1767,32 +1767,65 @@
 ts.newBuilder().
+addAllAttempted(monitoringInfos).
 build();%0A  %7D%0A%0A  

Return portable metrics from Flink runner