Skip to content

Adding API for listing event filters for instance level

Hitesh Raghuvanshi requested to merge 415769-list-event-type-filters into master

What does this MR do and why?

This MR adds ability to list down event filters associated with an instance level external audit event destination. Event filters are used for filtering of audit events while streaming to external audit event destinations. API for creating audit event filters was added in !124605 (merged).

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. You need to have Ultimate license for your instance.
  2. Enable feature flag by running ::Feature.enable(:ff_external_audit_events) in rails console.
  3. Login with instance administrator account at http://gitlab.localdev:3000/(or whatever your local gitlab setup url is).
  4. Then visit http://gitlab.localdev:3000/-/graphql-explorer for running graphql queries and mutations.
  5. Run following mutation for creating a new instance level external audit event destination
mutation {
  instanceExternalAuditEventDestinationCreate(input: { destinationUrl: "https://www.example.com"}) {
    errors
    instanceExternalAuditEventDestination {
      destinationUrl
      id
    }
  }
}
  1. Note the destination id in response and create an event type filter for this destination by running following mutation, you should not receive any errors and this will return all the event filters for the destination.
mutation {
   auditEventsStreamingDestinationInstanceEventsAdd(
    input: {
      destinationId:  "gid://gitlab/AuditEvents::InstanceExternalAuditEventDestination/<id>",
      eventTypeFilters:["filter1", "filter2"] 
    }
  ){
    errors
    eventTypeFilters
  }
}
  1. List down the destinations with their respective event filters by running following query:
query {
  instanceExternalAuditEventDestinations {
    nodes {
      id
      destinationUrl
      verificationToken
      eventTypeFilters
    }
  }
}
  1. Output of query in step 7 should be something like:
{
  "data": {
    "instanceExternalAuditEventDestinations": {
      "nodes": [
        {
          "id": "gid://gitlab/AuditEvents::InstanceExternalAuditEventDestination/39",
          "destinationUrl": "https://www.example.com",
          "verificationToken": "XSY4FpJCZfW5PnkKpJxiHJAy",
          "eventTypeFilters": [
            "filter5",
            "filter7"
          ]
        }
      ]
    }
  }
}

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 #415769 (closed)

Edited by Hitesh Raghuvanshi

Merge request reports