grafana
grafana copied to clipboard
Alerting: Export to HCL should declare deterministic resource name
Currently, export to HCL creates resource names by just adding an index to the name. However, this is not very helpful in workflows because the resource name can change depending on various factors, and therefore, it can cause unpredictable changes if exported data is pasted as is.
The proposal is to use folder UID and group name for resource name. Options:
- Simple concatenation of folder uid and group name. It can be a folder title. The problem is the length of the name. Will require some sanitizing, which can complicate ensuring the uniqueness
- Hash of folder uid and group name. Not human readable
- Other option.
Why not degrade gracefully starting from user readable:
- Folder full path + Group Name (if fits)
- Folder UID + Group Name (if fits)
- Folder UID + Hashed Group Name
folder's full path is prone to changes but in Terraform we refer to a folder by UID. It's still non-deterministic. I think UID + group name is more stable.
Hi, i would like to work on this, where should i take a look in the code ?
@KyriosGN0, great! I appreciate it! You can change it here https://github.com/grafana/grafana/blob/99d8025829e896b68f6cd5eb11d4ff448d6c3b30/pkg/services/ngalert/api/api_provisioning.go#L592-L596
We've discussed that during a team meeting, and if I recall correctly, the decision was to just go with FNV-1 hash of folder UID and group name. This is a stable enough identifier.
Hi @yuri-tceretian, PR opened
It would be great to address thus for all resources
@yuri-tceretian, what should be the elements to hash in Contact point and notif policy?
Notification policy is a singleton - i.e. it a single object for the entire organization. The model AlertingFileExport is a little bit incorrect here as it advertise it as slice. We can change that. So, I would just keep it without any suffix.
For contact points, templates and mute-timings we can choose the same approach - hash the name
@yuri-tceretian, opened PR