Skip to content

Collect Kafka ACL inventory in kafka_consumer - #24241

Open
piochelepiotr wants to merge 8 commits into
masterfrom
pwolski/kafka-consumer-acls
Open

Collect Kafka ACL inventory in kafka_consumer#24241
piochelepiotr wants to merge 8 commits into
masterfrom
pwolski/kafka-consumer-acls

Conversation

@piochelepiotr

@piochelepiotr piochelepiotr commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds Kafka ACL inventory collection to the kafka_consumer integration under the existing enable_cluster_monitoring flag that already gates broker, topic, consumer group, and schema metadata. ACLs are collected on every check run whenever cluster monitoring is enabled — there is no separate opt-out, consistent with everything else collected under that flag.

The check enumerates all ACL bindings through AdminClient.describe_acls (an ANY/ANY match-all filter) and emits one data-streams-message configuration event per binding (config_type: acl) carrying the full detail: principal, host, resource type, resource name, pattern type, operation, and permission type. Events are change-tracked through the shared configuration-event cache — re-emitted when a binding changes and otherwise refreshed on the standard 1-hour TTL used for broker/topic/schema config events.

Clusters without an authorizer (for example AWS MSK Serverless, or a security protocol with no ACL support) raise a KafkaException from describe_acls (or time out); this is caught, logged at debug, and ACL collection is skipped gracefully so the rest of metadata collection is never affected.

Motivation

ACL inventory gives Data Streams Monitoring users visibility into the authorization posture of their Kafka clusters alongside the broker, topic, consumer group, and schema metadata already collected under cluster monitoring.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

Add ACL collection to the kafka_consumer cluster monitoring path. When
enable_cluster_monitoring is on and the new collect_acls option is not
disabled, the check enumerates all ACL bindings via
AdminClient.describe_acls and emits:

- kafka.acl.count: a low-cardinality gauge tagged by resource_type,
  pattern_type, acl_operation, and permission_type (no principal/host).
- One data-streams-message config event per binding (config_type: acl)
  carrying the full binding detail, change-tracked through the existing
  event cache.

Clusters without an authorizer (for example AWS MSK Serverless) raise a
KafkaException from describe_acls; this is logged at debug and skipped so
the rest of metadata collection is unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@piochelepiotr piochelepiotr added the qa/required QA is required for this PR and will generate a QA card label Jun 29, 2026
@datadog-official

datadog-official Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 95.65%
Overall Coverage: 91.62%

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5f47f5a | Docs | Datadog PR Page | Give us feedback!

piochelepiotr and others added 6 commits June 29, 2026 15:00
The local model generator strips the Datadog license header that CI's
canonical generator preserves, causing "Run Validations / Validate" to
report config_models out of sync. Restore the headers to match master.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Use collision-proof JSON serialization for the ACL change-tracking key
  so free-form resource_name/principal containing '|' cannot collide and
  silently drop a config event.
- Broaden _collect_acls inner except to also debug-skip
  concurrent.futures.TimeoutError, avoiding error-level noise from a slow
  or unavailable authorizer.
- Move ACL_CACHE_MAX_SIZE into the grouped cache-size constant block.
- Tally ACL counts with collections.Counter.
- Add a second-run change-tracking test asserting unchanged ACLs do not
  re-emit config events.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Remove the kafka.acl.count gauge and its per-mechanism Counter tally;
ACLs are now collected exclusively as data-streams config events.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ngle-pass emit, timeout test

- Reword collect_acls spec.yaml description to events-only (kafka.acl.count metric was removed) and regenerate conf.yaml.example.
- Stop shadowing the builtin TimeoutError in cluster_metadata.py; use concurrent.futures.TimeoutError.
- Collapse _emit_acl_events double pass into a single pass computing each ACL key once.
- Add test_collect_acls_skipped_when_describe_times_out covering the describe_acls future timeout skip path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Round-3 review suggestion: the except clause also catches a timed-out
describe_acls future, so document that in the docstring alongside the
authorizer-unavailable case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Remove the collect_acls config option entirely. ACL collection now runs
whenever enable_cluster_monitoring is enabled, alongside the rest of
cluster metadata, instead of being gated behind a separate flag.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@piochelepiotr
piochelepiotr marked this pull request as ready for review June 29, 2026 16:22
@piochelepiotr
piochelepiotr requested a review from a team as a code owner June 29, 2026 16:22
@dd-octo-sts

dd-octo-sts Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and code coverage settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f47f5a56b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

self.log.error("Error collecting schema registry info: %s", e)

try:
self._collect_acls(shared_metadata)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor the collect_acls opt-out before fetching ACLs

When cluster monitoring is enabled, this call runs on every check regardless of the collect_acls: false setting described for the feature; KafkaConfig never reads that field and the spec/example were not updated, so setting it is silently ignored. On clusters where ACL enumeration is sensitive/expensive or the check user should not make DescribeAcls requests, users have no way to disable the new AdminClient.describe_acls call without disabling all cluster monitoring.

Useful? React with 👍 / 👎.

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.

This seems legitimate. Did you mean to implement this check?

A new boolean opt-out option collect_acls (default true) lets users disable ACL collection while keeping cluster monitoring enabled.

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 updated the PR description. I dropped the collect_acls flag completely. I want all the data to be collected via the enable_cluster_monitoring flag. The config should be as easy as possible

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.

2 participants