Skip to content

Add GQL interface for project observability logs

Max Woolf requested to merge 2907-opstrace/log-graphql-changes into master

What does this MR do and why?

  • Adds a new observabilityLogsLinks GraphQL edge to ProjectType.
  • Adds required types and resolver to implement it.
  • Adds specs, including changes to other files as well as request specs for the new GraphQL interface.

Database queries

All records for a project

(These are from locally generated data since the table is brand new)

This query reads from an index condition as expected.

SELECT "observability_logs_issues_connections".* FROM "observability_logs_issues_connections" WHERE "observability_logs_issues_connections"."project_id" = 15;
                                                                       QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------
 Index Scan using index_observability_logs_issues_connections_on_project_id on observability_logs_issues_connections  (cost=0.15..7.43 rows=17 width=69)
   Index Cond: (project_id = 15)
(2 rows)

Selecting an individual record for a project

Query uses same index condition as above, and then filters on specific criteria. This will likely never return more than 1 or 2 records.

SELECT "observability_logs_issues_connections".* FROM "observability_logs_issues_connections" WHERE "observability_logs_issues_connections"."project_id" = 15 AND "observability_logs_issues_connections"."log_timestamp" = '2024-07-27 16:20:33.215711' AND "observability_logs_issues_connections"."service_name" = 'test' AND "observability_logs_issues_connections"."severity_number" = 4 AND "observability_logs_issues_connections"."trace_identifier" = 'aaaaa' AND "observability_logs_issues_connections"."log_fingerprint" = 'fsdfdsfs';
                                                                                                             QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Index Scan using index_observability_logs_issues_connections_on_project_id on observability_logs_issues_connections  (cost=0.15..7.64 rows=1 width=69)
   Index Cond: (project_id = 15)
   Filter: ((log_timestamp = '2024-07-27 16:20:33.215711+00'::timestamp with time zone) AND (service_name = 'test'::text) AND (severity_number = 4) AND (trace_identifier = 'aaaaa'::text) AND (log_fingerprint = 'fsdfdsfs'::text))
(3 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

  1. Ensure you're using an Ultimate namespace.

  2. Enable the :observability_features feature flag.

  3. Create a new project, within an Ultimate group.

  4. Create a new issue, and note its ID.

  5. On a rails console, create a linked log for that project.

    issue_id = {{ID}}
    a = a = Observability::LogsIssuesConnection.create(issue: Project.find(issue_id).issues.last, severity_number: 12, service_name: 'gitlab-rails', trace_identifier: '23489affd', log_fingerprint: 'aaaaaa', log_timestamp: 2.days.ago)
    a.save! # Raise an exception if something went wrong.
  6. For the created log, we can query a list of links - note the format of the timestamp should be iso8601.

    query {
      project(fullPath: "Flightjs/Flight") {
        id
        observabilityLogsLinks(timestamp: "2024-08-13T11:02:24.262999Z", severityNumber: 12, serviceName: "gitlab-rails", fingerprint: "abcdefghi", traceIdentifier: "23489affd") {
          nodes {
            timestamp
            severityNumber
            serviceName
            fingerprint
            traceIdentifier
            issue {
              title
              webUrl
            }
          }
        }
      }
    }
  7. If successful, it should return a list of observabiltyLogsLinks, each representing the link between an observabililtyLog and its issue (if queried, as above)

    {
      "data": {
        "project": {
          "id": "gid://gitlab/Project/7",
          "observabilityLogsLinks": {
            "nodes": [
              {
                "timestamp": "2024-08-13T11:02:24Z",
                "severityNumber": 12,
                "serviceName": "gitlab-rails",
                "fingerprint": "abcdefghi",
                "traceIdentifier": "23489affd",
                "issue": {
                  "title": "fdfsdfsdfsdfsdfs",
                  "webUrl": "http://127.0.0.1:3000/flightjs/Flight/-/issues/40"
                }
              }
            ]
          } 
        }
      }
    }

Related to gitlab-org/opstrace/opstrace#2907 (closed)

Edited by Max Woolf

Merge request reports

Loading