Skip to content

🌱 Deduplicate metrics service lookup and port-forward in e2e steps#2710

Open
pedjak wants to merge 1 commit into
operator-framework:mainfrom
pedjak:e2e-steps-cleanup
Open

🌱 Deduplicate metrics service lookup and port-forward in e2e steps#2710
pedjak wants to merge 1 commit into
operator-framework:mainfrom
pedjak:e2e-steps-cleanup

Conversation

@pedjak
Copy link
Copy Markdown
Contributor

@pedjak pedjak commented May 18, 2026

Description

SendMetricsRequest (in steps.go) and withMetricsPortForward (in tls_steps.go) duplicated two chunks of logic:

  1. Service endpoint discovery — both queried for the service namespace via the same jsonpath, unmarshalled corev1.Service, and looped its ports looking for "metrics".
  2. Port-forward lifecycle — both called randomAvailablePort(), built a kubectl port-forward command, started it, and deferred kill+wait cleanup.

This PR extracts shared helpers and rewrites both callers to use them:

  • getMetricsService(component) (*corev1.Service, error) — returns the full Service object (namespace available via svc.Namespace)
  • metricsPort(svc) (int32, error) — extracts the metrics port from a service
  • portForward(ns, target, remotePort) (addr, cleanup, error) — reusable port-forward lifecycle
  • randomAvailablePort moved from steps.go to tls_steps.go alongside portForward

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

Copilot AI review requested due to automatic review settings May 18, 2026 13:46
@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 2ebc4dc
🔍 Latest deploy log https://app.netlify.com/projects/olmv1/deploys/6a0b38ab27bd830008887e40
😎 Deploy Preview https://deploy-preview-2710--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

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 reduces duplication in e2e metrics/TLS step helpers by centralizing metrics service discovery and kubectl port-forward setup/cleanup.

Changes:

  • Extracts shared helpers for metrics service lookup, metrics port selection, random port allocation, and port-forward startup.
  • Rewrites TLS metrics port-forwarding and metrics request steps to use the shared helpers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/e2e/steps/tls_steps.go Adds shared metrics service and port-forward helpers; updates TLS metrics forwarding to use them.
test/e2e/steps/steps.go Updates metrics request flow to use shared service lookup and port-forward helper.

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

Comment thread test/e2e/steps/steps.go Outdated
sc.metricsResponse = make(map[string]string)
for _, p := range pods {
port, err := randomAvailablePort()
addr, cleanup, err := portForward(p.Namespace, fmt.Sprintf("pod/%s", p.Name), mPort)
@perdasilva
Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label May 18, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.14%. Comparing base (5a1207d) to head (2ebc4dc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2710      +/-   ##
==========================================
+ Coverage   68.12%   68.14%   +0.01%     
==========================================
  Files         145      145              
  Lines       10698    10698              
==========================================
+ Hits         7288     7290       +2     
+ Misses       2880     2879       -1     
+ Partials      530      529       -1     
Flag Coverage Δ
e2e 37.15% <ø> (-0.03%) ⬇️
experimental-e2e 52.75% <ø> (+0.13%) ⬆️
unit 53.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 18, 2026

New changes are detected. LGTM label has been removed.

@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label May 18, 2026
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 18, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from perdasilva. 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

SendMetricsRequest and withMetricsPortForward duplicated service
endpoint discovery and port-forward lifecycle code. Extract shared
helpers (getMetricsService, metricsPort, portForward) and rewrite
both callers to use them. Port-forward cleanup is deferred to avoid
process leaks if waitFor panics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pedjak pedjak force-pushed the e2e-steps-cleanup branch from fe745b0 to 2ebc4dc Compare May 18, 2026 16:04
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