Skip to content

Add ability to activate/deactivate headers using the API

Overview

Now we have the custom headers GraphQL API, we want to allow the user to activate or deactivate headers using this GraphQL API.

This should be done for both group and instance level streaming

Proposal

  • Add the active property to the create and update mutations.
  • Add the active property to the API response.
  • Filter the headers used by the audit event stream based upon the active property at the point of streaming of an event.

# Add
mutation {
  auditEventsStreamingHeadersCreate(input: { destinationId: "gid://gitlab/AuditEvents::ExternalAuditEventDestination/24601", key: "foo", value: "bar", active: true }) {
    errors
  }
}

# Update
mutation {
  auditEventsStreamingHeadersUpdate(input: { headerId: "gid://gitlab/AuditEvents::Streaming::Header/24255", key: "new-foo", value: "new-bar", active: true }) {
    errors
  }
}

# List
query {
  group(fullPath: "your-group") {
    id
    externalAuditEventDestinations {
      nodes {
        destinationUrl
        id
        headers {
          nodes {
            key
            value
            id
            active
          }
        }
      }
    }
  }
}

Implementation plan:

  1. Create following migrations:
    1. Add a new non-null boolean column active to instance_audit_events_streaming_headers table, with default value as true. This will also backfill all the existing rows with value true.
    2. Add a new non-null boolean column active to audit_events_streaming_headers table, with default value as true. This will also backfill all the existing rows with value true. Please note that the no. of existing rows for both these tables are very small so this will not timeout.
  2. Add boolean validation for active in concern StreamableHeader .
  3. Add a method in https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/models/concerns/audit_events/custom_http_externally_destinationable.rb for returning active headers of destination and in header_hash use active headers instead of headers.
  4. Add support for active attribute in following places:
    1. https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/types/audit_events/streaming/base_header_interface.rb
    2. https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/streaming/headers/create.rb
    3. https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/streaming/headers/update.rb
    4. https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/streaming/instance_headers/create.rb
    5. https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/streaming/instance_headers/update.rb
Edited by Hitesh Raghuvanshi