prodriguezdefino opened a new pull request, #41708:
URL: https://github.com/apache/beam/pull/41708
Problem:
In `buildUrnToOpsMap`
(`sdks/go/pkg/beam/runners/prism/internal/jobservices/metrics.go`),
`typ2accumFac` registers accumulators for counters, distributions, gauges,
top-N, bottom-N, string sets, and progress metrics, but omits
`MonitoringInfoTypeUrns_BOUNDED_TRIE_TYPE` (`beam:metrics:bounded_trie:v1`) and
`MonitoringInfoTypeUrns_HISTOGRAM` (`beam:metrics:histogram_int64:v1`).
When `AddShortIDs` resolves a metric with either type URN, `metricsStore`
logs an unknown short-ID debug message, creates no accumulator, drops every
update in `contributeMetrics`, and omits the metric from `GetJobMetrics`.
Python's `PrismRunnerTest` disables bounded trie checks with
`check_bounded_trie=False`, and Java's Prism build excludes
`UsesBoundedTrieMetrics`.
Fix:
Add `metricAccumulator` implementations for `BoundedTrie` (merging singleton
and trie nodes with bound trimming) and `HistogramValue` (summing bucket counts
and total count across matching `BucketOptions`), and register both type URNs
in `typ2accumFac`. Enable bounded trie metric checks in `prism_runner_test.py`
and `runners/prism/java/build.gradle`, and add unit tests in `metrics_test.go`.
Reproduction (Python SDK on `PrismRunner`):
Build Prism (`cd sdks && go build -o /tmp/prism ./go/cmd/prism`) and run
`python repro.py --prism_location=/tmp/prism`. Python's
`HistogramCell.to_runner_api_monitoring_info` is a stub returning `None`, so
this script wires it to `monitoring_infos.user_histogram` to report
`USER_HISTOGRAM` payloads from the `LOOPBACK` worker.
```python
import sys
import apache_beam as beam
from apache_beam.metrics import cells
from apache_beam.metrics import monitoring_infos
from apache_beam.metrics.metric import Metrics
from apache_beam.metrics.metric import MetricsFilter
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.portability.api import beam_job_api_pb2
from apache_beam.portability.api import metrics_pb2
from apache_beam.utils.histogram import LinearBucket
cells.HistogramCell.to_runner_api_monitoring_info = (
lambda self, name, transform_id: monitoring_infos.user_histogram(
name.namespace, name.name, self.data, ptransform=transform_id))
class RecordMetricsDoFn(beam.DoFn):
def __init__(self):
self.trie = Metrics.bounded_trie("ns", "paths")
self.hist = Metrics.histogram("ns", "latency", LinearBucket(0, 10,
5))
def process(self, element):
seg, val = element
self.trie.add(("root", seg))
self.hist.update(val)
yield element
if __name__ == "__main__":
options = PipelineOptions(
["--runner=PrismRunner", "--environment_type=LOOPBACK"] +
sys.argv[1:]
)
p = beam.Pipeline(options=options)
_ = (
p
| beam.Create([("a", 5), ("b", 15), ("b", 25)])
| beam.ParDo(RecordMetricsDoFn())
)
res = p.run()
res.wait_until_finish()
tries = res.metrics().query(
MetricsFilter().with_namespace("ns").with_name("paths")
)["bounded_tries"]
resp = res._job_service.GetJobMetrics(
beam_job_api_pb2.GetJobMetricsRequest(job_id=res._job_id)
)
hists = [
metrics_pb2.HistogramValue.FromString(mi.payload)
for mi in resp.metrics.committed
if monitoring_infos.is_histogram(mi)
and mi.labels.get("NAMESPACE") == "ns"
and mi.labels.get("NAME") == "latency"
]
trie_paths = [set(t.committed.flattened()) for t in tries]
hist_counts = [(h.count, list(h.bucket_counts)) for h in hists]
print("bounded_tries:", trie_paths)
print("histograms:", hist_counts)
assert trie_paths == [{("root", "a", False), ("root", "b", False)}]
assert hist_counts == [(3, [1, 1, 1, 0, 0])]
```
Before the fix (`master`): `bounded_tries: []` and `histograms: []`, and the
first assertion fails.
After the fix: `bounded_tries: [{('root', 'a', False), ('root', 'b',
False)}]` and `histograms: [(3, [1, 1, 1, 0, 0])]`.
<!--
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
- [ ] Replace these instructions with a description of your change and why
you have made it.
- [ ] Mention the appropriate issue in your description (for example:
`addresses #123` or `fixes #456`).
- [ ] Update `CHANGES.md` with noteworthy changes.
See [CONTRIBUTING.md]() for more details.
-->
--
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]