Skip to content

test: add e2e test for OpenCensus to OpenTelemetry metrics migration#2811

Open
khrm wants to merge 2 commits into
tektoncd:mainfrom
khrm:e2e-otel-metrics-test
Open

test: add e2e test for OpenCensus to OpenTelemetry metrics migration#2811
khrm wants to merge 2 commits into
tektoncd:mainfrom
khrm:e2e-otel-metrics-test

Conversation

@khrm

@khrm khrm commented Jun 29, 2026

Copy link
Copy Markdown

Adds TestOTelMetrics, a consolidated e2e test for the OC→OTel metrics migration in Pipelines-as-Code (PR #2567). The test scrapes two pods:

Controller (app.kubernetes.io/name=controller):

  • Asserts http_client_* metrics from knative k8s client OTel instrumentation
  • Asserts go_* runtime metrics
  • Checks PAC application metrics (pipelines_as_code_*) are absent/present
  • Asserts old OC metric names are absent

Watcher (app.kubernetes.io/name=watcher):

  • Asserts kn_workqueue_* metrics (watcher uses knative reconciler)
  • Asserts go_* runtime metrics

Verified locally with PAC controller and watcher deployed to kind via ko.

Relates to #2567

📝 Description of the Change

🔗 Linked GitHub Issue

Fixes #

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

AI assistance can be used for various tasks, such as code generation,
documentation, or testing.

Please indicate whether you have used AI assistance
for this PR and provide details if applicable.

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Important

Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a new end-to-end test (test/metrics_otel_test.go) to verify the OpenCensus-to-OpenTelemetry metrics migration in Pipelines-as-Code by scraping the controller and watcher pods' metrics endpoints. The review feedback focuses on improving test robustness and efficiency: it recommends refactoring the metrics scraping helper to return errors instead of calling t.Fatalf (which would prematurely abort the test on transient errors during polling), reusing a single pre-initialized Kubernetes client across helper functions, and adding the necessary fmt import.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread test/metrics_otel_test.go
Comment thread test/metrics_otel_test.go Outdated
Comment thread test/metrics_otel_test.go Outdated
Comment thread test/metrics_otel_test.go Outdated
Comment thread test/metrics_otel_test.go Outdated
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.62%. Comparing base (2a84139) to head (4ce4736).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2811   +/-   ##
=======================================
  Coverage   61.62%   61.62%           
=======================================
  Files         213      213           
  Lines       17512    17512           
=======================================
  Hits        10792    10792           
  Misses       5901     5901           
  Partials      819      819           
Flag Coverage Δ
unit-tests 61.62% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 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.

@khrm khrm force-pushed the e2e-otel-metrics-test branch from d4ec0f5 to 7c391cc Compare June 29, 2026 12:57
@khrm

khrm commented Jun 29, 2026

Copy link
Copy Markdown
Author

//gemini help

@gemini-code-assist

Copy link
Copy Markdown
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@khrm

khrm commented Jun 29, 2026

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a new E2E test file test/metrics_otel_test.go to verify the OpenCensus-to-OpenTelemetry metrics migration in Pipelines-as-Code by scraping and asserting metrics from the controller and watcher pods. The feedback recommends parameterizing the waitForPACMetric helper function with a labelSelector parameter. This allows reusing the helper to poll and wait for the watcher pod's metrics, resolving potential test flakiness caused by scraping the watcher metrics only once without retries.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread test/metrics_otel_test.go Outdated
Comment thread test/metrics_otel_test.go Outdated
Comment thread test/metrics_otel_test.go Outdated
@khrm khrm force-pushed the e2e-otel-metrics-test branch from 7c391cc to 16c8b75 Compare June 29, 2026 13:12
Comment thread test/metrics_otel_test.go Outdated

// ========== Infrastructure metric assertions (OTel renames) ==========

t.Run("Renames/k8s_client_uses_http_client_prefix", func(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

plesae use testcase as per convention on this repo insteda of t.Run...

@khrm khrm force-pushed the e2e-otel-metrics-test branch 8 times, most recently from 317d87a to da6459d Compare June 29, 2026 14:19
@zakisk zakisk force-pushed the e2e-otel-metrics-test branch from da6459d to 3337cc1 Compare June 29, 2026 15:18
Comment thread test/metrics_otel_test.go Outdated
@khrm khrm force-pushed the e2e-otel-metrics-test branch 4 times, most recently from 44bfe89 to b6ca870 Compare June 29, 2026 18:37
Comment thread test/metrics_otel_test.go
// and asserts that pipelines_as_code_pipelinerun_count_total increments by
// exactly 1. The test skips automatically if Gitea is not configured
// (TEST_GITEA_API_URL and related env vars are unset).
func TestOthersOTelMetricsAfterPACRun(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This e2e test is failing in the CI === RUN TestOthersOTelMetricsAfterPACRun {"level":"info","ts":1782788949.960166,"caller":"gitea/gitea.go:290","msg":"gitea: initialized API client with provided credentials user=pac providerURL=http://localhost:3000"} {"level":"info","ts":1782788949.964509,"caller":"cctx/ctx.go:19","msg":"Found pipelines-as-code installation in namespace pipelines-as-code"} {"level":"info","ts":1782788949.9646285,"caller":"cctx/ctx.go:22","msg":"Pipelines as Code Controller: &{Name:default Configmap:pipelines-as-code Secret:pipelines-as-code-secret GlobalRepository:pipelines-as-code}"} {"level":"info","ts":1782788949.9674673,"caller":"repository/create.go:17","msg":"Namespace pac-e2e-test-2w5pv created"} {"level":"info","ts":1782788949.9676106,"caller":"gitea/scm.go:151","msg":"Creating gitea repository pac-e2e-test-2w5pv for user pac"} {"level":"info","ts":1782788950.389976,"caller":"gitea/scm.go:163","msg":"Creating webhook to smee url on gitea repository pac-e2e-test-2w5pv"} {"level":"info","ts":1782788950.909148,"caller":"repository/create.go:26","msg":"PipelinesAsCode Repository pac-e2e-test-2w5pv has been created in namespace pac-e2e-test-2w5pv"} {"level":"info","ts":1782788951.527173,"caller":"scm/scm.go:48","msg":"Pushed files to repo https://gitea.paac-127-0-0-1.nip.io/pac/pac-e2e-test-2w5pv branch pac-e2e-test-2w5pv"} {"level":"info","ts":1782788956.5320754,"caller":"gitea/test.go:254","msg":"Creating PullRequest"} {"level":"info","ts":1782788957.0262525,"caller":"gitea/test.go:269","msg":"PullRequest https://gitea.paac-127-0-0-1.nip.io/pac/pac-e2e-test-2w5pv/pulls/1 has been created"} {"level":"info","ts":1782788957.17538,"caller":"gitea/test.go:477","msg":"Number of gitea status on PR: 0/1"} {"level":"info","ts":1782788962.3255165,"caller":"gitea/test.go:474","msg":"Status on SHA: pac-e2e-test-2w5pv is success from Pipelines as Code CI / always-good-pipelinerun"} {"level":"info","ts":1782788962.325611,"caller":"gitea/test.go:477","msg":"Number of gitea status on PR: 1/1"} {"level":"info","ts":1782788962.3256638,"caller":"gitea/test.go:542","msg":"Looking for regexp \".*Pipelines as Code CI.*has.*successfully.*validated your commit.*\" in PR comments"} {"level":"info","ts":1782788962.4651678,"caller":"gitea/test.go:548","msg":"Found regexp in comment: Pipelines as Code CI/always-good-pipelinerun-z9rnx has successfully validated your commit.\n
    \n
  • Namespace: pac-e2e-test-2w5pv
  • \n
  • PipelineRun: always-good-pipelinerun-z9rnx
  • \n
\n
\n

Task Statuses:

\n\n\n \n\n\n\n
StatusDurationName
Succeeded3 seconds\n\n[The Task name is Task](http://dashboard.paac-127-0-0-1.nip.io/#/namespaces/pac-e2e-test-2w5pv/pipelineruns/always-good-pipelinerun-z9rnx?pipelineTask=task)\n\n
"} metrics_otel_test.go:314: Timed out waiting for metric "pipelines_as_code_pipelinerun_count_total" (selector=app.kubernetes.io/name=controller,app.kubernetes.io/part-of=pipelines-as-code, waited 2m0s): context deadline exceeded setup.go:87: Deleted gitea repo pac/pac-e2e-test-2w5pv --- FAIL: TestOthersOTelMetricsAfterPACRun (132.88s) FAIL FAIL github.com/openshift-pipelines/pipelines-as-code/test 1007.891s

Comment thread test/metrics_otel_test.go
if err != nil {
t.Skipf("PAC controller metrics not reachable, skipping: %v", err)
}
baseCount := counterValue(baseline, "pipelines_as_code_pipelinerun_count_total")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@khrm actually it's pipelines_as_code_pipelinerun_count not pipelines_as_code_pipelinerun_count_total that's why the test is failing

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The OTEL exporter should add total suffix. Need to check why it's not happening?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Actually, I was scapping from controller instead of watcher.

@khrm khrm force-pushed the e2e-otel-metrics-test branch from b6ca870 to 258e7e9 Compare June 30, 2026 15:21
@khrm khrm force-pushed the e2e-otel-metrics-test branch from 258e7e9 to 731dc35 Compare June 30, 2026 15:38
@khrm khrm force-pushed the e2e-otel-metrics-test branch from 731dc35 to 91da0b3 Compare June 30, 2026 16:01

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@khrm You should try running the e2e on a local setup for validation.
Refs 1, 2

Moving this PR to draft while you resolve these issues.

@theakshaypant theakshaypant marked this pull request as draft July 3, 2026 11:50
Adds TestOTelMetrics, a consolidated e2e test for the OC→OTel metrics
migration in Pipelines-as-Code (PR tektoncd#2567). The test scrapes two pods:

Controller (app.kubernetes.io/name=controller):
- Asserts http_client_* metrics from knative k8s client OTel instrumentation
- Asserts go_* runtime metrics
- Checks PAC application metrics (pipelines_as_code_*) are absent/present
- Asserts old OC metric names are absent

Watcher (app.kubernetes.io/name=watcher):
- Asserts kn_workqueue_* metrics (watcher uses knative reconciler)
- Asserts go_* runtime metrics

Verified locally with PAC controller and watcher deployed to kind via ko.

Relates to tektoncd#2567

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@khrm khrm force-pushed the e2e-otel-metrics-test branch from 2d5d489 to b34fae7 Compare July 8, 2026 14:51
@khrm khrm marked this pull request as ready for review July 8, 2026 14:56

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, overall.
Green CI is a very positive sign. Got a couple minor comments.

Comment thread test/metrics_otel_test.go
Comment on lines +272 to +273
// exactly 1 on the watcher pod. The test skips automatically if Gitea is not
// configured (TEST_GITEA_API_URL and related env vars are unset).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test skips automatically if Gitea is not
// configured

Is that correct? I believe the other tests fail if the env vars are not set.

Comment thread test/metrics_otel_test.go
Comment on lines +208 to +216
// Old OC metric names must be absent.
// TODO: Remove in a future release once no OC-based release is supported.
for name := range families {
for _, prefix := range []string{"pipelines_as_code/", "tekton_pipelines_as_code_"} {
if strings.HasPrefix(name, prefix) {
t.Errorf("Old OC metric %q still present; expected removal after OTel migration", name)
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should the same check be present for watcher metrics test as well?

@chmouel chmouel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not know much about metrics, but this LGTM to me, please see comments of other reviewers tho

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.

5 participants