Skip to content

fix(ROSAENG-435): support PagerDuty incident lookup for HCP clusters - #962

Open
fullsend-ai-coder[bot] wants to merge 4 commits into
masterfrom
agent/ROSAENG-435-hcp-pagerduty-incidents
Open

fix(ROSAENG-435): support PagerDuty incident lookup for HCP clusters#962
fullsend-ai-coder[bot] wants to merge 4 commits into
masterfrom
agent/ROSAENG-435-hcp-pagerduty-incidents

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown

Summary

  • Adds HCP (Hosted Control Plane) cluster support to PagerDuty incident lookup in both osdctl cluster context and osdctl org context commands
  • For HCP clusters, PD services are region-based rather than per-cluster, so the PD query uses the AWS region ID instead of the DNS base domain
  • Incidents are filtered by matching the cluster's external UUID (not the internal OCM ID) against EventDetails in the first trigger log entry, ensuring only incidents for the target cluster are shown
  • Classic cluster behavior is unchanged — filtering is only applied when a cluster ID is set

What changed

pkg/provider/pagerduty/pagerduty.go

  • Added clusterID field and WithClusterID() builder method to the PD client
  • Modified GetFiringAlertsForCluster() to request first_trigger_log_entries from PD and filter incidents by cluster ID when set
  • Added incidentMatchesCluster() helper that checks cluster_id, clusterID, and cluster-id keys in EventDetails

cmd/cluster/context.go

  • For HCP clusters, overrides baseDomain with the region ID for PD service lookup
  • Passes externalClusterID to WithClusterID() (the external UUID that PD alerts reference)

cmd/org/context.go

  • Updated NewPDClient function signature to accept clusterID parameter
  • Detects HCP clusters and passes cluster.ExternalID() for incident filtering

Testing

  • 25 PagerDuty provider unit tests pass (6 new tests for incidentMatchesCluster, 1 for WithClusterID, 4 for HCP filtering in GetFiringAlertsForCluster)
  • 1 new test in cmd/org/context_test.go verifying NewPDClient passes both parameters
  • All existing tests continue to pass — classic cluster behavior is not affected
  • go vet and go build pass on all changed packages

Related to https://redhat.atlassian.net/browse/ROSAENG-435

Post-script verification

  • Branch is not main/master (agent/ROSAENG-435-hcp-pagerduty-incidents)
  • Secret scan passed (gitleaks — c02ab22b7faf938a24ff7f1a084ae3c650f07759..HEAD)
  • PR body secret scan passed (gitleaks — no-git)

HCP clusters use region-based PD services instead of per-cluster
services keyed by DNS base domain. For classic clusters, PD services
are named after the cluster's DNS domain, so querying by baseDomain
works. For HCP, the PD service corresponds to the AWS region (e.g.
us-east-1), and incidents for multiple clusters share the same
service.

Changes:
- Add WithClusterID() to the PD client builder so callers can
  set a cluster ID for incident filtering
- Modify GetFiringAlertsForCluster() to include
  first_trigger_log_entries when a cluster ID is set, and filter
  incidents by matching the cluster ID in EventDetails
- Add incidentMatchesCluster() helper that checks cluster_id,
  clusterID, and cluster-id keys in EventDetails
- In cmd/cluster/context.go: override baseDomain with the region
  ID for HCP clusters, and pass externalClusterID (the external
  UUID) to WithClusterID — PD alerts reference the external UUID,
  not the internal OCM ID
- In cmd/org/context.go: update NewPDClient signature to accept
  clusterID, detect HCP clusters and pass cluster.ExternalID()

The critical fix is using ExternalID() rather than ID() when
filtering incidents. PagerDuty alerts contain the cluster's
external UUID in their EventDetails, so passing the internal
OCM ID would cause incidentMatchesCluster to always return false,
filtering out all incidents.

Related to ROSAENG-435
@fullsend-ai-coder fullsend-ai-coder Bot added the ready-for-review Triggers review agent dispatch label Sep 10, 2026
@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 255c1843-54e6-4301-b86a-0584fc0e69b4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 10, 2026

Copy link
Copy Markdown

🤖 Review · ⚠️ Cancelled · Started 3:28 PM UTC · Ended 3:29 PM UTC

Commit: fcf9c36 · View workflow run →

@openshift-ci

openshift-ci Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fullsend-ai-coder[bot]
Once this PR has been reviewed and has the lgtm label, please assign clcollins for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 10, 2026
@openshift-ci

openshift-ci Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Hi @fullsend-ai-coder[bot]. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 10, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 3:30 PM UTC · Completed 3:48 PM UTC

Commit: fcf9c36 · View workflow run →

Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $7.76

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Sep 10, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Sep 10, 2026

Copy link
Copy Markdown

Risk Assessment: low (1/5)

Details

Low-risk change: moderate line count but well-scoped to 5 files with good test coverage (40% test files), no protected paths or security-sensitive files touched, no dependency or CI changes, bot author with prior contributions, and changed files show low recent churn.

Previous run

Risk Assessment: moderate (2/5)

Details

Small-to-medium change (5 files, 404 lines) adding HCP PagerDuty incident lookup support by a bot author. No protected paths, security-sensitive files, CI, or dependency changes. Good test coverage ratio (0.40). cmd/cluster/context.go has notable regression history but no recent churn. Overall risk remains moderate, consistent with prior assessment.

Previous run (2)

Risk Assessment: moderate (2/5)

Details

Small focused change (5 files, 296 lines) adding HCP PagerDuty incident lookup support by a bot author. No protected paths, no security-sensitive files, no CI or dependency changes. Good test coverage ratio (0.40). Most files stable for over a year but change scope is well-contained.

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 10, 2026

Copy link
Copy Markdown

Review

Findings

Medium

  • [error handling / output corruption] pkg/provider/pagerduty/pagerduty.go:143 — The fmt.Printf("Skipping incident %d (%s): does not match cluster %s\n", ...) calls in GetFiringAlertsForCluster (line 143) and GetHistoricalAlertsForCluster (line 210) write to stdout. Both osdctl cluster context -o json and osdctl org context -o json also write structured JSON to stdout. When HCP filtering occurs, these debug messages corrupt the JSON output for downstream consumers (e.g., jq, scripts). This is also inconsistent with the codebase logging pattern — the pagerduty package uses fmt.Printf only for genuine error conditions.
    Remediation: Replace fmt.Printf with fmt.Fprintf(os.Stderr, ...) or remove the debug logging entirely, since the filtering behavior is expected and validated by tests.

Low

  • [test adequacy] cmd/org/context_test.go:113TestNewPDClient_PassesClusterID only verifies the function signature accepts two parameters. While pagerduty_test.go has thorough unit tests for incidentMatchesCluster and HCP filtering, there is no integration-level test verifying that FetchContext correctly detects HCP clusters and passes the region as baseDomain and externalID as clusterID.
    Remediation: Add an integration test for the FetchContext HCP detection path.

  • [edge case] pkg/provider/pagerduty/pagerduty.go:158 — When EventDetails is nil in incidentMatchesCluster, the incident is silently filtered out. If PagerDuty doesn't populate EventDetails for certain incident types (e.g., incidents created via the UI rather than an integration), legitimate HCP incidents could be silently dropped with no indication.

  • [duplicated-guard] cmd/cluster/context.go:198 — The guard o.cluster.Hypershift().Enabled() && o.cluster.Region() != nil && o.cluster.Region().ID() != "" appears twice in the same file (setup() and generateContextData()) and once in cmd/org/context.go. Computing the HCP check once in setup() and storing the result on contextOptions would reduce the maintenance surface.
    Remediation: Compute the HCP check once in setup() and store on contextOptions.

  • [test-organization] pkg/provider/pagerduty/pagerduty_test.go:73 — The WithClusterID test is placed in the "Provider Functionality" block alongside mock-backed integration tests. The existing file structure separates builder/setter tests under "Client Creation".
    Remediation: Move the WithClusterID test under the "Client Creation" Describe block.

  • [intent-tier-mismatch] — PR title uses the "fix" prefix but the change adds new HCP cluster support. While "fix" is defensible (making an existing feature work for a cluster type it previously didn't support), "feat" may be more accurate for changelog categorization.
    Remediation: Consider updating the PR title to use feat([ROSAENG-435](https://redhat.atlassian.net/browse/ROSAENG-435)).

  • [scope-coherence] pkg/provider/pagerduty/pagerduty.go — The PR bundles two incidental pre-existing bug fixes (pagination offset reset in GetFiringAlertsForCluster, incidents slice accumulation in GetHistoricalAlertsForCluster) alongside the HCP feature. Both fixes are correct and closely related to the modified code paths.

  • [architectural-coherence] cmd/org/context.go:41 — The NewPDClient signature change from one to two parameters is consistent with project patterns. If more parameters are needed in the future, consider refactoring to an options struct.


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run

Review

Findings

Medium

  • [logic-error] pkg/provider/pagerduty/pagerduty.go:176 — In GetHistoricalAlertsForCluster, the incidents slice is declared outside the outer for loop and is never reset between iterations over pdServiceIDs. When processing multiple service IDs, incidents from all previous services accumulate and are re-counted for every subsequent service, producing inflated IncidentOccurrenceTracker counts. This is a pre-existing bug not introduced by this PR, but the PR touches this exact code path, making it a reasonable time to fix.
    Remediation: Add incidents = incidents[:0] or incidents = nil immediately after for _, pdServiceID := range pdServiceIDs {.

Low

  • [edge-case] pkg/provider/pagerduty/pagerduty.go:157 — The incidentMatchesCluster function performs exact string equality checks on the cluster ID. No logging or metrics are emitted when incidents are filtered out, which could make debugging HCP incident visibility issues harder in production.

  • [test-organization] pkg/provider/pagerduty/pagerduty_test.go:23 — The new incidentMatchesCluster tests are added as a separate top-level Describe block, while the existing test file uses a single top-level Describe that nests all tests. Consider moving them inside the existing block for consistency.
    Remediation: Move the incidentMatchesCluster tests inside the existing Describe("Tests the Pagerduty Provider", ...) block.

  • [naming-convention] pkg/provider/pagerduty/pagerduty.go:51WithClusterID uses uppercase ID, while the existing WithTeamIdList uses lowercase Id. The new method follows Go naming conventions correctly (ID all-caps); the pre-existing WithTeamIdList is the one that deviates.


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run (2)

Review

Findings

Medium

  • [missing filtering] pkg/provider/pagerduty/pagerduty.go:134GetHistoricalAlertsForCluster does not apply cluster-ID filtering for HCP clusters. Since the same client (with clusterID set) is used for both GetFiringAlertsForCluster and GetHistoricalAlertsForCluster, historical alerts for HCP clusters will include incidents from ALL clusters in the region-based PD service, not just the target cluster. GetHistoricalAlertsForCluster would also need to request first_trigger_log_entries via the Includes option to make filtering possible.
    Remediation: Apply the same incidentMatchesCluster filtering in GetHistoricalAlertsForCluster when c.clusterID is set (and include first_trigger_log_entries in the options), or document that historical alerts intentionally show region-wide data for HCP.

Low

  • [pagination bug] pkg/provider/pagerduty/pagerduty.go:106 — Pre-existing bug preserved by this PR: incidentListOffset is declared outside the outer for loop over pdServiceIDs and is never reset to 0 when iteration moves to the next service ID. When multiple service IDs are provided and the first service has paginated results, the second service's API call starts at a non-zero offset, potentially missing incidents.
    Remediation: Reset incidentListOffset to 0 at the start of each outer loop iteration.

  • [inconsistent HCP detection] cmd/cluster/context.go:389 — In generateContextData(), the HCP check for setting the cluster ID uses only o.cluster.Hypershift().Enabled(), while setup() additionally guards with o.cluster.Region() != nil && o.cluster.Region().ID() != "". If an HCP cluster has no region, setup() would NOT override baseDomain, but generateContextData() would still call WithClusterID, enabling filtering against a baseDomain that holds the DNS domain.
    Remediation: Use the same compound condition in generateContextData().

  • [scope-coherence] cmd/cluster/context.go:200baseDomain field is overloaded with the region ID for HCP clusters. Semantically baseDomain represents a DNS base domain but is repurposed as a PD service query string. Functional but could cause confusion if baseDomain is used elsewhere for DNS-related purposes.
    Remediation: Consider introducing a separate variable (e.g., pdServiceQuery) to distinguish between DNS base domain and PD service lookup key.

  • [api-design-coherence] cmd/org/context.go:44NewPDClient function signature was changed to include clusterID as a parameter, while cmd/cluster/context.go uses the builder pattern directly via WithClusterID(). The two code paths use inconsistent approaches for threading the same value.


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Sep 10, 2026

Copy link
Copy Markdown
Author

🤖 Finished Fix · ✅ Success · Started 3:49 PM UTC · Completed 4:05 PM UTC

Commit: fcf9c36 · View workflow run →

Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $2.01

- Add cluster-ID filtering to GetHistoricalAlertsForCluster for HCP
  clusters, matching the existing filtering in GetFiringAlertsForCluster.
  Requests first_trigger_log_entries and filters by incidentMatchesCluster
  when clusterID is set.
- Fix pre-existing pagination bug: reset incidentListOffset to 0 at the
  start of each outer loop iteration over pdServiceIDs in
  GetFiringAlertsForCluster.
- Make HCP detection in generateContextData() consistent with setup() by
  adding Region() != nil && Region().ID() != "" guards.

Addresses #962
@fullsend-ai-coder

Copy link
Copy Markdown
Author

🔧 Fix agent — iteration 1 (bot-triggered)

Addressed 3 of 5 review findings with code fixes: added cluster-ID filtering to GetHistoricalAlertsForCluster for HCP clusters, fixed the pre-existing pagination offset bug in GetFiringAlertsForCluster, and made the HCP detection guard consistent between setup() and generateContextData(). Disagreed with 2 findings (scope-coherence and api-design-coherence) as out-of-scope refactoring suggestions. All 29 PagerDuty tests pass (2 new). All changed packages compile and pass go vet.

Fixed (3):

  1. missing filtering (pkg/provider/pagerduty/pagerduty.go): Applied the same incidentMatchesCluster filtering in GetHistoricalAlertsForCluster when c.clusterID is set, and included first_trigger_log_entries in the Includes option to make filtering possible. Added two tests covering HCP filtering and classic (unfiltered) behavior.
  2. pagination bug (pkg/provider/pagerduty/pagerduty.go): Reset incidentListOffset to 0 at the start of each outer loop iteration over pdServiceIDs in GetFiringAlertsForCluster, preventing the second service's API call from starting at a stale offset.
  3. inconsistent HCP detection (cmd/cluster/context.go): Added Region() != nil && Region().ID() != "" guards to the HCP check in generateContextData() to match the compound condition used in setup(), ensuring WithClusterID is only called when baseDomain has been overridden to the region ID.

Disagreed (2):

  1. scope-coherence: Introducing a separate pdServiceQuery variable is a refactoring suggestion beyond the scope of this PR. The baseDomain overloading is clearly documented with inline comments explaining the HCP behavior, and baseDomain is not used for DNS purposes after the override point. This change would touch multiple call sites across files for a cosmetic improvement.
  2. api-design-coherence: The two code paths use different patterns for valid architectural reasons: cmd/cluster/context.go builds the PD client inline and has direct access to the builder, while cmd/org/context.go uses a function variable (NewPDClient) for testability and dependency injection. Making them consistent would require either removing the testable function variable pattern in org/context.go or wrapping the builder in cluster/context.go behind a function variable it doesn't need — both would be larger refactors beyond this PR's scope.

Tests: passed

Decision points
  • Whether to fix the pre-existing pagination bug (alternatives: Fix it since it's in code already being modified, Leave it as out of scope since it's pre-existing; rationale: Fixed it because it's a trivial one-liner in code the PR already modifies, and the reviewer explicitly flagged it.)

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push
    Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 10, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 4:06 PM UTC · Completed 4:25 PM UTC

Commit: 04befce · View workflow run →

Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $6.97

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Sep 10, 2026

Copy link
Copy Markdown
Author

🤖 Finished Fix · ✅ Success · Started 4:26 PM UTC · Completed 4:36 PM UTC

Commit: 04befce · View workflow run →

Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $1.97

- Fix pre-existing bug in GetHistoricalAlertsForCluster where the
  incidents slice was not reset between service ID iterations, causing
  inflated IncidentOccurrenceTracker counts for subsequent services
- Add debug logging when incidents are filtered out by
  incidentMatchesCluster to aid HCP incident visibility debugging
- Move incidentMatchesCluster tests inside existing Describe block
  for consistency with test file organization

Addresses #962
@fullsend-ai-coder

Copy link
Copy Markdown
Author

🔧 Fix agent — iteration 2 (bot-triggered)

Fixed incidents slice accumulation bug in GetHistoricalAlertsForCluster, added debug logging for filtered incidents, and reorganized incidentMatchesCluster tests into the existing test structure. All 27 pagerduty tests and the org context test pass.

Fixed (3):

  1. incidents slice not reset between service IDs in GetHistoricalAlertsForCluster (pkg/provider/pagerduty/pagerduty.go): Added incidents = incidents[:0] at the start of the outer for loop to reset the slice between service ID iterations, preventing inflated IncidentOccurrenceTracker counts
  2. No logging when incidents are filtered out by incidentMatchesCluster (pkg/provider/pagerduty/pagerduty.go): Added fmt.Printf debug logging in both GetFiringAlertsForCluster and GetHistoricalAlertsForCluster when incidents are skipped due to cluster ID mismatch
  3. incidentMatchesCluster tests in separate top-level Describe block (pkg/provider/pagerduty/pagerduty_test.go): Moved incidentMatchesCluster tests from a separate top-level Describe block into the existing 'Tests the Pagerduty Provider' Describe block as a Context under 'Provider Functionality'

Disagreed (1):

  1. WithClusterID uses uppercase ID while WithTeamIdList uses lowercase Id: The reviewer explicitly notes that WithClusterID follows Go naming conventions correctly and WithTeamIdList is the one that deviates. Renaming WithTeamIdList is out of scope for this PR as it is a pre-existing public API and not part of this PR's changes.

Tests: passed

Decision points
  • Whether to rename WithTeamIdList to WithTeamIDList for consistency (alternatives: Rename WithTeamIdList to follow Go conventions, Leave as-is since it is pre-existing and out of scope; rationale: Renaming would be a breaking change to an existing public API and is unrelated to HCP support. The reviewer acknowledged the new code is correct.)

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push
    Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 10, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 4:38 PM UTC · Completed 5:20 PM UTC

Commit: 5c96b53 · View workflow run →

Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high

@fullsend-ai-review fullsend-ai-review Bot added risk/low PR risk: low and removed risk/moderate PR risk: moderate labels Sep 10, 2026

@fullsend-ai-review fullsend-ai-review 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.

See the review comment for full details.

continue
}
incidents[pdServiceID] = append(incidents[pdServiceID], incident)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[medium] error handling / output corruption

The fmt.Printf("Skipping incident ...") calls in GetFiringAlertsForCluster (line 143) and GetHistoricalAlertsForCluster (line 210) write to stdout. Both osdctl cluster context -o json and osdctl org context -o json also write structured JSON to stdout. When HCP filtering occurs, these debug messages corrupt the JSON output for downstream consumers (e.g., jq, scripts). This is also inconsistent with the codebase logging pattern — the pagerduty package uses fmt.Printf only for genuine error conditions.

Suggested fix: Replace fmt.Printf with fmt.Fprintf(os.Stderr, ...) or remove the debug logging entirely, since the filtering behavior is expected and validated by tests.

Comment thread cmd/org/context_test.go
@@ -111,6 +111,29 @@ func TestFetchContext_NoSubscriptions(t *testing.T) {
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[low] test-inadequate

TestNewPDClient_PassesClusterID only verifies the function signature accepts two parameters. While pagerduty_test.go has thorough unit tests for incidentMatchesCluster and HCP filtering, there is no integration-level test verifying that FetchContext correctly detects HCP clusters and passes the region as baseDomain and externalID as clusterID.

Suggested fix: Add an integration test for the FetchContext HCP detection path.

// given cluster by inspecting the first trigger log entry's EventDetails for
// a matching cluster_id value. This is used for HCP clusters where PD services
// are region-based and contain incidents for multiple clusters.
func incidentMatchesCluster(incident pd.Incident, clusterID string) bool {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[low] edge-case

When EventDetails is nil in incidentMatchesCluster, the incident is silently filtered out. If PagerDuty doesn't populate EventDetails for certain incident types (e.g., incidents created via the UI rather than an integration), legitimate HCP incidents could be silently dropped.

Comment thread cmd/cluster/context.go
o.clusterID = o.cluster.ID()
o.externalClusterID = o.cluster.ExternalID()
o.baseDomain = o.cluster.DNS().BaseDomain()
// HCP clusters use region-based PD services rather than per-cluster

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[low] pattern-violation

The HCP detection guard appears identically in two places within the same file (setup() and generateContextData()) and once in cmd/org/context.go. Computing the HCP check once in setup() and storing the result on contextOptions would reduce the maintenance surface.

Suggested fix: Compute the HCP check once in setup() and store on contextOptions.

ctrl.Finish()
})

Context("WithClusterID", func() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[low] code-organization

The WithClusterID test is placed in the Provider Functionality block alongside mock-backed integration tests. The existing file structure separates builder/setter tests under Client Creation.

Suggested fix: Move the WithClusterID test under the Client Creation Describe block.

Comment thread cmd/org/context.go
@@ -41,7 +41,7 @@ type DefaultContextFetcher struct {
GetLimitedSupport func(*sdk.Connection, string) ([]*cmv1.LimitedSupportReason, error)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[low] design-direction

The NewPDClient signature change from one to two parameters is consistent with project patterns. If more parameters are needed in the future, consider refactoring to an options struct.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Sep 10, 2026

Copy link
Copy Markdown
Author

🤖 Finished Fix · ✅ Success · Started 5:21 PM UTC · Completed 5:43 PM UTC

Commit: 5c96b53 · View workflow run →

Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $2.73

- Remove fmt.Printf stdout debug logging that corrupts JSON output
  when HCP filtering skips incidents; add stderr warning only for
  nil EventDetails edge case (visibility for silent drops)
- Deduplicate HCP region guard: compute once in setup() and store
  as isHCPRegionBased on contextOptions
- Move WithClusterID test to "Client Creation" describe block

Addresses #962
@fullsend-ai-coder

Copy link
Copy Markdown
Author

🔧 Fix agent — iteration 3 (bot-triggered)

Addressed 4 of 8 review findings with code changes: removed stdout-corrupting debug logging, added stderr warning for nil EventDetails edge case, deduplicated HCP guard in cmd/cluster/context.go, and moved WithClusterID test to correct describe block. Recorded reasoned disagreements for the remaining 4 findings (integration test scope, PR title convention, scope coherence observation, future architectural suggestion).

Fixed (4):

  1. error handling / output corruption (pkg/provider/pagerduty/pagerduty.go): Removed fmt.Printf stdout debug logging from GetFiringAlertsForCluster and GetHistoricalAlertsForCluster that would corrupt JSON output when HCP filtering skips non-matching incidents
  2. edge case: nil EventDetails silent drop (pkg/provider/pagerduty/pagerduty.go): Added fmt.Fprintf(os.Stderr, ...) warning in incidentMatchesCluster when EventDetails is nil, so incidents without EventDetails are no longer silently dropped — users see a diagnostic message on stderr
  3. duplicated-guard (cmd/cluster/context.go): Added isHCPRegionBased field to contextOptions, computed once in setup(), and replaced the duplicated compound guard in generateContextData() with the stored boolean
  4. test-organization: WithClusterID test placement (pkg/provider/pagerduty/pagerduty_test.go): Moved WithClusterID test from the Provider Functionality describe block to the Client Creation describe block, consistent with other builder/setter tests

Disagreed (4):

  1. test adequacy: integration test for FetchContext HCP detection: Adding an integration test for FetchContext HCP detection requires mocking OCM cluster objects with Hypershift and Region builders, which is complex test infrastructure not present in cmd/org/context_test.go. The HCP filtering logic is thoroughly tested in pagerduty_test.go (6 unit tests for incidentMatchesCluster, 4 for HCP filtering in GetFiringAlertsForCluster, 2 for GetHistoricalAlertsForCluster). The FetchContext wiring is straightforward and already covered by the existing TestNewPDClient_PassesClusterID. An integration test would be a valuable follow-up but is out of scope for this PR.
  2. intent-tier-mismatch: PR title fix vs feat: The fix prefix is defensible — the change makes an existing feature (PagerDuty incident lookup) work correctly for a cluster type (HCP) it previously did not support. Additionally, the fix agent cannot modify PR titles. This is a judgment call for the PR author.
  3. scope-coherence: bundled pre-existing bug fixes: Informational observation acknowledged. The reviewer notes both fixes are correct and closely related to the modified code paths. No action required.
  4. architectural-coherence: NewPDClient options struct: The current two-parameter signature is consistent with project patterns as the reviewer acknowledges. Refactoring to an options struct is a valid future consideration but out of scope for this PR.

Tests: passed

Decision points
  • Remove stdout debug logging vs redirect to stderr (alternatives: Remove debug logging entirely, Redirect all skipped-incident messages to stderr; rationale: Removed the generic 'Skipping incident' messages entirely since filtering is expected behavior. Added stderr warning only for the nil EventDetails edge case, which is the one scenario that deserves operator visibility.)

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push
    Updated by fullsend fix agent

@fullsend-ai-review

Copy link
Copy Markdown

🤖 Review · Started 5:44 PM UTC

Commit: 24c9674 · View workflow run →

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

Labels

needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. ready-for-review Triggers review agent dispatch risk/low PR risk: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants