Skip to content

Cleanup the DualStatsManager and fix any leftover Stats calls #62705

Closed
xBis7 wants to merge 6 commits into
apache:mainfrom
xBis7:dual-stats-manager-cleanup
Closed

Cleanup the DualStatsManager and fix any leftover Stats calls #62705
xBis7 wants to merge 6 commits into
apache:mainfrom
xBis7:dual-stats-manager-cleanup

Conversation

@xBis7

@xBis7 xBis7 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

related discussion: #62019 (comment)

DualStatsManager code explanation

Usually the legacy metrics don't have any tags and all the variables are included in the name.

The tags dict refers to tags that are set on both the new name metric and the legacy name metric (separately from the name variables).

The legacy_name_tags dict refers to the legacy name variables.

The legacy metrics will only have the tags values as tags.

Both dictionaries are eventually merged and the resulting dict is used for the final tags of the new metric.

For example,

tags={},
legacy_name_tags=tags

the legacy metric won't have any tags and after that is exported, {} and tags are merged and then set as the new metric tags.

Patch changes

The patch is consisted of the following changes

  • renamed extra_tags to legacy_name_tags for clarity
  • added explanation comments in the DualStasManager
  • replaced the word ...extra... with the word ...legacy... in all references
  • cleaned up mess-ups with the tags and legacy_name_tags params
  • added missing stats in the metrics_template.yaml
  • for providers, followed the try-except pattern for the DualStatsManager import and maintained the old Stats calls as fallbacks

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
  • No

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@xBis7

xBis7 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

@amoghrajesh @ashb

stat.last_duration,
tags={"file_name": file_name, "bundle_name": normalized_bundle},
tags={},
legacy_name_tags={"bundle_name": normalized_bundle, "file_name": file_name},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial assumption here was that the tags would be the other way around -- why don't we want bundle name and filepath included in the modern tags?

@xBis7 xBis7 Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are.

It goes like this

  • check the legacy_name_tags and cross-reference them with the variables in the YAML file
  • set the legacy_name_tags as variables in the legacy name
  • build the legacy metric name
  • export the legacy metric with the tags param
  • merge the tags and the legacy_name_tags
  • export the new name with the merged dictionary as tags

That was actually a bug because, by just setting the tags, there weren't any available variables for the legacy name.

I've added comments in the code to explain the above.

The legacy_name_tags are going to end up as regular tags for the modern name. And the tags are just for whatever tag is set on both metrics.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. That's slightly confusing. The behabiour makes sense, but, just from the callsite (of which there are going to be lots) it's a bit confusing that legacy_name_tags gets applied to non-legacy metrics.

🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. The behavior is consistent with before but the DualStatsManager logic is confusing. I renamed the extra_tags param to legacy_name_tags to make it more intuitive and added comments but it's still not that clear.

Do you have any suggestions?

Before the DualStatsManager

  • legacy metrics didn't have any tags and everything was included in the name
  • modern metrics had a simpler name and all the variables from the legacy metric name, as tags

The thing is that I'm trying to cover an edge case where the legacy and the modern metric had some extra tags, apart from the name variables.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashb Can you make a final review? Then I think it would be great to merge.

@xBis7

xBis7 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

This

https://github.com/xBis7/airflow/blob/dual-stats-manager-cleanup/providers/edge3/tests/unit/edge3/executors/test_edge_executor.py#L60

@patch(f"{Stats.__module__}.Stats.incr")

and this

https://github.com/xBis7/airflow/blob/dual-stats-manager-cleanup/providers/edge3/tests/unit/edge3/executors/test_edge_executor.py#L96-L104

mock_stats_incr.assert_called_with(
    "edge_worker.ti.finish",
    tags={
        "dag_id": "test_dag",
        "queue": "default",
        "state": "failed",
        "task_id": "started_running_orphaned",
    },
)

are wrong, but the test passes. I'm looking into it.

@xBis7

xBis7 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

Regarding the test_edge_executor test, after I fixed the import on the patch annotation, the mock assertions worked. The test is fixed now.

Comment thread providers/edge3/src/airflow/providers/edge3/executors/edge_executor.py Outdated
@xBis7

xBis7 commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

Hey @jscheffl, thank you for the review! I changed all the DualStatsManager imports under providers and their respective tests. I replaced the try-except pattern with an AIRFLOW_V_3_2_PLUS check like you suggested.

@xBis7 xBis7 force-pushed the dual-stats-manager-cleanup branch from 256ae43 to 1125582 Compare March 3, 2026 11:58

@jscheffl jscheffl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Viewing the edge part - looks good to me! Thanks for the rework!

@dheerajturaga dheerajturaga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edge3 looks good to me

@xBis7

xBis7 commented Mar 4, 2026

Copy link
Copy Markdown
Contributor Author

@jscheffl @dheerajturaga Thank you for the reviews! The CI failures seem unrelated.

@xBis7 xBis7 force-pushed the dual-stats-manager-cleanup branch 2 times, most recently from 6e560ad to ccbe11b Compare March 6, 2026 12:56
@xBis7 xBis7 force-pushed the dual-stats-manager-cleanup branch from ccbe11b to ac037b1 Compare March 11, 2026 07:18
@xBis7

xBis7 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

@ashb @amoghrajesh Can you take a look?

@xBis7

xBis7 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

I'm looking into removing the DualStatsManager entirely in

#63932

I'll keep this PR open just in case, I need to split the above patch into smaller ones. Otherwise, I'll close it.

@xBis7

xBis7 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

I'm closing this PR. Due to the work in #63932, this isn't relevant anymore.

@xBis7 xBis7 closed this Mar 27, 2026
@xBis7 xBis7 deleted the dual-stats-manager-cleanup branch May 4, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:DAG-processing area:providers area:Scheduler including HA (high availability) scheduler area:task-sdk area:Triggerer provider:edge Edge Executor / Worker (AIP-69) / edge3 provider:openlineage AIP-53

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants