Add GraphQL interface for linked metrics for issues
What does this MR do and why?
- Adds a new column
project_idtoobservability_metrics_issues_connectionsto more easily query a project's metrics and connected issues.- Adds matching foreign key, and indexes as required.
- Adds a GraphQL interface to query those connections.
- This requires new types, enums, resolvers and associations on the appropriate models.
- Adds tests for all new files and updated code.
Relates to gitlab-org/opstrace/opstrace#2903 (closed)
Query plans
All metrics for a project
SELECT "observability_metrics_issues_connections".*
FROM "observability_metrics_issues_connections"
WHERE "observability_metrics_issues_connections"."project_id" = 7
QUERY PLAN
-----------------------------------------------------------------------------------------
Seq Scan on observability_metrics_issues_connections (cost=0.00..1.09 rows=1 width=82)
Filter: (project_id = 7)
(2 rows)
Filtered metric for a project
SELECT "observability_metrics_issues_connections".*
FROM "observability_metrics_issues_connections"
WHERE "observability_metrics_issues_connections"."project_id" = 7
AND "observability_metrics_issues_connections"."metric_name" = 'te343st2345'
AND "observability_metrics_issues_connections"."metric_type" = 1
QUERY PLAN
--------------------------------------------------------------------------------------------
Seq Scan on observability_metrics_issues_connections (cost=0.00..1.12 rows=1 width=82)
Filter: ((project_id = 7) AND (metric_name = 'te343st2345'::text) AND (metric_type = 1))
(2 rows)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
| Before | After |
|---|---|
How to set up and validate locally
-
Ensure you're using an Ultimate namespace.
-
Enable the
:observability_featuresfeature flag. -
Create a new project, within an Ultimate group.
-
Create two new issues, and note their ID.
-
On a
rails console, create a few linked metrics for that project. Repeat this for each issue.issue_id = {{ID}} a = Observability::MetricsIssuesConnection.new(metric_type: :sum_type, metric_name: "test2345", issue: Issue.find(issue_id)) a.save! # Raise an exception if something went wrong. -
This will create two metric links for the same metric (denoted by
metric_type, andmetric_name) in the same project, across two different issues. -
For the created metric, we can query a list of links: (
typeis a newly defined GQL enum of OpenTelemetry metric types)query { project(fullPath: "Flightjs/Flight") { id observabilityMetricsLinks(name: "test2345", type: SUM_TYPE) { nodes { name type issue { title webUrl } } } } } -
If successful, it should return a list of
observabiltyMetrics, each representing the link between an observabililtyMetric and its issue (if queried, as above){ "data": { "project": { "id": "gid://gitlab/Project/7", "observabilityMetricsLinks": { "nodes": [ { "name": "test2345", "type": "sum_type", "issue": { "title": "fdfsdfsdfsdfsdfs", "webUrl": "http://127.0.0.1:3000/flightjs/Flight/-/issues/40" } }, { "name": "test2345", "type": "sum_type", "issue": { "title": "gdfgdfgdfgdf", "webUrl": "http://127.0.0.1:3000/flightjs/Flight/-/issues/39" } }, { "name": "test2345", "type": "sum_type", "issue": { "title": "Alias quia iure quibusdam vero nam dicta.", "webUrl": "http://127.0.0.1:3000/flightjs/Flight/-/issues/18" } } ] } } } }