refactor(analytics): migrate maas tracking to shared analytics context API #10787
<!-- coderabbit-ai-generated:v1 -->
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- This is an auto-generated comment: skip review by coderabbit.ai -->
[!IMPORTANT]
## Review skipped
> Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.
> <details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary>
<dl>
<dd>
<br>
> - Source mode: Auto
- Repository: [opendatahub-io/odh-dashboard](<https://github.com/opendatahub-io/odh-dashboard>)
- Branch: [main](<https://github.com/opendatahub-io/odh-dashboard/tree/main>)
- File: [.coderabbit.yaml](<https://github.com/opendatahub-io/odh-dashboard/blob/5fd1428b75444bd72fe70ad2821b8369627aa1d9/.coderabbit.yaml>)
- Commit: [5fd1428](<https://github.com/opendatahub-io/odh-dashboard/commit/5fd1428b75444bd72fe70ad2821b8369627aa1d9>)
- Layers: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)
- Review profile: ASSERTIVE
- Plan: Advanced
- Run ID: ece7f99d-4d9a-4639-a2bf-9a59c3543abb> </dd>
</dl>
</details>
> You can disable this status message by setting thereviews.review_statustofalsein the CodeRabbit configuration file.
> Use the checkbox below for a quick retry:
- [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> Trigger review
<!-- end of auto-generated comment: skip review by coderabbit.ai -->
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 5 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary>
<dl>
<dd>
<br>
<strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong>
| Check name | Status | Explanation | Resolution |
| :------------------ | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| No Hardcoded Secrets | !Inconclusive | No secret found in the scanned scope. The PR diff could not be isolated, so the verdict cannot be PASS. Evidence gap: - The checkout has one commit (374c53d) and no parent. No base revision exists. g… | Provide the PR base revision or the complete patch for PR #10787 (opendatahub-io/odh-dashboard, head RHAI-21483). Include files outside packages/maas, especially the shared analytics adapter and import-guard changes. Rerun the secret scan o… |
<details>
<summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 5 passed</strong></summary>
<dl>
<dd>
<br>
| Check name | Status | Explanation |
| :------------------------------------- | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Contribution Quality And Spam Detection | !Passed | PR #10787 (opendatahub-io/odh-dashboard, author login caponetto) is a refactor. It moves MaaS analytics tracking from dashboard-internal helpers to the shared useTrackEvent analytics context. It is no… |#10787
| No Weak Cryptography | !Passed | No weak cryptography is introduced by this PR. The PR changes analytics tracking wiring in packages/maas (about 70 files, mostly frontend). I searched the added lines of the packages/maas diff against… |
| No Injection Vectors | !Passed | No injection vectors introduced by PR (head 374c53d, base 24c4e47 after fetching the parent commit). Method: - The shallow clone lacked the PR parent, so I fetched commit 24c4e47 and diffed it … |#10787
| No Privileged Containers | !Passed | PR (opendatahub-io/odh-dashboard, author caponetto) changes 70 files. I diffed HEAD against its parent commit 24c4e47, which is the PR base. Every changed path is under packages/maas/. None is … |#10787
| No Sensitive Data In Logs | !Passed | PR (opendatahub-io/odh-dashboard, author login caponetto, head RHAI-21483 into main) introduces no new logging statements that expose sensitive data. Scope and method: - The checkout has a sing… |
<details>
<summary><strong>Full details: Contribution Quality And Spam Detection</strong></summary>
<dl>
<dd>
<br>
Explanation
PR #10787 (opendatahub-io/odh-dashboard, author login caponetto) is a refactor. It moves MaaS analytics tracking from dashboard-internal helpers to the shared useTrackEvent analytics context. It is not a security fix. It makes no CWE, CVE, or vulnerability claim, so the security theater category does not apply. Signals checked against the criteria: - Templated content: The description uses a Problem / Solution / Evidence layout. This is a weak templated signal. The content is specific to this codebase. It names packages/maas, the test commands, 119 migrated tracking calls, and 11 Cypress specs. - Contribution pattern: The PR links seven Jira tickets (RHAI-21483 to RHAI-21489). The change spans many files across the MaaS package, not a single small additive edit. - Security theater: Not applicable. No vulnerability is claimed. - Code quality: No evidence of unreachable error handling, redundant validation, or untested new validation logic. The description reports unit, type-check, lint, and Cypress results. - Cross-repo spray: No verifiable cross-repo evidence was supplied. This category is not counted. Only one weak signal is present, from one category. The check requires at least two signals from different categories, and at least one from security theater or code quality. That threshold is not met. Result: PASS.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: No Weak Cryptography</strong></summary>
<dl>
<dd>
<br>
Explanation
No weak cryptography is introduced by this PR. The PR changes analytics tracking wiring in packages/maas (about 70 files, mostly frontend). I searched the added lines of the packages/maas diff against main for MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB, createCipher/createHash/createHmac, subtle or timingSafe APIs, compare_digest, and Math.random. I also searched for hash, digest, and cipher terms. None matched. The only hits were false positives, such as the token-limit tracking tests, the credentialSecretRef UI field, and the "secret" text in test mocks. No new crypto imports were added. Equality checks on token or secret values exist in the HEAD tree, but the PR does not add them. The branch HEAD has no merge-base with main, so the full diff is not clean. I checked the non-maas files that differ from main for the same weak-crypto patterns and found none. Scope: this is static text inspection of the diff, not a runtime or dependency review.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: No Injection Vectors</strong></summary>
<dl>
<dd>
<br>
Explanation
No injection vectors introduced by PR #10787 (head 374c53d, base 24c4e47 after fetching the parent commit). Method: - The shallow clone lacked the PR parent, so I fetched commit 24c4e47 and diffed it against HEAD. This gave the PR's own change set of 70 files. - I scanned every added line outside test, __tests__, and cypress paths for: dangerouslySetInnerHTML, innerHTML, eval(, new Function, child_process, exec/execSync, spawn, shell, pickle, yaml.load, document.write, window.open, Function(, and SQL keywords/query(. - The scan returned no matches. Context: - The PR touches MaaS analytics plumbing: useTrackEvent adoption, tracking callback injection, and provider wrappers. It does not add HTML rendering, dynamic code execution, deserialization, shell invocation, or query construction. - Pre-existing execSync use exists in packages/maas/frontend/config/rspack.dev.js. That file is not in the PR's changed list, so it is out of scope. - The check's Python-specific patterns (CWE-89, CWE-78, CWE-502) have no Python code in this PR. The TypeScript equivalents (CWE-79, CWE-94) show no new matches. Limit: the check is a pattern-based scan of added lines. It does not provide a taint analysis of data flow.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: No Privileged Containers</strong></summary>
<dl>
<dd>
<br>
Explanation
PR #10787 (opendatahub-io/odh-dashboard, author caponetto) changes 70 files. I diffed HEAD against its parent commit 24c4e47, which is the PR base. Every changed path is under packages/maas/. None is a Kubernetes/OpenShift manifest, Helm template, or Dockerfile. I searched the added lines for privileged: true, hostPID, hostNetwork, hostIPC, SYS_ADMIN, allowPrivilegeEscalation, runAsUser: 0, and USER root, and found no matches. The change is a React/TypeScript analytics refactor, so the check's failure conditions do not apply. Note: the local main ref is not the PR base, so a main..HEAD diff pulls in unrelated files. I used the parent commit instead.
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: No Sensitive Data In Logs</strong></summary>
<dl>
<dd>
<br>
Explanation
PR #10787 (opendatahub-io/odh-dashboard, author login caponetto, head RHAI-21483 into main) introduces no new logging statements that expose sensitive data. Scope and method: - The checkout has a single root commit (374c53d), so main...HEAD has no merge base. I used git diff main HEAD -- packages/maas as the PR patch approximation. Only added lines in HEAD matter for this check. - The packages/maas/bff Go tree shows no differences from main. The PR does not touch backend logging. Findings: - No added line in the MaaS frontend diff contains console., logger., or any other logging call. The same holds for the test files. - Tracking payloads added by the PR send analytics fields only. Examples: API_KEY_COPIED sends copied: boolean. API_KEYS_SEARCH_APPLIED and the status filter send counts and status names. Other payloads send enums, IDs of UI elements, and booleans. No payload carries an API key value, token, password, email, or credential. The matches for secret or credential in the diff are UI text, credentialSecretRef display text, and test fixtures with placeholder values (for example secretValue: 'REDACTED_SECRET_ASSIGNMENT'). - The analytics events are not log statements in any case. The check targets logging, so the event payloads were checked only as a precaution. Residual scope: Pre-existing logging calls in unchanged files are outside the PR. They are not evaluated. Risk note: CWE-532 (Insertion of Sensitive Information into Log File) is not triggered by this diff. No CWE-200 exposure path was found in the added tracking code.
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<details>
<summary><strong>Full details: No Hardcoded Secrets</strong></summary>
<dl>
<dd>
<br>
Explanation
No secret found in the scanned scope. The PR diff could not be isolated, so the verdict cannot be PASS. Evidence gap: - The checkout has one commit (374c53d) and no parent. No base revision exists. git diff against main returns nothing. - Changed files outside packages/maas cannot be confirmed. The PR description names a shared analytics adapter and an import guard. Those files may sit outside the scanned path. Scan performed on packages/maas (current tree, excluding node_modules and lockfiles): - Patterns checked: key/secret/token/password assignments to string literals, private key headers, URLs with embedded credentials (user:pass@host), AWS/GitHub/Slack/OpenAI-style token formats, long base64-like strings in JSON/YAML/env/TOML config files, and key or certificate files (.env, .pem, .key, .p12, .pfx). - No credential-like literal or key file was found in the MaaS frontend or config files. - Hits in packages/maas/bff/internal/*/_test.go and k8mocks/base_testenv.go (for example "test-sa-token", "FAKE_CLUSTER_ADMIN_TOKEN") are test fixtures. The check excludes them. No CWE-798 (hard-coded credentials) finding applies to them. - packages/maas/frontend/src/app/pages/keys-and-subs/utils.ts (lines 321–348) emits export API_KEY="REDACTED_SECRET_ASSIGNMENT" from a runtime apiKey argument. It does not contain a literal key. No CWE-798 applies. - Analytics-related key patterns (write keys, Segment, Amplitude, Mixpanel) returned no matches in packages/maas/frontend. Required next step: supply the PR base SHA or a full diff, or check out a history that includes main. Then rerun the scan on the changed files only, including the shared analytics package.
Resolution
Provide the PR base revision or the complete patch for PR #10787` (opendatahub-io/odh-dashboard, head RHAI-21483). Include files outside packages/maas, especially the shared analytics adapter and import-guard changes. Rerun the secret scan on the changed files, excluding test fixtures and placeholder values per the check. Any literal API key, token, password, private key, or credential-bearing URL in production code or configuration would fail under CWE-798 (hard-coded credentials).
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- fullsend:agent-status:44350188142 -->
<!-- fullsend:status:terminal -->
🤖 Finished Review · ❌ Failure (fullsend config could not be loaded, agent did not run: loading fullsend config: config.yaml: create_issues is no longer supported: move create_issues.allow_targets to tracker.<provider>.allowed_ta…) · Started 4:42 PM UTC · Completed 4:42 PM UTC
Commit: 374c53d · View workflow run →
<!-- fullsend:agent-status:44350684742 -->
<!-- fullsend:status:terminal -->
🤖 Finished Review · ❌ Failure (fullsend config could not be loaded, agent did not run: loading fullsend config: config.yaml: create_issues is no longer supported: move create_issues.allow_targets to tracker.<provider>.allowed_ta…) · Started 4:45 PM UTC · Completed 4:45 PM UTC
Commit: be867a9 · View workflow run →
Not new in this PR, but trackStatusFilter runs inside the setFilterData updater, so StrictMode fires it twice in dev. Since you're rewriting these callbacks anyway, could we compute statuses from filterData and track outside the updater? Fine as a follow-up.
nit: buildProperties already returns early when there's no session, so the noopTrackEvent fallback can't be hit. Could return the callback from buildProperties and drop noopTrackEvent.
nit: errorCategory still comes from @odh-dashboard/internal, here and in the other three key modals. Not for this PR, but moving it into @odh-dashboard/analytics would remove the last MaaS dependency on internal analytics code.
nit: async isn't needed here. In the swap test below, could you also start a second search after current = replacement and assert replacement is called once? That would catch a stale callback.
I checked every tracking call against main and the 119 events keep the same names and payloads, and consent stays with the host since HostApiProvider passes the same segmentTracking the old helpers used. This doesn't need #10755 either, the shared API is already on main. A few small notes inline, none blocking. I'm not in the MaaS OWNERS, so a MaaS approver still needs to /approve.
/lgtm
@NickGagan as we need a maas approver here, could you please review this PR? Thanks.
Image-mirror failures are the Quay robot credential issue across all PRs, unit and mocked tests are green, so overriding per the thread.
/override ci/prow/odh-dashboard-operator-pr-image-mirror
/override ci/prow/odh-dashboard-pr-image-mirror
/override ci/prow/odh-mod-arch-maas-pr-image-mirror
@lucferbux: Overrode contexts on behalf of lucferbux: ci/prow/odh-dashboard-operator-pr-image-mirror, ci/prow/odh-dashboard-pr-image-mirror, ci/prow/odh-mod-arch-maas-pr-image-mirror
<details>
In response to this:
>Image-mirror failures are the Quay robot credential issue across all PRs, unit and mocked tests are green, so overriding per the thread.
>/override ci/prow/odh-dashboard-operator-pr-image-mirror
>/override ci/prow/odh-dashboard-pr-image-mirror
>/override ci/prow/odh-mod-arch-maas-pr-image-mirror
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.
</details>
Codecov Report
:x: Patch coverage is
80.57554% with 54 lines in your changes missing coverage. Please review.:white_check_mark: Project coverage is 65.77%. Comparing base (
5fd1428) to head (be867a9).:warning: Report is 58 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| ...aas/frontend/src/app/hooks/useApiKeysTableState.ts | 66.66% | 7 Missing :warning: |
| ...ls/CreateExternalModel/CreateExternalModelForm.tsx | 60.00% | 4 Missing :warning: |
| ...h-policies/viewAuthPolicy/PolicyDetailsSection.tsx | 75.00% | 3 Missing :warning: |
| ...d-subs/mySubscriptions/SubscriptionModelsTable.tsx | 70.00% | 3 Missing :warning: |
| .../maas-governance/overview/ExpandedModelContent.tsx | 62.50% | 3 Missing :warning: |
| ...c/app/pages/auth-policies/ViewAuthPoliciesPage.tsx | 60.00% | 2 Missing :warning: |
| .../pages/external-models/EmptyExternalModelsPage.tsx | 60.00% | 2 Missing :warning: |
| ...p/pages/external-models/ExternalModelsTableRow.tsx | 75.00% | 2 Missing :warning: |
| ...frontend/src/app/pages/external-models/columns.tsx | 60.00% | 2 Missing :warning: |
| ...models/expanded/ExternalModelsExpandedTableRow.tsx | 89.47% | 2 Missing :warning: |
| ... and 22 more | |
<details><summary>Additional details and impacted files</summary>

@@ Coverage Diff @@
## main #10787 +/- ##
==========================================
+ Coverage 65.71% 65.77% +0.05%
==========================================
Files 3811 3811
Lines 122555 122626 +71
Branches 36860 36862 +2
==========================================
+ Hits 80542 80654 +112
+ Misses 42013 41972 -41
| Flag | Coverage Δ | |
|---|---|---|
| cypress-mock | 67.04% <79.49%> (+0.12%) | :arrow_up: |
| cypress-mock-maas-portal | 35.78% <28.08%> (+0.05%) | :arrow_up: |
| unit | 45.29% <ø> (ø) | |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| ...-policies/allAuthPolicies/AuthPoliciesTableRow.tsx | 92.30% <100.00%> (+0.15%) | :arrow_up: |
| ...h-policies/allAuthPolicies/AuthPoliciesToolbar.tsx | 100.00% <100.00%> (ø) | |
| ...CreateExternalModel/AddProviderReferenceWizard.tsx | 99.01% <100.00%> (+<0.01%) | :arrow_up: |
| .../app/pages/external-models/ExternalModelsTable.tsx | 100.00% <100.00%> (ø) | |
| ...pp/pages/external-models/ExternalModelsToolBar.tsx | 100.00% <100.00%> (ø) | |
| ...s/frontend/src/app/pages/external-models/const.tsx | 95.45% <100.00%> (+0.10%) | :arrow_up: |
| ...s/external-providers/ExternalProvidersTableRow.tsx | 100.00% <100.00%> (ø) | |
| ...ers/createProvider/CreateExternalProviderModal.tsx | 81.25% <100.00%> (+1.25%) | :arrow_up: |
| ...oviders/editProvider/EditExternalProviderModal.tsx | 81.25% <100.00%> (+1.25%) | :arrow_up: |
| ...-and-subs/mySubscriptions/SubscriptionsToolbar.tsx | 87.50% <100.00%> (+0.83%) | :arrow_up: |
| ... and 41 more | |
... and 23 files with indirect coverage changes
------
Continue to review full report in Codecov by Harness.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered by Codecov. Last update 5fd1428...be867a9. Read the comment docs.
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Looks great @caponetto! 🚀
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: <a href="https://github.com/opendatahub-io/odh-dashboard/pull/10787#pullrequestreview-6072211969" title="Approved">agagancarczyk</a>, <a href="https://github.com/opendatahub-io/odh-dashboard/pull/10787#pullrequestreview-5973844305" title="Approved">lucferbux</a>
The full list of commands accepted by this bot can be found here.
The pull request process is described 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
</details>
<!-- META={"approvers":[]} -->
/retest
/early-gate-build
Good call — errorCategory is just statusObject.code → k8s_XXX/unknown_error with no real tracking dep, so it could live in analytics or k8s-core. It was kept in frontend to avoid pulling k8s-core into analytics (now duck-typed) vs. adding tracking naming to k8s-core. Let's defer the move to the next time this area changes and pick the home then — no behavior change here.
lucferbux
caponetto
Fixes: RHAI-21483, RHAI-21484, RHAI-21485, RHAI-21486, RHAI-21487, RHAI-21488, RHAI-21489
Problem
MaaS custom events depend on dashboard-internal tracking helpers, preventing embedding hosts from controlling their delivery through the shared analytics context. Migrate API keys, subscriptions, model access, governance, external providers/models, and deployment publishing while preserving existing telemetry and privacy behavior.
Solution
useTrackEventin components and hooks, and inject callbacks into external-model column factories and publish sessions. Preserve event names, payloads, outcomes, timing, and multiplicity.Evidence
pnpm -C packages/maas/frontend run test:unit --runInBand: 425 tests pass across 51 suites on the final changes.pnpm -C packages/maas/frontend run test:type-check: passes.pnpm -C packages/maas/frontend run test:lint: ESLint passes; Prettier fails on existing formatting in the unchangedpackages/maas/README.md. Targeted ESLint also passes for the final regression-test changes.git diff --checkandgit diff --cached --check: pass.