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 Contact Points: Refer by name #1247

Merged
merged 2 commits into from
Jan 4, 2024

Conversation

julienduchesne
Copy link
Member

Background:
Currently, the contact point's ID is a collection of notifier UIDs. However, in Grafana (and in the resource's import ref), it's referred to by name

This PR:
Change the Terraform ID from semi-colon separated UIDs to the contact point name. This will be easier to test, and this will allow simplifying the code in the next major version (removing the code fetching notifiers by UID) Since the UID reading logic is moved to the read function, it also allows importing contact points in Crossplane where the import function is not used

Copy link

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

Background:
Currently, the contact point's ID is a collection of notifier UIDs. However, in Grafana (and in the resource's import ref), it's referred to by name

This PR:
Change the Terraform ID from semi-colon separated UIDs to the contact point name. This will be easier to test, and this will allow simplifying the code in the next major version (removing the code fetching notifiers by UID)
Since the UID reading logic is moved to the read function, it also allows importing contact points in Crossplane where the import function is not used
@julienduchesne julienduchesne force-pushed the julienduchesne/contact-point-refer-by-name branch from 07a6c05 to 186930e Compare December 19, 2023 21:23
@julienduchesne julienduchesne marked this pull request as ready for review December 19, 2023 21:41
@julienduchesne julienduchesne requested a review from a team as a code owner December 19, 2023 21:41
julienduchesne added a commit that referenced this pull request Dec 20, 2023
Depends on #1247
When the ID is the contact point's name, it makes it easy to write the test helper
@julienduchesne julienduchesne merged commit 7f4cbed into master Jan 4, 2024
24 checks passed
@julienduchesne julienduchesne deleted the julienduchesne/contact-point-refer-by-name branch January 4, 2024 13:22
julienduchesne added a commit that referenced this pull request Jan 4, 2024
Depends on #1247
When the ID is the contact point's name, it makes it easy to write the test helper
julienduchesne added a commit that referenced this pull request Jan 11, 2024
* Alerting Contact Points: Use OpenAPI for tests
Depends on #1247
When the ID is the contact point's name, it makes it easy to write the test helper

* Rename badly named func
@duncan485
Copy link

Shouldn't this have been announced as a breaking change? As we created the resources with a version prior to this change, our TF state broke after upgrading the provider. As it tried to fetch the contact points based on the ID which was already in state, rather than the name.

@julienduchesne
Copy link
Member Author

Shouldn't this have been announced as a breaking change? As we created the resources with a version prior to this change, our TF state broke after upgrading the provider. As it tried to fetch the contact points based on the ID which was already in state, rather than the name.

This was tested with IDs in the state. The read by name or ID should still work in the latest version also. As tested here: https://github.com/grafana/terraform-provider-grafana/blob/main/internal/resources/grafana/resource_alerting_contact_point_test.go#L93-L108. (An import test will set only the ID and try to read the resource from that)

@duncan485
Copy link

duncan485 commented Feb 19, 2024

Not sure what happend then, because in our case (grafana cloud), we got a context deadline exceeded (HTTP 500) on

Get https://company.grafana.net/api/v1/provisioning/contact-points?name=00000000-00000-00000-0000-0000000

fyi, we go this on updating to grafana provider from 2.7.0 --> 2.10.0

@julienduchesne
Copy link
Member Author

Not sure what happend then, because in our case (grafana cloud), we got a context deadline exceeded (HTTP 500) on

Get https://company.grafana.net/api/v1/provisioning/contact-points?name=00000000-00000-00000-0000-0000000

fyi, we go this on updating to grafana provider from 2.7.0 --> 2.10.0

huh, interesting. 00000000-00000-00000-0000-0000000 is not a valid ID either. Not sure what's up with that error

@duncan485
Copy link

I redacted the actual uid before posting it here. just like company.grafana.net was not the actual endpoint.

@julienduchesne
Copy link
Member Author

Right 😄. The logic goes that if a contact point isn't found by name (404, or empty list), then it tries by ID. In your case, it's a 500, so that's going to crash the process right away. As if you had gotten a 500 while trying to fetch the contact points by ID.

Not sure if the 500 is linked to the API call in particular, the ?name= query is not a new thing, it's at least as old as the resource itself

@duncan485
Copy link

I just checked, if I query any name, other than an existing one, I get a 500 error instead of 404 or []. For example,
https://company.grafana.net/api/v1/provisioning/contact-points?name=doesnotexist returns 500.

Maybe it has to do with how it is implemented in grafana-cloud.

@julienduchesne
Copy link
Member Author

Interesting. I'll test it out and put out a fix

@julienduchesne
Copy link
Member Author

julienduchesne commented Feb 20, 2024

Hey, the 500 error should be fixed soon in Grafana Cloud. It was a Grafana bug, and the fix has been merged to the main branch

@duncan485
Copy link

@julienduchesne awesome, thanks !

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

Successfully merging this pull request may close these issues.

None yet

3 participants