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

Alerting: Allow none provenance alert rule creation from provisioning API #58410

Merged

Conversation

alexmobo
Copy link
Contributor

@alexmobo alexmobo commented Nov 8, 2022

What is this feature?

There has been some pain around being able to modify alerts created via API lately. Since our Alerting API is not stable just yet we are enabling a workaround within the Provisioning API to do it by adding the x-disable-provenance header to the following requests:

  • POST /api/v1/provisioning/alert-rules
  • PUT /api/v1/provisioning/alert-rules/{UID}

This will create alert rules as if they were created via UI and make the editable.

Why do we need this feature?

Many clients are asking to be able to create editable alert rules from the API.

Who is this feature for?

Users that want to edit API-created alert rules using the UI.

Which issue(s) does this PR fix?:

Fixes #57911

@grafanabot
Copy link
Contributor

Copy link
Member

@JohnnyQQQQ JohnnyQQQQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw that you edited a generated file (pkg/services/ngalert/api/generated_base_api_provisioning.go). This should not be done. You will need to look at another way to do this.

You could i.e. extend the generation template to consider headers when generating handlers. The codegen code can be found in grafana/pkg/services/ngalert/api/tooling

@alexmobo
Copy link
Contributor Author

I just saw that you edited a generated file (pkg/services/ngalert/api/generated_base_api_provisioning.go). This should not be done. You will need to look at another way to do this.

You could i.e. extend the generation template to consider headers when generating handlers. The codegen code can be found in grafana/pkg/services/ngalert/api/tooling

I didn't notice it was generated even though it says in the name of the file. Thanks.

@grafanabot
Copy link
Contributor

@alexmobo alexmobo force-pushed the allow-none-provenance-alert-rules-from-provisioning-api branch from b212ef6 to ce0eea6 Compare November 10, 2022 12:25
@grafanabot
Copy link
Contributor

@grafanabot
Copy link
Contributor

@grafanabot
Copy link
Contributor

@grafanabot
Copy link
Contributor

@grafanabot
Copy link
Contributor

@grobinson-grafana
Copy link
Contributor

The changes look good to me!

@grafanabot
Copy link
Contributor

@alexmobo alexmobo force-pushed the allow-none-provenance-alert-rules-from-provisioning-api branch from 1e16b61 to 13873f2 Compare November 11, 2022 14:56
@grafanabot
Copy link
Contributor

Copy link
Member

@JohnnyQQQQ JohnnyQQQQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@greatvovan
Copy link
Contributor

Please explain, how it will help with Terraformed alerts?

@alexmobo
Copy link
Contributor Author

alexmobo commented Jan 3, 2023

There is no workaround to do it directly from terraform. This is API only.

@alexweav
Copy link
Contributor

@greatvovan @alexmobo Actually, this is possible. The grafana terraform provider allows you to provide any set of custom headers via the http_headers provider config option. So you can add the header there, and all the requests will carry the header, so they will all be UI-editable.

See the option docs here:
https://registry.terraform.io/providers/grafana/grafana/latest/docs#optional

@phyzical
Copy link

hey @alexweav any chance you could confirm this is how it should be set?

http_headers = {
    "X-Disable-Provenance" = "disabled"
  }

running 9.3.0 i tried remove some alerts and recreating but sadly still complained it was provisioned still

@nitesh8860
Copy link

i just tried it with grafana v9.4.3 and terraform provider v1.35.0, both are latest, and it doesn't work

provider "grafana" {
  url          = var.grafana_url
  auth         = var.auth
  http_headers = var.http_headers
}
variable "http_headers" {
  type = map(string)
  default = {
    "X-Disable-Provenance" = "disabled"
  }
}

image

while working with api directly works /api/v1/provisioning/alert-rules/ and providing http_header

image

Please review and let me know if there is some other way of doing this.

Thanks
Nitesh

@phyzical
Copy link

phyzical commented Mar 7, 2023

@nitesh8860 thanks for trying also, i think this might actually be an issue to be raised for the terraform provider instead

@joegoggins
Copy link

joegoggins commented Sep 28, 2023

I'm using GET /api/v1/provisioning/alert-rules/export to extract alert rules from an existing instance with working rules, then adding them to provisioning/alerting/alert-rules.yaml. I'm wondering if there is a way to use this X-Disable-Provenance header in this context? (see docs)

For dashboards, I use allowUiUpdates: true in the provisioning/dashboards/default.yaml to allow tinkering/refinements . I was hoping there was a similar flag I could enable in the alert-rules.yaml to make alert tinkering possible post provisioning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Alerting provisioning: allow edits of provisioned alerts
10 participants