jk-shah opened a new issue, #41076:
URL: https://github.com/apache/beam/issues/41076

   ### What happened?
   
   Calling `DataflowMetrics.query()` (for example while polling a running 
Dataflow job where only `tentative='true'` metrics have been reported so far, 
or querying a completed job / metric entry where only the non-tentative 
`committed` entry is present in `get_job_metrics`) raises `KeyError: 
'committed'` or `KeyError: 'tentative'`.
   
   Minimal reproducer:
   
   ```python
   from types import SimpleNamespace
   from apache_beam.runners.dataflow.dataflow_metrics import DataflowMetrics
   
   response = SimpleNamespace(metrics=[
       SimpleNamespace(
           name=SimpleNamespace(
               origin='user',
               name='rows_read',
               context={'namespace': 'my_ns', 'tentative': 'true'},
           ),
           scalar=42,
           distribution=None,
       )
   ])
   
   dm = DataflowMetrics()
   out = []
   dm._populate_metrics(response, out, user_metrics=True)
   # KeyError: 'committed'
   
   
   
   ##Cause
   
   In sdks/python/apache_beam/runners/dataflow/dataflow_metrics.py (lines 
187–196), _get_metric_value explicitly handles None, but _populate_metrics 
indexes metric['tentative'] and metric['committed'] directly instead of using 
.get(...):
   
   ```python
       for metric_key, metric in metrics_by_name.items():
         attempted = self._get_metric_value(metric['tentative'])
         committed = self._get_metric_value(metric['committed'])
         result.append(
             MetricResult(metric_key, attempted=attempted, committed=committed))
   
   Replacing metric['tentative'] / metric['committed'] with 
metric.get('tentative') / metric.get('committed') resolves the crash cleanly.
   
   
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   - [ ] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [ ] Component: IO connector
   - [ ] Component: Beam YAML
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Infrastructure
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Prism Runner
   - [ ] Component: Hazelcast Jet Runner
   - [x] Component: Google Cloud Dataflow Runner


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to