Skip to content

fix: disable metric formatters#542

Open
andrestejerina97 wants to merge 2 commits into
mainfrom
fix/disable-metric-formatters
Open

fix: disable metric formatters#542
andrestejerina97 wants to merge 2 commits into
mainfrom
fix/disable-metric-formatters

Conversation

@andrestejerina97
Copy link
Copy Markdown
Contributor

@andrestejerina97 andrestejerina97 commented May 12, 2026

ref: https://app.clickup.com/t/86b9pvafe

Summary by CodeRabbit

  • New Features

    • Audit logging can be selectively disabled per entity via configuration.
    • Audit logging disabled for SummitEventAttendanceMetric and SummitMetric.
  • Improvements

    • Audit processing now skips disabled entities earlier to avoid generating audit events.
  • Tests

    • Added tests covering per-entity audit enable/disable logic and behavior when auditing is disabled.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c53913e5-588e-4ee8-b66d-5d4006187367

📥 Commits

Reviewing files that changed from the base of the PR and between 645f3f3 and c1774e9.

📒 Files selected for processing (5)
  • app/Audit/AuditLogFormatterFactory.php
  • app/Audit/AuditLogOtlpStrategy.php
  • app/Audit/IAuditLogFormatterFactory.php
  • tests/OpenTelemetry/AuditLogFormatterFactoryTest.php
  • tests/OpenTelemetry/AuditLogOtlpStrategyDisabledAuditTest.php

📝 Walkthrough

Walkthrough

This PR adds per-entity audit-disable checks to AuditLogFormatterFactory (centralizing subject class resolution) and makes AuditLogOtlpStrategy exit early when an entity is configured disabled. Two summit metric entities are disabled in config and tests cover the factory and strategy behavior.

Changes

Entity-Level Audit Disablement

Layer / File(s) Summary
Factory subject resolution & disable checks
app/Audit/AuditLogFormatterFactory.php
Adds ClassUtils import, centralizes subject class resolution (getSubjectClass()), adds private isAuditDisabledForSubject() and public isAuditDisabled() methods, and short-circuits make() when auditing is disabled for the subject.
OTLP strategy early-exit
app/Audit/AuditLogOtlpStrategy.php
AuditLogOtlpStrategy::audit() now returns early if formatterFactory->isAuditDisabled($subject) is true.
Factory interface update
app/Audit/IAuditLogFormatterFactory.php
Adds public function isAuditDisabled(mixed $subject): bool; to the factory interface.
Entity-level audit configuration
config/audit_log.php
Disable auditing for \models\summit\SummitEventAttendanceMetric::class and \models\summit\SummitMetric::class by setting their enabled flags to false.
Tests: factory and strategy
tests/OpenTelemetry/AuditLogFormatterFactoryTest.php, tests/OpenTelemetry/AuditLogOtlpStrategyDisabledAuditTest.php
Add tests (including reflection-driven checks, config injection helper, and test doubles) validating isAuditDisabledForSubject behavior, that make() returns null when disabled, and that AuditLogOtlpStrategy::audit() returns early and does not enqueue jobs when audits are disabled.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AuditLogOtlpStrategy
  participant AuditLogFormatterFactory
  participant Config
  participant Queue
  Client->>AuditLogOtlpStrategy: audit(ctx, subject, event)
  AuditLogOtlpStrategy->>AuditLogFormatterFactory: isAuditDisabled(subject)
  AuditLogFormatterFactory->>Config: read audit_log.entities[getSubjectClass(subject)]['enabled']
  alt enabled === false
    AuditLogFormatterFactory-->>AuditLogOtlpStrategy: true
    AuditLogOtlpStrategy-->>Client: return (no enqueue)
  else
    AuditLogFormatterFactory-->>AuditLogOtlpStrategy: false
    AuditLogOtlpStrategy->>AuditLogFormatterFactory: make(ctx, subject, event)
    AuditLogOtlpStrategy->>Queue: dispatch EmitAuditLogJob
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • smarcet
  • martinquiroga-exo
  • caseylocker

Poem

🐰 I sniffed the config, soft and small,

Some metrics sleep, the rest must call.
The factory checks, then lets them be—
Quiet logs where silence should be.
—A happy Summit Rabbit 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix: disable metric formatters' is vague and does not clearly summarize the main changes. While it mentions disabling formatters, it omits the key implementation detail that audit logging is being disabled for specific metric entities through configuration changes and factory logic updates. Consider a more descriptive title such as 'fix: disable audit logging for metric entities' or 'fix: add audit disable logic for SummitMetric and SummitEventAttendanceMetric' to better reflect the scope of changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/disable-metric-formatters

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-542/

This page is automatically updated on each push to this PR.

@andrestejerina97 andrestejerina97 marked this pull request as ready for review May 12, 2026 11:38
Copy link
Copy Markdown
Contributor

@caseylocker caseylocker left a comment

Choose a reason for hiding this comment

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

LGTM. Nothing blocking. Follows the ticket direction.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a configuration-driven way to disable audit logging for specific entity types, and uses it to disable audit logging for metric entities (notably SummitEventAttendanceMetric and SummitMetric) in the OpenTelemetry audit logging pipeline.

Changes:

  • Add an entity “enabled/disabled” guard to AuditLogFormatterFactory::make() to skip formatter creation for disabled entities.
  • Disable audit logging for SummitEventAttendanceMetric and SummitMetric via config/audit_log.php.
  • Extend unit tests to cover per-entity audit-disable behavior and factory output when disabled.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
app/Audit/AuditLogFormatterFactory.php Adds a config-based early return to skip audit formatter creation when an entity is disabled.
config/audit_log.php Sets enabled => false for metric entities to disable their audit logging.
tests/OpenTelemetry/AuditLogFormatterFactoryTest.php Adds test coverage for the new “audit disabled” logic and factory behavior.
Comments suppressed due to low confidence (1)

tests/OpenTelemetry/AuditLogFormatterFactoryTest.php:24

  • The class-level docblock still says these tests are only for matchesStrategy() null-guard behavior, but this file now also tests audit-disable behavior (isAuditDisabledForSubject / make). Updating the docblock would keep the test intent accurate.
use App\Audit\Interfaces\IAuditStrategy;
use PHPUnit\Framework\TestCase;

/**
 * Class AuditLogFormatterFactoryTest

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +204 to +209
$entities = $this->config['entities'] ?? [];
$entity_config = $entities[get_class($subject)] ?? null;

return is_array($entity_config)
&& array_key_exists('enabled', $entity_config)
&& $entity_config['enabled'] === false;
Comment on lines +45 to +47
if ($this->isAuditDisabledForSubject($subject)) {
return null;
}
@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-542/

This page is automatically updated on each push to this PR.

@andrestejerina97 andrestejerina97 force-pushed the fix/disable-metric-formatters branch from 7ff8e9c to 645f3f3 Compare May 19, 2026 12:44
@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-542/

This page is automatically updated on each push to this PR.

@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-542/

This page is automatically updated on each push to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants