Skip to content

disable deleting metrics that are in use - #3298

Open
bcb37 wants to merge 3 commits into
devfrom
feature/2922-prevent-metric-delete
Open

disable deleting metrics that are in use#3298
bcb37 wants to merge 3 commits into
devfrom
feature/2922-prevent-metric-delete

Conversation

@bcb37

@bcb37 bcb37 commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@bcb37
bcb37 requested review from danoswaltCL and zackcl and a lite review from Copilot August 26, 2026 21:15
@bcb37 bcb37 linked an issue Aug 26, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request aims to prevent deletion of metrics that are referenced by experiment queries by surfacing “in-use” metadata from the backend and disabling the delete action in the metrics UI, while also avoiding unintended HTTP cancellations during navigation-triggered refreshes.

Changes:

  • Add hasQuery metadata to the metrics catalog payload and use it in the UI to disable metric deletion with an explanatory tooltip.
  • Refresh the metrics catalog after experiment metric updates and experiment deletion.
  • Add an opt-out mechanism for navigation-based HTTP cancellation for app-wide metrics catalog fetches.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/types/src/Experiment/interfaces.ts Adds optional hasQuery flag to IMetricUnit for in-use signaling.
packages/frontend/projects/upgrade/src/assets/i18n/en.json Adds tooltip copy for disabled metric deletion.
packages/frontend/projects/upgrade/src/app/features/dashboard/profile/components/metrics/metrics.model.ts Adds isTopLevel marker used to constrain delete affordance to row roots.
packages/frontend/projects/upgrade/src/app/features/dashboard/profile/components/metrics/metrics.component.ts Propagates isTopLevel and hard-blocks deletion when hasQuery is true.
packages/frontend/projects/upgrade/src/app/features/dashboard/profile/components/metrics/metrics.component.scss Styles disabled delete icon state.
packages/frontend/projects/upgrade/src/app/features/dashboard/profile/components/metrics/metrics.component.html Disables delete icon + tooltip when hasQuery, and limits delete to top-level nodes.
packages/frontend/projects/upgrade/src/app/core/http-interceptors/http-cancel.interceptor.ts Introduces SKIP_NAVIGATION_CANCEL context token to bypass navigation cancellation.
packages/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.ts Dispatches actionFetchMetrics() after experiment metrics update and experiment deletion.
packages/frontend/projects/upgrade/src/app/core/experiments/store/experiments.effects.spec.ts Adds unit coverage for updateExperimentMetrics$ emitting two actions.
packages/frontend/projects/upgrade/src/app/core/analysis/store/analysis.effects.ts Adds defaultIfEmpty guards so canceled requests emit a failure action.
packages/frontend/projects/upgrade/src/app/core/analysis/analysis.data.service.ts Sets SKIP_NAVIGATION_CANCEL on metrics catalog fetch requests.
packages/frontend/projects/upgrade/src/app/core/analysis/analysis.data.service.spec.ts Updates fetchMetrics expectation (but needs stronger assertion of token behavior).
packages/backend/src/api/services/MetricService.ts Fetches query-used metric keys and annotates top-level metrics with hasQuery.
packages/backend/src/api/repositories/QueryRepository.ts Adds query to return distinct metric keys referenced by queries.
packages/backend/test/unit/services/MetricService.test.ts Updates unit tests to validate hasQuery behavior on metric trees.
packages/backend/test/unit/repositories/QueryRepository.test.ts Adds unit tests for getMetricKeysWithQueries().

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +70 to +81
public async getMetricKeysWithQueries(): Promise<string[]> {
const queryResult = await this.createQueryBuilder('query')
.innerJoin('query.metric', 'metric')
.select('DISTINCT metric.key', 'metricKey')
.getRawMany()
.catch((errorMsg: any) => {
const errorMsgString = repositoryError('QueryRepository', 'getMetricKeysWithQueries', {}, errorMsg);
throw errorMsgString;
});

return queryResult.map((row: { metricKey: string }) => row.metricKey);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've confirmed that this would result in the metrics data disappearing from the data tab and from exports, which we probably don't want.

Comment thread packages/backend/src/api/services/MetricService.ts
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.

Prevent deletion of metrics that are in use by experiments

2 participants