grafana icon indicating copy to clipboard operation
grafana copied to clipboard

Alerting: Export to HCL should declare deterministic resource name

Open yuri-tceretian opened this issue 1 year ago • 3 comments

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:

  1. 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
  2. Hash of folder uid and group name. Not human readable
  3. Other option.

yuri-tceretian avatar Jun 04 '24 15:06 yuri-tceretian

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

stevesg avatar Jun 04 '24 18:06 stevesg

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.

yuri-tceretian avatar Jun 05 '24 19:06 yuri-tceretian

Hi, i would like to work on this, where should i take a look in the code ?

KyriosGN0 avatar Jun 29 '24 14:06 KyriosGN0

@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.

yuri-tceretian avatar Jul 02 '24 20:07 yuri-tceretian

Hi @yuri-tceretian, PR opened

KyriosGN0 avatar Jul 13 '24 22:07 KyriosGN0

It would be great to address thus for all resources

yuri-tceretian avatar Jul 19 '24 15:07 yuri-tceretian

@yuri-tceretian, what should be the elements to hash in Contact point and notif policy?

KyriosGN0 avatar Jul 19 '24 16:07 KyriosGN0

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 avatar Jul 23 '24 14:07 yuri-tceretian

@yuri-tceretian, opened PR

KyriosGN0 avatar Jul 24 '24 22:07 KyriosGN0