Skip to content

RI-8196 Enrich BE analytics events with isProduction#5930

Draft
KrumTy wants to merge 1 commit into
mainfrom
be/feature/RI-8196/enrich-analytics-with-is-production
Draft

RI-8196 Enrich BE analytics events with isProduction#5930
KrumTy wants to merge 1 commit into
mainfrom
be/feature/RI-8196/enrich-analytics-with-is-production

Conversation

@KrumTy
Copy link
Copy Markdown
Contributor

@KrumTy KrumTy commented May 15, 2026

What

Enriches existing backend analytics events with the connection's production status so we can answer the PRD's analytics questions ("did users run dangerous commands on prod?", "did Profiler start on prod?", "did bulk-delete confirm on prod?") without adding parallel FE PROD_CONFIRMATION_SHOWN events. Part of epic RI-6594 — Prod vs non-prod modes. Ticket: RI-8196.

Builds on RI-8177 (the isProduction field, 'true' | 'false' string convention from database.analytics.ts) and RI-8179 (DangerousCommandsProvider, an ACL-CAT-backed dangerous-command cache).

Events enriched

Module Events New fields
CLI CLI_COMMAND_EXECUTED, CLI_COMMAND_ERROR_RECEIVED, CLI_CLUSTER_NODE_COMMAND_EXECUTED isProduction, dangerous
Workbench WORKBENCH_COMMAND_EXECUTED, WORKBENCH_COMMAND_ERROR_RECEIVED, SEARCH_* variants, WORKBENCH_INDEX_INFO_SUBMITTED isProduction, dangerous (index info: isProduction only)
Bulk actions BULK_ACTIONS_STARTED, BULK_ACTIONS_STOPPED, BULK_ACTIONS_SUCCEED, BULK_ACTIONS_FAILED isProduction, dangerous (true for Delete/Unlink), confirmedThrough
Profiler PROFILER_LOG_DOWNLOADED, PROFILER_LOG_DELETED, new PROFILER_STARTED isProduction

Implementation notes

  • Each analytics service injects DatabaseRepository and uses a private resolveIsProduction(...) helper, wrapped in try/catch (defaults to 'false' on lookup failure so analytics never blocks the request path).
  • dangerous is computed in the caller (CLI/Workbench command executors) using DangerousCommandsProvider.getDangerousCommands(client) — the cache is per-database, so the cost is one ACL CAT round-trip per connection. Caller passes the boolean via additionalData; the analytics service stringifies it.
  • For Bulk actions, dangerous is derived from BulkActionType (Delete/Unlink → 'true', Upload → 'false') since there's no command-level granularity.
  • New optional confirmedThrough: 'standard' | 'type-to-confirm' field on CreateBulkActionDto, threaded through BulkActionIBulkActionOverview → analytics. Defaults to null (for paths that don't go through a confirmation dialog, including all imports).
  • DangerousCommandsProvider is now exported from DatabaseModule.
  • New PROFILER_STARTED event fires from ProfilerService.addListenerForInstance after the listener attaches.

Out of scope (deferred)

Browser write events (key rename / delete / TTL change / value mutations, hash/list/set/zset/stream writes). The ticket's #5 scope item assumes existing BE analytics to enrich, but the codebase has none for those services — they're FE-tracked today. Adding them is a net-new module-wide telemetry effort and exceeds the "enrich existing emits" framing. RI-8184 will need to keep its FE confirmation event or get a follow-up BE ticket.

Testing

  • Unit tests: 238 affected tests pass (cli-analytics, cli-business, workbench.analytics, workbench-commands.executor, bulk-actions.analytics, bulk-import.service, bulk-action, new profiler-analytics.service.spec.ts). Full API suite (3444 tests) green. New assertions cover:
    • isProduction='true' when the database is production-flagged
    • dangerous passthrough for command events and Delete vs Upload for bulk
    • confirmedThrough round-trips through the bulk-action DTO
    • isProduction='false' fallback when the repository lookup throws
  • Lint: clean on all touched files.
  • Type check: no new src/ errors (pre-existing test/ failures unchanged).
  • Manual smoke (still to do before un-drafting): with a prod-flagged and a non-prod database connected, run GET foo and FLUSHDB from CLI/Workbench and confirm Segment payloads carry the correct isProduction and dangerous; trigger a bulk-delete with the FE confirmation dialog and confirm confirmedThrough='type-to-confirm'; open Profiler and confirm PROFILER_STARTED fires once.

🤖 Generated with Claude Code

Enrich CLI, Workbench, Bulk-actions, and Profiler analytics with
`isProduction` (resolved from `DatabaseRepository`), plus `dangerous`
(derived from `DangerousCommandsProvider` cache, or action type for
bulk) for command-style events and `confirmedThrough` for bulk actions.
Adds a new `PROFILER_STARTED` event.

Lets analytics answer "did users run dangerous commands on prod?"
without parallel FE PROD_CONFIRMATION_SHOWN events. Browser write
events are deferred to a follow-up — they have no existing BE analytics
to enrich.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented May 15, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@github-actions
Copy link
Copy Markdown
Contributor

Code Coverage - Backend unit tests

St.
Category Percentage Covered / Total
🟢 Statements 92.71% 15683/16916
🟡 Branches 74.77% 4953/6624
🟢 Functions 86.96% 2448/2815
🟢 Lines 92.55% 14992/16199

Test suite run success

3444 tests passing in 308 suites.

Report generated by 🧪jest coverage report action from a1c4135

@github-actions
Copy link
Copy Markdown
Contributor

Code Coverage - Integration Tests

Status Category Percentage Covered / Total
🟡 Statements 79.53% 17590/22117
🟡 Branches 62.08% 8102/13049
🟡 Functions 68.12% 2441/3583
🟡 Lines 79.1% 16545/20916

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.

1 participant