Skip to content

feat(alerts): add alerts feature flag BED-8382#2831

Open
mistahj67 wants to merge 2 commits into
mainfrom
BED-8382
Open

feat(alerts): add alerts feature flag BED-8382#2831
mistahj67 wants to merge 2 commits into
mainfrom
BED-8382

Conversation

@mistahj67
Copy link
Copy Markdown
Contributor

@mistahj67 mistahj67 commented May 27, 2026

Description

Adds feature flag for Alerts

Describe your changes in detail

Motivation and Context

Resolves BED-8382

Why is this change required? What problem does it solve?

How Has This Been Tested?

Verified migration ran and new record was created on FF table

Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc.

Screenshots (optional):

Types of changes

  • Chore (a change that does not modify the application functionality)
  • Database Migrations

Checklist:

Summary by CodeRabbit

  • New Features

    • Added an "Alerts" feature flag to support a controlled rollout of alerts.
  • Refactor

    • Centralized feature-flag checking with a simple accessor for the alerts flag, ensuring safe fallback to disabled if retrieval fails.
    • Feature-flag audit metadata is now exposed for improved traceability.

Review Change Stack

@mistahj67 mistahj67 self-assigned this May 27, 2026
@mistahj67 mistahj67 added the api A pull request containing changes affecting the API code. label May 27, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

📝 Walkthrough

Walkthrough

Adds an "alerts" feature flag: a Goose migration inserts an idempotent alerts row (enabled=false, user_updatable=false) and Go code adds FeatureAlerts, a generic GetFlagEnabled helper, GetAlertsEnabled, and FeatureFlag.AuditData().

Changes

Add alerts feature flag

Layer / File(s) Summary
Alerts feature flag database and accessor
cmd/api/src/database/migration/migrations/20260527000000_v9_add_alerts_feature_flag.sql, cmd/api/src/model/appcfg/flag.go
Database migration creates the idempotent alerts feature flag row with enabled=false and user_updatable=false. Go code adds FeatureAlerts constant, GetFlagEnabled(ctx, service, key), GetAlertsEnabled(ctx, service), and FeatureFlag.AuditData().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • SpecterOps/BloodHound#2809: Both PRs add new feature flags via Goose migrations and update cmd/api/src/model/appcfg/flag.go with exported feature-flag constants using the same mechanism.

Suggested labels

dbmigration

Suggested reviewers

  • lrfalslev
  • mykeelium
  • ktstrader
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding an alerts feature flag, directly matching the primary objective of the pull request.
Description check ✅ Passed The description is mostly complete with key sections filled out (Description, Motivation/Context, Testing, Types of changes, and Checklist all addressed), though some placeholder text remains unfilled.
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 BED-8382

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

Comment thread cmd/api/src/model/appcfg/flag.go
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/api/src/model/appcfg/flag.go (1)

110-116: ⚡ Quick win

Hoist and group local variable initialization in GetFlagEnabled.

Please align this function with the Go guideline by declaring locals at the top via a var (...) block.

Proposed diff
 func GetFlagEnabled(ctx context.Context, service GetFlagByKeyer, key string) bool {
-	if flag, err := service.GetFlagByKey(ctx, key); err != nil {
+	var (
+		flag FeatureFlag
+		err  error
+	)
+
+	if flag, err = service.GetFlagByKey(ctx, key); err != nil {
 		slog.WarnContext(ctx, "Failed to fetch feature flag; returning false", slog.String("key", key))
 		return false
-	} else {
-		return flag.Enabled
 	}
+
+	return flag.Enabled
 }

As per coding guidelines: "Group variable initializations in a var ( ... ) block and hoist them to the top of the function when possible".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/api/src/model/appcfg/flag.go` around lines 110 - 116, Hoist and group the
local variables used in GetFlagEnabled by declaring them in a var (...) block at
the top of the function (e.g., var flag *FlagType, err error) then call
service.GetFlagByKey(ctx, key) to assign those variables, check err and call
slog.WarnContext("Failed to fetch feature flag; returning false",
slog.String("key", key)) when err != nil, otherwise return flag.Enabled; keep
references to GetFlagEnabled, service.GetFlagByKey, flag, err and
slog.WarnContext when applying the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/api/src/model/appcfg/flag.go`:
- Around line 110-116: Hoist and group the local variables used in
GetFlagEnabled by declaring them in a var (...) block at the top of the function
(e.g., var flag *FlagType, err error) then call service.GetFlagByKey(ctx, key)
to assign those variables, check err and call slog.WarnContext("Failed to fetch
feature flag; returning false", slog.String("key", key)) when err != nil,
otherwise return flag.Enabled; keep references to GetFlagEnabled,
service.GetFlagByKey, flag, err and slog.WarnContext when applying the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 4b58b569-406a-4f35-961d-590df4f9c583

📥 Commits

Reviewing files that changed from the base of the PR and between 6ad5eee and d83ea32.

📒 Files selected for processing (2)
  • cmd/api/src/database/migration/migrations/20260527000000_v9_add_alerts_feature_flag.sql
  • cmd/api/src/model/appcfg/flag.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/api/src/database/migration/migrations/20260527000000_v9_add_alerts_feature_flag.sql

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

Labels

api A pull request containing changes affecting the API code. dbmigration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants