[Bug][Go]: Metrics incremented in Setup methods are not recalled. #27038
Copy link
Copy link
Open
Labels
Description
What happened?
Because the ParDo Setup context is uncached metrics initialized in Setup are lost, which is unexpected. Work done in setup, while logically outside of a bundle, will be under the context of the first bundle to execute that transform.
So there needs to be a way to transfer/extract the metrics from the Setup context so they are recorded back to the runner.
Issue Priority
Priority: 3 (minor)
Issue Components
- Component: Python SDK
- Component: Java SDK
- Component: Go SDK
- Component: Typescript SDK
- Component: IO connector
- Component: Beam examples
- Component: Beam playground
- Component: Beam katas
- Component: Website
- Component: Spark Runner
- Component: Flink Runner
- Component: Samza Runner
- Component: Twister2 Runner
- Component: Hazelcast Jet Runner
- Component: Google Cloud Dataflow Runner
Activity
moawnallah commentedon Feb 7, 2025
Hi @lostluck,
I am interested in this issue and have been exploring Apache Beam metrics before working on this issue regarding unrecalled metric increments in
Setupmethods. As part of my learning, I wrote a simple Beam Go SDK program that converts words to uppercase and ran it on a local Flink development cluster. The dev environment looks like Apache Beam Go SDK v2.62.0, apache/beam_flink1.19_job_server, and flink:1.19.0-java11.I observed that no custom metrics are reported in the Flink runner—only internal Beam metrics appear in the
Accumulatorstab. This behavior seems related to issue #32895.Any insights on this?
For reference, here is the simple program I used:
Looking forward to your thoughts! 🙏
lostluck commentedon Feb 20, 2025
Sorry for missing this earlier @mohamedawnallah .
If Flink doesn't support exporting user metrics, then it's not something the Go SDK can fix by itself.
IIRC this issue is strictly for when a DoFn has metrics, and increments them in in the Once Per DoFn Instance Setup() lifecycle method. The provided code would not verify this issue by itself since it has no Setup methods on its dofns.
The default Go SDK runner, Prism, should be able to validate this issue though, if the base code reveals it. The changes would be in the
execpackage, ultimately.albertjaison18 commentedon Jul 13, 2026
.free-issue
mgalore commentedon Jul 22, 2026
.take-issue
mgalore commentedon Jul 22, 2026
.free-issue
4 remaining items
nightcityblade commentedon Aug 13, 2026
Hi, I'd like to work on this. I'll submit a focused PR shortly.
nightcityblade commentedon Aug 13, 2026
After tracing the current metrics lifecycle, this needs a broader design around carrying one-time setup metrics into the first bundle store than I can safely complete as a small focused patch right now, so I'm stepping back to leave it available. Sorry for the noise.
LeonxLJX commentedon Aug 27, 2026
Hi! I'd like to work on this issue. Please let me know if I can be assigned. Thanks!
LeonxLJX commentedon Sep 1, 2026
Hi! I'd like to fix Go metrics incremented in Setup methods not being recalled. Plan: reproduce, fix the metric lifecycle, add a test. May I be assigned?
lostluck commentedon Sep 2, 2026
Thank you for your interest @LeonxLJX ! You can self assign most issues by following the instructions at the contribution guide: https://github.com/apache/beam/blob/master/CONTRIBUTING.md#share-your-intent
kragent66-glitch commentedon Sep 2, 2026
Hi, I'd like to pick this up and investigate the metrics loss in Setup methods.
kragent66-glitch commentedon Sep 2, 2026
Hi, I'd like to pick this up. I'll look into the metrics initialization in the Setup method for the Go SDK.
kragent66-glitch commentedon Sep 2, 2026
Hi, I'd like to pick this up and work on a fix for capturing metrics from the Setup() lifecycle method.
kragent66-glitch commentedon Sep 2, 2026
Hi, I'd like to pick this up and work on ensuring metrics incremented in Setup() are correctly recorded.
lostluck commentedon Sep 2, 2026
Thank you for your interest @kragent66-glitch ! You can self assign most issues by following the instructions at the contribution guide: https://github.com/apache/beam/blob/master/CONTRIBUTING.md#share-your-intent
(Yes I'm teasing the obvious AI bot).
kragent66-glitch commentedon Sep 2, 2026
Hi @lostluck, after investigating, I found that this issue is related to the Setup() method not receiving the bundle context when it doesn't accept a context.Context argument. I've written a test case that confirms if Setup(ctx context.Context) is used, the metric is correctly captured. If the user uses Setup() without context and passes context.Background() to the metric API, the metric is correctly (but perhaps unexpectedly) dropped because context.Background() has no counter set. I'll provide a PR with a test case to clarify this convention.
singhmrinal02 commentedon Sep 16, 2026
Hi, I'd like to work on this issue as a first contribution . Could you please assign it to me?
jrmccluskey commentedon Sep 17, 2026
@singhmrinal02 There's an open PR attempting to address the issue, I would recommend checking out another open issue. As stated above, you can self-assign issues by following https://github.com/apache/beam/blob/master/CONTRIBUTING.md#share-your-intent
Merge setup metrics tests into one file and document the behavior und…
Add test case verifying metric capture in Setup() lifecycle method (#…