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:
- Create following migrations:
- Add a new non-null boolean column
active
toinstance_audit_events_streaming_headers
table, with default value as true. This will also backfill all the existing rows with valuetrue
. - Add a new non-null boolean column
active
toaudit_events_streaming_headers
table, with default value as true. This will also backfill all the existing rows with valuetrue
. Please note that the no. of existing rows for both these tables are very small so this will not timeout.
- Add a new non-null boolean column
- Add boolean validation for
active
in concernStreamableHeader
. - 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. - Add support for
active
attribute in following places:- https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/types/audit_events/streaming/base_header_interface.rb
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/streaming/headers/create.rb
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/streaming/headers/update.rb
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/streaming/instance_headers/create.rb
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/graphql/mutations/audit_events/streaming/instance_headers/update.rb
Edited by Hitesh Raghuvanshi