Skip to content

Adding list instance headers API

Hitesh Raghuvanshi requested to merge 404560-list-streaming-headers into master

What does this MR do and why?

  1. Added support for listing streaming headers associated with instance level external audit event destinations.

GraphQL API


query {
  instanceExternalAuditEventDestinations {
    nodes {
      id
      destinationUrl
      verificationToken      
      headers {
        nodes {
          id
          key
          value
        }
      }
    }
  }
}
Sample Response - Click to expand
{
  "data": {
    "instanceExternalAuditEventDestinations": {
      "nodes": [
        {
          "id": "gid://gitlab/AuditEvents::InstanceExternalAuditEventDestination/21",
          "destinationUrl": "https://example1.com",
          "verificationToken": "QCWGDjeeS8jhmanpqTTPU6E8",
          "headers": {
            "nodes": [
              {
                "id": "gid://gitlab/AuditEvents::Streaming::InstanceHeader/5",
                "key": "header10",
                "value": "header10value"
              },
              {
                "id": "gid://gitlab/AuditEvents::Streaming::InstanceHeader/4",
                "key": "header4",
                "value": "header4value"
              },
              {
                "id": "gid://gitlab/AuditEvents::Streaming::InstanceHeader/3",
                "key": "header3",
                "value": "header3value"
              },
              {
                "id": "gid://gitlab/AuditEvents::Streaming::InstanceHeader/2",
                "key": "header5",
                "value": "header5value"
              },
              {
                "id": "gid://gitlab/AuditEvents::Streaming::InstanceHeader/1",
                "key": "header6",
                "value": "header6value"
              }
            ]
          }
        },
        {
          "id": "gid://gitlab/AuditEvents::InstanceExternalAuditEventDestination/20",
          "destinationUrl": "https://www.example4.com",
          "verificationToken": "KGdm2CctmfZGK7VDsThYFLi7",
          "headers": {
            "nodes": []
          }
        }
      ]
    }
  }
}

Query plan

Query - Click to expand
SELECT 
  "instance_audit_events_streaming_headers".* 
FROM 
  "instance_audit_events_streaming_headers" 
WHERE 
  "instance_audit_events_streaming_headers"."instance_external_audit_event_destination_id" IN (26, 25)

https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/19381/commands/63998

Note: Since this is an instance level API, there are no records on production, hence it will be returning 0 rows.

How to set up and validate locally

  1. Enable the feature flag from rails console by running Feature.enable(:ff_external_audit_events).
  2. Open graphql-explorer console in browser by opening url http://127.0.0.1:3000/-/graphql-explorer.
  3. Run following mutation in the graphql explorer and note down the id, which would be something like gid://gitlab/AuditEvents::InstanceExternalAuditEventDestination/<id> from output.
mutation {
  instanceExternalAuditEventDestinationCreate(input: { destinationUrl: "https://www.example.com"}) {
    errors
    instanceExternalAuditEventDestination {
      destinationUrl
      id
    }
  }
}
  1. Run the following graphql command in explorer for creating a header created for destination created in step 3:
mutation {
  auditEventsStreamingInstanceHeadersCreate(input: 
    { 
      key: "header1",
      value: "header1value",
      destinationId: "gid://gitlab/AuditEvents::InstanceExternalAuditEventDestination/<id>"
    }) {
    errors
    header {
      id
      key
      value
    }
  }
}
  1. Run following query command to list down streaming headers for the destinations, there will be header nodes present in the output for the above destination.
query {
  instanceExternalAuditEventDestinations {
    nodes {
      id
      destinationUrl
      verificationToken      
      headers {
        nodes {
          id
          key
          value
        }
      }
    }
  }
}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #404560 (closed)

Edited by Hitesh Raghuvanshi

Merge request reports