Alerting: Update rule API to address folders by UID (#74600)
* Change ruler API to expect the folder UID as namespace * Update example requests * Fix tests * Update swagger * Modify FIle field in /api/prometheus/grafana/api/v1/rules * Fix ruler export * Modify folder in responses to be formatted as <parent UID>/<title> * Add alerting test with nested folders * Apply suggestion from code review * Alerting: use folder UID instead of title in rule API (#77166) Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com> * Drop a few more latent uses of namespace_id * move getNamespaceKey to models package * switch GetAlertRulesForScheduling to use folder table * update GetAlertRulesForScheduling to return folder titles in format `parent_uid/title`. * fi tests * add tests for GetAlertRulesForScheduling when parent uid * fix integration tests after merge * fix test after merge * change format of the namespace to JSON array this is needed for forward compatibility, when we migrate to full paths * update EF code to decode nested folder --------- Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com> Co-authored-by: Virginia Cepeda <virginia.cepeda@grafana.com> Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com> Co-authored-by: Alex Weaver <weaver.alex.d@gmail.com> Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
This commit is contained in:
co-authored by
Sonia Aguilar
Yuri Tseretyan
Virginia Cepeda
Alex Weaver
Gilles De Mey
parent
ec1d4274ed
commit
d1dab5828d
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api"
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/quota"
|
||||
@@ -260,9 +261,20 @@ func (a apiClient) ReloadCachedPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
// CreateFolder creates a folder for storing our alerts, and then refreshes the permission cache to make sure that following requests will be accepted
|
||||
func (a apiClient) CreateFolder(t *testing.T, uID string, title string) {
|
||||
func (a apiClient) CreateFolder(t *testing.T, uID string, title string, parentUID ...string) {
|
||||
t.Helper()
|
||||
payload := fmt.Sprintf(`{"uid": "%s","title": "%s"}`, uID, title)
|
||||
cmd := folder.CreateFolderCommand{
|
||||
UID: uID,
|
||||
Title: title,
|
||||
}
|
||||
if len(parentUID) > 0 {
|
||||
cmd.ParentUID = parentUID[0]
|
||||
}
|
||||
|
||||
blob, err := json.Marshal(cmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
payload := string(blob)
|
||||
u := fmt.Sprintf("%s/api/folders", a.url)
|
||||
r := strings.NewReader(payload)
|
||||
// nolint:gosec
|
||||
|
||||
Reference in New Issue
Block a user