Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alert metadata #3764

Merged
merged 49 commits into from
Apr 2, 2024
Merged

Add alert metadata #3764

merged 49 commits into from
Apr 2, 2024

Conversation

shivanishendge
Copy link
Collaborator

  • Identified the issue which this PR solves.
  • Read the CONTRIBUTING document.
  • Code builds clean without any errors or warnings.
  • [] Added appropriate tests for any new functionality.
  • [] All new and existing tests passed.
  • Added comments in the code, where necessary.
  • Ran make check to catch common errors. Fixed any that came up.

Description:

  • Implement a new meta in alert creation endpoints to accommodate a set of key=value pairs.
  • Create a new alert_data table for storing the new data, with an alert_id column and a data column (jsonb).
  • Extend Webhook notifications to include the new meta values.

Which issue(s) this PR fixes:
Add Metadata to Alerts for Traceability and Integration

Out of Scope:
Display of metadata in goAlert UI

Screenshots:
n/a

Describe any introduced user-facing changes:
None

Describe any introduced API changes:
Users can add 'meta' field in the create alert requests to track additional metadata(kv pairs)

@shivanishendge shivanishendge marked this pull request as draft March 21, 2024 16:18
alert/alert.go Outdated Show resolved Hide resolved
alert/alert.go Outdated Show resolved Hide resolved
alert/meta.go Outdated Show resolved Hide resolved
alert/store.go Outdated Show resolved Hide resolved
alert/meta.go Outdated Show resolved Hide resolved
graphql2/graphqlapp/alert.go Outdated Show resolved Hide resolved
graphql2/graphqlapp/dataloaders.go Outdated Show resolved Hide resolved
graphql2/schema.graphql Outdated Show resolved Hide resolved
migrate/migrations/20240212125328-alert-metadata.sql Outdated Show resolved Hide resolved
notification/alert.go Outdated Show resolved Hide resolved
@shivanishendge shivanishendge marked this pull request as ready for review March 26, 2024 20:52
Since we're handling this separatly with a specific store method, we
don't want to add a second place to set metadata here.

If/when we update things using CreateOrUpdate, we'll make a Tx method
for it. This way we don't need to update call sites across the app for
the new signature.
So this query is a bit more complicated, but we want to make sure no
future bug allows a service/integration key to update the metadata of an
alert that doesn't belong to it.

Integration keys in GoAlert are tied to a single service, and all DB
calls regarding alerts should be guarded such that only alerts belonging
to that specific service may be modified, including the newly introduced
metadata.

The approach I took here allows us to pass a service ID, optionally
(i.e., ONLY when a request comes from an integration), where the query
will fail to insert/update any data if it's mismatched. If the service
ID is null, it will skip this check (i.e., a user action).
This is just updating the type from int to bigint (64 bit) and using
@alert_ids instead of $1 so that sqlc generates a better name for the
argument.
For organization sake, moving the store methods to a separate file (we
have a bad habbit of having the store.go files growing forever).

I also implemented things using the `gadb` and taking a `DBTX` rather
than a sql.Tx. This is the most recent pattern, although most DB code
has not been refactored for this.

I'm using the `map[string]string` Go type directly to get rid of any
indirection on the metadata format external to this package. Internally,
I added a `metadataDBFormat` that hopefully by name makes it clearer
it's only intended to be used at rest.

Compared to what was there before, I also:
- Added assertions on the type string
- Added a MetadataAlertID type that includes an alert ID for the
  dataloader
- Added an Access Denied error if SetMetadataTx fails because of an
  invalid alert or service ID mismatch
weefatboi
weefatboi previously approved these changes Apr 1, 2024
- removed debug print
- removed redundant nil check on Metadata() result
- updated Metadata comment regarding return values
mastercactapus
mastercactapus previously approved these changes Apr 1, 2024
mastercactapus
mastercactapus previously approved these changes Apr 1, 2024
mastercactapus
mastercactapus previously approved these changes Apr 1, 2024
@weefatboi weefatboi self-requested a review April 2, 2024 16:19
@mastercactapus mastercactapus removed the request for review from Forfold April 2, 2024 18:06
@mastercactapus mastercactapus merged commit cbe89ca into master Apr 2, 2024
7 checks passed
@mastercactapus mastercactapus deleted the add-alertMetadata branch April 2, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants