Skip to content

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

Merged
mistahj67 merged 2 commits into
mainfrom
BED-8382
Jun 2, 2026
Merged

feat(alerts): add alerts feature flag BED-8382#2831
mistahj67 merged 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 safe accessor that falls back to disabled on error.
    • Exposed feature-flag audit metadata to improve traceability of flag changes.

@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

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: ffd3ae8c-ae30-4ba0-a3db-0d223f469291

📥 Commits

Reviewing files that changed from the base of the PR and between d83ea32 and 3dff59f.

📒 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 (2)
  • cmd/api/src/database/migration/migrations/20260527000000_v9_add_alerts_feature_flag.sql
  • cmd/api/src/model/appcfg/flag.go

📝 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, FeatureFlag.AuditData(), GetFlagEnabled(ctx, service, key), and GetAlertsEnabled(ctx, service).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • SpecterOps/BloodHound#2809: Both PRs add new entries to feature_flags via goose migrations and update cmd/api/src/model/appcfg/flag.go with exported feature-flag constants.

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 concisely describes the main change: adding an alerts feature flag, with specific reference to the Jira ticket BED-8382.
Description check ✅ Passed The description addresses most template sections with relevant content, including a clear summary of changes, resolution of the associated ticket (BED-8382), testing verification, and completed checklist items.
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

@mistahj67 mistahj67 enabled auto-merge (squash) June 2, 2026 16:43
@mistahj67 mistahj67 merged commit 7f61c24 into main Jun 2, 2026
13 checks passed
@mistahj67 mistahj67 deleted the BED-8382 branch June 2, 2026 16:52
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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