Skip to content

feat(gcp): add GCP PSC conditions to metrics and platform-specific gauges - #9254

Closed
apahim wants to merge 6 commits into
openshift:mainfrom
apahim:gcp-959
Closed

feat(gcp): add GCP PSC conditions to metrics and platform-specific gauges#9254
apahim wants to merge 6 commits into
openshift:mainfrom
apahim:gcp-959

Conversation

@apahim

@apahim apahim commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements GCP-959 (GA checklist items 6.1, 6.2, 6.3): add PSC connectivity conditions to failure metrics and transition duration histograms, and expose a GCP credential validity gauge.

Changes

1. GCP GetCredentialStatus foundation (gcp.go)

  • Add CredentialStatus type (Valid=0, Invalid=1, Unknown=2) mirroring the AWS pattern
  • Add GetCredentialStatus() inspecting ValidGCPWorkloadIdentity and ValidGCPCredentials conditions

2. PSC conditions in ExpectedHCConditions() (support/conditions/conditions.go)

  • Add GCPEndpointAvailable and GCPServiceAttachmentAvailable to the GCP case unconditionally
  • Unlike AWS, GCP has no Public-only endpoint access mode — both GCP modes use PSC, so no gate is needed
  • Impact: PSC failures now appear in hypershift_hostedclusters_failure_conditions

3. PSC conditions in transition duration metrics (metrics.go)

  • Add GCPEndpointAvailable and GCPServiceAttachmentAvailable to collectTransitionDurationMetrics()
  • Impact: PSC setup latency tracked in hypershift_hosted_cluster_transition_seconds histogram

4. hypershift_cluster_invalid_gcp_creds gauge (metrics.go)

  • Add metric constant, descriptor, collectGcpCredsMetric() function
  • Called unconditionally from collectPerClusterMetrics() — non-GCP clusters report 2 (unknown)

Tests

  • TestGetCredentialStatus — all condition combinations for the GCP tri-state function
  • TestReportInvalidGcpCreds — gauge metric collection for all credential states
  • TestReportTransitionDurationForGCPEndpointConditions — histogram observation for PSC conditions
  • TestExpectedHCConditionsGCPPlatform — expected conditions for GCP platform

Jira: https://redhat.atlassian.net/browse/GCP-959

Summary by CodeRabbit

  • New Features

    • Added GCP credential-status reporting for HostedClusters, distinguishing valid, invalid, and unknown states.
    • Added GCP credential validity metrics.
    • Added transition-duration metrics for GCP endpoint and service-attachment conditions.
    • GCP hosted clusters now report endpoint and service-attachment availability conditions.
  • Bug Fixes

    • Improved handling of missing, unknown, and mixed credential conditions in status reporting.

apahim added 6 commits August 6, 2026 14:48
Add a tri-state CredentialStatus type (Valid=0, Invalid=1, Unknown=2)
and GetCredentialStatus function to the GCP platform package, mirroring
the existing AWS pattern in platform/aws.

GetCredentialStatus checks ValidGCPWorkloadIdentity and ValidGCPCredentials
conditions: returns Invalid if either is False, Valid if both are True,
and Unknown otherwise (missing or Unknown conditions). The Unknown state
also covers non-GCP clusters naturally, matching AWS behavior.

This is a prerequisite for the hypershift_cluster_invalid_gcp_creds
Prometheus gauge introduced in a subsequent commit.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
… to ExpectedHCConditions

Both GCP endpoint access modes (Private and PublicAndPrivate) use Private
Service Connect, so PSC conditions are included unconditionally in the GCP
case — there is no GCPEndpointAccessPublic constant unlike AWS.

This causes PSC failures to appear in the
hypershift_hostedclusters_failure_conditions metric.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
…trics

Track GCP Private Service Connect setup latency and credential validity
in Prometheus, mirroring existing AWS metric patterns.

Transition duration (hypershift_hosted_cluster_transition_seconds):
- Add GCPEndpointAvailable and GCPServiceAttachmentAvailable to the
  condition slice in collectTransitionDurationMetrics so PSC setup
  latency is captured in the histogram.

Credentials gauge (hypershift_cluster_invalid_gcp_creds):
- New gauge emitting 0=valid, 1=invalid, 2=unknown per HostedCluster.
- Calls gcp.GetCredentialStatus; non-GCP clusters report Unknown (2),
  consistent with the AWS collectAwsCredsMetric pattern.
- Wired unconditionally into collectPerClusterMetrics.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
- Rename all new GCP test case names to follow the required
  "When ..., it should ..." format per TESTING.md conventions.
- Add two mixed False/Unknown condition test cases to TestGetCredentialStatus
  to cover the contract that False overrides Unknown, producing Invalid status.
- Add matching mixed cases to TestReportInvalidGcpCreds expecting gauge value 1.
- Fix TestReportTransitionDurationForGCPEndpointConditions case names to
  follow the same convention.

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
Add support/conditions/conditions_test.go to cover the GCP-specific
conditions added to ExpectedHCConditions. The file had 0% patch coverage
as reported by Codecov; these tests bring the GCP case to full coverage.

Tests verify that all four GCP-specific conditions are present and set
to True for GCP clusters, and absent for non-GCP clusters:
- ValidGCPWorkloadIdentity
- ValidGCPCredentials
- GCPEndpointAvailable
- GCPServiceAttachmentAvailable

Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
Signed-off-by: Amador Pahim <apahim@redhat.com>
Commit-Message-Assisted-by: Claude (via Claude Code)
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci openshift-ci Bot added do-not-merge/needs-area area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release labels Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 2578d589-9620-40b8-81f8-e0557a021ab1

📥 Commits

Reviewing files that changed from the base of the PR and between 8ddee28 and 4a61331.

📒 Files selected for processing (6)
  • hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp.go
  • hypershift-operator/controllers/hostedcluster/internal/platform/gcp/gcp_conditions_test.go
  • hypershift-operator/controllers/hostedcluster/metrics/metrics.go
  • hypershift-operator/controllers/hostedcluster/metrics/metrics_test.go
  • support/conditions/conditions.go
  • support/conditions/conditions_test.go

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting


📝 Walkthrough

Walkthrough

This change adds tri-state GCP credential evaluation for HostedClusters. The metrics collector exposes credential status and tracks GCP endpoint and service-attachment condition transitions. Expected GCP conditions are marked true for GCP platforms and remain absent for AWS platforms. Tests cover credential states, metric values, transition observations, and platform-specific expected conditions.

Sequence Diagram(s)

sequenceDiagram
  participant HostedCluster
  participant MetricsCollector
  participant GCPPlatform
  participant Prometheus
  HostedCluster->>MetricsCollector: provide platform and conditions
  MetricsCollector->>GCPPlatform: GetCredentialStatus(HostedCluster)
  GCPPlatform-->>MetricsCollector: return credential status
  MetricsCollector->>Prometheus: emit GCP metrics
Loading

Possibly related PRs

Suggested reviewers: bryan-cox

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci openshift-ci Bot added area/platform/gcp PR/issue for GCP (GCPPlatform) platform and removed do-not-merge/needs-area labels Aug 7, 2026
@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: apahim
Once this PR has been reviewed and has the lgtm label, please assign bryan-cox 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

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

Labels

area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/platform/gcp PR/issue for GCP (GCPPlatform) platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant