Skip to content

Support a Unix Domain Socket for the metrics clients - #70517

Merged
hussein-awala merged 1 commit into
apache:mainfrom
sortega:sortega/DNAWF-4497_dd_dogstats_url
Aug 24, 2026
Merged

hussein-awala merged 1 commit into
apache:mainfrom
sortega:sortega/DNAWF-4497_dd_dogstats_url

Conversation

@sortega

@sortega sortega commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Adds a `[metrics] statsd_socket_path` option so Airflow can submit metrics over a Unix Domain Socket instead of host/port — for both the StatsD and DataDog backends.

Today `get_statsd_logger` / `get_dogstatsd_logger` only pass `statsd_host` / `statsd_port`, so deployments that expose the daemon over a UDS — e.g. the Datadog Kubernetes operator, which mounts a socket and sets `DD_DOGSTATSD_URL=unix:///var/run/datadog/dsd.socket` — have no way to use it from Airflow. Both `datadog.DogStatsd` and the `statsd` library (`UnixSocketStatsClient`) support a socket path; this exposes it through Airflow config.

`statsd_host` and `statsd_port` keep their existing defaults (`localhost` / `8125`). When `statsd_socket_path` is set it takes precedence and host/port are ignored:

  • DataDog backend (`statsd_datadog_enabled = True`): builds `DogStatsd(socket_path=...)`. Accepts a plain path or a `unix://` / `unixgram://` / `unixstream://` URL.
  • StatsD backend: builds `statsd.UnixSocketStatsClient` instead of the UDP `StatsClient`. Expects a plain filesystem path.

When `statsd_socket_path` is unset, behavior is identical to before.

  • New `[metrics] statsd_socket_path` config key (`default: ~`).
  • `get_dogstatsd_logger` and `get_statsd_logger` (shared) gain a `socket_path` kwarg; when set, the socket-capable client is selected automatically.
  • airflow-core and task-sdk wrappers read the new key and select `UnixSocketStatsClient` / pass `socket_path` to `DogStatsd` when it is set.
  • Unit tests covering socket_path passthrough for both backends.

Closes #70666


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.8 1M)

Generated-by: Claude Code (Opus 4.8 1M) following the guidelines

@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch 2 times, most recently from 844b919 to b4dcbec Compare July 29, 2026 08:17
@sortega sortega changed the title Support a Unix Domain Socket for the Datadog metrics client Support a Unix Domain Socket for the StatsD and Datadog metrics clients Jul 29, 2026
@sortega sortega changed the title Support a Unix Domain Socket for the StatsD and Datadog metrics clients Support a Unix Domain Socket for the metrics clients Jul 29, 2026
@sortega
sortega marked this pull request as ready for review July 29, 2026 08:24

@uranusjr uranusjr 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.

It is too implicit to me that the path silently takes precedence over host+port. An exception should be raised probably when both are set.

@sortega

sortega commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

It is too implicit to me that the path silently takes precedence over host+port. An exception should be raised probably when both are set.

We can fix that by making the host/port nullable and removing the default values. But then we need to reintroduce the default values at the metrics loggers because we don't want to break existing configurations that just enable metrics but don't specify host and port.

I'll do that

@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch 2 times, most recently from 4c1c550 to c105ef7 Compare July 29, 2026 11:57
@sortega
sortega marked this pull request as draft July 29, 2026 11:59
@xBis7

xBis7 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Having configured all of the options host, port and socket_path isn't fatal.

For datadog, the same class accepts all of them and then silently gives precedence to the socket_path.

For statsd, each config option is used for a different class but all of them could co-exist. If both classes are instantiated, the same metric will be emitted twice which isn't optimal or desired but still there won't be an issue for the system.

IMO, we shouldn't set host and port to None when socket_path is also provided. For statsd, we should just give precedence to the socket_path and log a warning while for datadog, we should just log a warning.

@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch from c105ef7 to fcdee0c Compare July 29, 2026 12:27
@sortega
sortega marked this pull request as ready for review July 29, 2026 13:19
@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch from fcdee0c to f7b3331 Compare July 29, 2026 14:09
@sortega

sortega commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@xBis7, makes sense. No exception anymore.

@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch 4 times, most recently from 91044a2 to 5ad1e00 Compare August 4, 2026 12:59
@sortega
sortega requested review from uranusjr and xBis7 August 5, 2026 12:56
@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch 3 times, most recently from 666cf2f to 5cf9fdf Compare August 17, 2026 08:39
@sortega
sortega requested a review from uranusjr August 17, 2026 08:53
@sortega

sortega commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@uranusjr, do you want me to go for the observability lib depending on the config lib?

@xBis7

xBis7 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

@sortega Thanks for updating the PR!

If you need a new exception type, then it needs to be added here instead of adding a new dependency

https://github.com/sortega/airflow/blob/sortega/DNAWF-4497_dd_dogstats_url/shared/observability/src/airflow_shared/observability/exceptions.py

But, I don't think we should do that. airflow-core and task-sdk both initialize their own config parser and then re-use some parts fromshared/configuration. Because the conf object is different for these main packages, config is read twice under airflow-core and task-sdk and then passed to shared. E.g.

https://github.com/apache/airflow/pull/70517/changes#diff-8a528bc2492e4fcc8361aeb91b6014d77b09d1ad190c3f75a7d9b8f087ddc6bcR33

https://github.com/apache/airflow/pull/70517/changes#diff-fba7485cf1bc00467f34ed32e234b40b630fe7f0ff52df832d27f4c10b679418R34

So, if you need to do a validation which will throw an AirflowConfigException, then that should happen in the factory methods and then the validated value should be passed to the shared code.

You don't have to move the entire thing, just do a quick validation regarding the config value and the rest stays the same.

@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch from 5cf9fdf to 7422272 Compare August 17, 2026 13:46
@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch 3 times, most recently from 6aded0a to 55e8e5c Compare August 18, 2026 08:07
@sortega
sortega requested a review from uranusjr August 18, 2026 11:05
@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch from 55e8e5c to 5939d84 Compare August 18, 2026 12:45

@uranusjr uranusjr 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.

A few minor issues this need to fix before the PR is mergeable.

@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch 2 times, most recently from 4baf5a6 to ecbe5b9 Compare August 19, 2026 10:52

@xBis7 xBis7 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.

I have 2 non-blocking questions. LGTM!

@sortega

sortega commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@uranusjr, @xBis7 good to merge?

@hussein-awala hussein-awala 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.

Overall the change looks good, add a few comments, LGTM once they are addressed.

@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch from 74fa104 to 36e5323 Compare August 24, 2026 10:08
Airflow's metrics clients could only be pointed at a host and port, so
deployments that expose the daemon over a Unix Domain Socket (for example the
Datadog Kubernetes operator, which mounts a socket and sets DD_DOGSTATSD_URL)
had no way to use it from Airflow.

Add a ``[metrics] statsd_socket_path`` option, honored by both backends: the
DataDog client is built with ``socket_path`` and the StatsD client uses
``statsd.UnixSocketStatsClient``. ``statsd_host`` and ``statsd_port`` are now
nullable, and only explicitly-configured values are passed to the client; when
nothing is set the DataDog client falls back to its own environment variables
(DD_AGENT_HOST / DD_DOGSTATSD_URL). ``statsd_socket_path`` takes precedence over
``statsd_host`` / ``statsd_port`` when both are set — the DataDog client is
given all of them and prefers the socket, the StatsD client is built on the
socket — and a warning is logged in that case.
@sortega
sortega force-pushed the sortega/DNAWF-4497_dd_dogstats_url branch from 36e5323 to 7bdedfb Compare August 24, 2026 10:12
@hussein-awala hussein-awala added the type:new-feature Changelog: New Features label Aug 24, 2026
@hussein-awala hussein-awala added this to the Airflow 3.4.0 milestone Aug 24, 2026
@hussein-awala
hussein-awala merged commit b03e48a into apache:main Aug 24, 2026
107 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support a Unix Domain Socket for the metrics clients

4 participants