Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocklist to disable specific metric tags or metric names #29881

Merged
merged 13 commits into from
Mar 6, 2023

Conversation

sungwy
Copy link
Contributor

@sungwy sungwy commented Mar 2, 2023

closes: #29663

This PR adds two additional configuration parameters:

statsd_disabled_tags:
      description: |
        If you want to avoid sending all the available metrics tags to StatsD,
        you can configure a blocklist of prefixes (comma separated) to filter out metric tags 
        that start with the elements of the list (e.g: "job_id,run_id")
      version_added: 2.6.0
      type: string
      example: job_id,run_id,dag_id,task_id
      default: job_id,run_id

statsd_block_list:
      description: |
        If you want to avoid sending all the available metrics to StatsD,
        you can configure a block list of prefixes (comma separated) to filter out metrics that
        start with the elements of the list (e.g: "scheduler,executor,dagrun").
        If statsd_allow_list and statsd_block_list are both configured, statsd_block_list is ignored
      version_added: 2.6.0
      type: boolean
      example: ~
      default: "False"

statsd_disabled_tags allows users to define a blocklist of tag name prefixes to disable.

statsd_invert_allow_list is a boolean parameter that converts the functionality of statsd_invert_allow_list from an allowlist to a blocklist.

The reason we need the metric name blocklist on top of a blocklist just for metric tags is because there are legacy metric names that have high cardinality under the definition explored in #29663 like: local_task_job.task_exit.<job_id>.<dag_id>.<task_id>.<return_code> that users might want to disable to reduce their metric storage costs.

@sungwy
Copy link
Contributor Author

sungwy commented Mar 2, 2023

@hussein-awala @potiuk may I ask for your review on this PR? Thank you both very much for your input!

@potiuk potiuk added this to the Airflow 2.6.0 milestone Mar 3, 2023
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

I think it is very confusing as defined now. I think we should change "allow_list_validator" field into "list_validator" and have two implementations:

  • AllowListValidator
  • BlockListValidator

And let the user choose which validator to use (by name for example). The way where you invert meaning of a list is super confusing. IMHO

@sungwy
Copy link
Contributor Author

sungwy commented Mar 5, 2023

I think it is very confusing as defined now. I think we should change "allow_list_validator" field into "list_validator" and have two implementations:

  • AllowListValidator
  • BlockListValidator

And let the user choose which validator to use (by name for example). The way where you invert meaning of a list is super confusing. IMHO

I see what you are saying @potiuk . I've made your suggested changes in stats.py. I've also introduced a separate statsd_block_list config parameter that expects a comma delimited string instead of statsd_invert_allow_list. Made a note on the config comment to note that if both statsd_allow_list and statsd_block_list are set, then statsd_block_list will be ignored in favor of statsd_allow_list.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Much more straightforward now :). I'd love another committer to review it too.

# If you want to avoid sending all the available metrics to StatsD,
# you can configure a block list of prefixes (comma separated) to filter out metrics that
# start with the elements of the list (e.g: "scheduler,executor,dagrun").
# If statsd_allow_list and statsd_block_list are both configured, statsd_block_list is ignored
Copy link
Member

Choose a reason for hiding this comment

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

One small NIT. Probably we should have a warning in the logs if both are configured.

@potiuk
Copy link
Member

potiuk commented Mar 5, 2023

Static checks need fixing.

stat += f",{k}={v}"
else:
log.error("Dropping invalid tag: %s=%s.", k, v)
if self.metric_tags_validator.test(k):
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to check if the tag is filtered here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hussein-awala

Aren't we only concatenating metric tags that are allowed? (i.e. not disabled / not blocked)

If it's test(k) returns True, we will want to publish that metric tag

Copy link
Member

Choose a reason for hiding this comment

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

My bad, I thought that this filter:

            tags_list = [
                f"{key}:{value}" for key, value in tags.items() if self.metric_tags_validator.test(key)
            ]

is used for the two clients datadog and influxdb, but just found that is just used for datadog, and if self.metric_tags_validator.test(k): is used for influxdb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - influxdb integration just adds the tag key:value pairs to the metric name with a comma-delimited standard, instead of having a separate Statsd client implementation that takes tags as a separate parameter.

@sungwy
Copy link
Contributor Author

sungwy commented Mar 6, 2023

Static checks need fixing.

Fixed the checks and added the log based on your feedback! @potiuk

@potiuk potiuk merged commit 86cd79f into apache:main Mar 6, 2023
@sungwy sungwy deleted the disable-tags branch March 6, 2023 15:02
@pierrejeambrun pierrejeambrun added the type:new-feature Changelog: New Features label Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:new-feature Changelog: New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to Disable High Cardinality Metrics on Statsd
4 participants