Alerting: Drop NamespaceID from responses on unstable ngalert API endpoints in favor of NamespaceUID (#79359)

* Drop from API response

* Drop from swagger docs

* Drop from integration tests

* regenerate public swagger docs

* Drop from frontend

* Drop asserts for namespaceID field
This commit is contained in:
Alexander Weaver
2023-12-15 11:06:53 -06:00
committed by GitHub
parent f8a1e7d500
commit cf8e8852c3
19 changed files with 10 additions and 61 deletions
+6 -7
View File
@@ -163,7 +163,7 @@ func (srv RulerSrv) RouteGetNamespaceRulesConfig(c *contextmodel.ReqContext, nam
for groupKey, rules := range ruleGroups { for groupKey, rules := range ruleGroups {
// nolint:staticcheck // nolint:staticcheck
result[namespaceTitle] = append(result[namespaceTitle], toGettableRuleGroupConfig(groupKey.RuleGroup, rules, namespace.ID, provenanceRecords)) result[namespaceTitle] = append(result[namespaceTitle], toGettableRuleGroupConfig(groupKey.RuleGroup, rules, provenanceRecords))
} }
return response.JSON(http.StatusAccepted, result) return response.JSON(http.StatusAccepted, result)
@@ -193,7 +193,7 @@ func (srv RulerSrv) RouteGetRulesGroupConfig(c *contextmodel.ReqContext, namespa
result := apimodels.RuleGroupConfigResponse{ result := apimodels.RuleGroupConfigResponse{
// nolint:staticcheck // nolint:staticcheck
GettableRuleGroupConfig: toGettableRuleGroupConfig(ruleGroup, rules, namespace.ID, provenanceRecords), GettableRuleGroupConfig: toGettableRuleGroupConfig(ruleGroup, rules, provenanceRecords),
} }
return response.JSON(http.StatusAccepted, result) return response.JSON(http.StatusAccepted, result)
} }
@@ -243,7 +243,7 @@ func (srv RulerSrv) RouteGetRulesConfig(c *contextmodel.ReqContext) response.Res
} }
namespace := folder.Title namespace := folder.Title
// nolint:staticcheck // nolint:staticcheck
result[namespace] = append(result[namespace], toGettableRuleGroupConfig(groupKey.RuleGroup, rules, folder.ID, provenanceRecords)) result[namespace] = append(result[namespace], toGettableRuleGroupConfig(groupKey.RuleGroup, rules, provenanceRecords))
} }
return response.JSON(http.StatusOK, result) return response.JSON(http.StatusOK, result)
} }
@@ -405,7 +405,7 @@ func changesToResponse(finalChanges *store.GroupDelta) response.Response {
return response.JSON(http.StatusAccepted, body) return response.JSON(http.StatusAccepted, body)
} }
func toGettableRuleGroupConfig(groupName string, rules ngmodels.RulesGroup, namespaceID int64, provenanceRecords map[string]ngmodels.Provenance) apimodels.GettableRuleGroupConfig { func toGettableRuleGroupConfig(groupName string, rules ngmodels.RulesGroup, provenanceRecords map[string]ngmodels.Provenance) apimodels.GettableRuleGroupConfig {
rules.SortByGroupIndex() rules.SortByGroupIndex()
ruleNodes := make([]apimodels.GettableExtendedRuleNode, 0, len(rules)) ruleNodes := make([]apimodels.GettableExtendedRuleNode, 0, len(rules))
var interval time.Duration var interval time.Duration
@@ -413,7 +413,7 @@ func toGettableRuleGroupConfig(groupName string, rules ngmodels.RulesGroup, name
interval = time.Duration(rules[0].IntervalSeconds) * time.Second interval = time.Duration(rules[0].IntervalSeconds) * time.Second
} }
for _, r := range rules { for _, r := range rules {
ruleNodes = append(ruleNodes, toGettableExtendedRuleNode(*r, namespaceID, provenanceRecords)) ruleNodes = append(ruleNodes, toGettableExtendedRuleNode(*r, provenanceRecords))
} }
return apimodels.GettableRuleGroupConfig{ return apimodels.GettableRuleGroupConfig{
Name: groupName, Name: groupName,
@@ -422,7 +422,7 @@ func toGettableRuleGroupConfig(groupName string, rules ngmodels.RulesGroup, name
} }
} }
func toGettableExtendedRuleNode(r ngmodels.AlertRule, namespaceID int64, provenanceRecords map[string]ngmodels.Provenance) apimodels.GettableExtendedRuleNode { func toGettableExtendedRuleNode(r ngmodels.AlertRule, provenanceRecords map[string]ngmodels.Provenance) apimodels.GettableExtendedRuleNode {
provenance := ngmodels.ProvenanceNone provenance := ngmodels.ProvenanceNone
if prov, exists := provenanceRecords[r.ResourceID()]; exists { if prov, exists := provenanceRecords[r.ResourceID()]; exists {
provenance = prov provenance = prov
@@ -439,7 +439,6 @@ func toGettableExtendedRuleNode(r ngmodels.AlertRule, namespaceID int64, provena
Version: r.Version, Version: r.Version,
UID: r.UID, UID: r.UID,
NamespaceUID: r.NamespaceUID, NamespaceUID: r.NamespaceUID,
NamespaceID: namespaceID,
RuleGroup: r.RuleGroup, RuleGroup: r.RuleGroup,
NoDataState: apimodels.NoDataState(r.NoDataState), NoDataState: apimodels.NoDataState(r.NoDataState),
ExecErrState: apimodels.ExecutionErrorState(r.ExecErrState), ExecErrState: apimodels.ExecutionErrorState(r.ExecErrState),
@@ -1431,10 +1431,6 @@
"is_paused": { "is_paused": {
"type": "boolean" "type": "boolean"
}, },
"namespace_id": {
"format": "int64",
"type": "integer"
},
"namespace_uid": { "namespace_uid": {
"type": "string" "type": "string"
}, },
@@ -4472,7 +4468,6 @@
"type": "array" "type": "array"
}, },
"integration": { "integration": {
"description": "Integration integration",
"properties": { "properties": {
"lastNotifyAttempt": { "lastNotifyAttempt": {
"description": "A timestamp indicating the last attempt to deliver a notification regardless of the outcome.\nFormat: date-time", "description": "A timestamp indicating the last attempt to deliver a notification regardless of the outcome.\nFormat: date-time",
@@ -426,7 +426,6 @@ type GettableGrafanaRule struct {
Version int64 `json:"version" yaml:"version"` Version int64 `json:"version" yaml:"version"`
UID string `json:"uid" yaml:"uid"` UID string `json:"uid" yaml:"uid"`
NamespaceUID string `json:"namespace_uid" yaml:"namespace_uid"` NamespaceUID string `json:"namespace_uid" yaml:"namespace_uid"`
NamespaceID int64 `json:"namespace_id" yaml:"namespace_id"`
RuleGroup string `json:"rule_group" yaml:"rule_group"` RuleGroup string `json:"rule_group" yaml:"rule_group"`
NoDataState NoDataState `json:"no_data_state" yaml:"no_data_state"` NoDataState NoDataState `json:"no_data_state" yaml:"no_data_state"`
ExecErrState ExecutionErrorState `json:"exec_err_state" yaml:"exec_err_state"` ExecErrState ExecutionErrorState `json:"exec_err_state" yaml:"exec_err_state"`
+2 -7
View File
@@ -1431,10 +1431,6 @@
"is_paused": { "is_paused": {
"type": "boolean" "type": "boolean"
}, },
"namespace_id": {
"format": "int64",
"type": "integer"
},
"namespace_uid": { "namespace_uid": {
"type": "string" "type": "string"
}, },
@@ -3988,6 +3984,7 @@
"type": "object" "type": "object"
}, },
"URL": { "URL": {
"description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use the EscapedPath method, which preserves\nthe original encoding of Path.\n\nThe RawPath field is an optional field which is only set when the default\nencoding of Path is different from the escaped path. See the EscapedPath method\nfor more details.\n\nURL's String method uses the EscapedPath method to obtain the path.",
"properties": { "properties": {
"ForceQuery": { "ForceQuery": {
"type": "boolean" "type": "boolean"
@@ -4023,7 +4020,7 @@
"$ref": "#/definitions/Userinfo" "$ref": "#/definitions/Userinfo"
} }
}, },
"title": "URL is a custom URL type that allows validation at configuration load time.", "title": "A URL represents a parsed URL (technically, a URI reference).",
"type": "object" "type": "object"
}, },
"UpdateRuleGroupResponse": { "UpdateRuleGroupResponse": {
@@ -4412,7 +4409,6 @@
"type": "object" "type": "object"
}, },
"gettableAlerts": { "gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"items": { "items": {
"$ref": "#/definitions/gettableAlert" "$ref": "#/definitions/gettableAlert"
}, },
@@ -4655,7 +4651,6 @@
"type": "object" "type": "object"
}, },
"receiver": { "receiver": {
"description": "Receiver receiver",
"properties": { "properties": {
"active": { "active": {
"description": "active", "description": "active",
+2 -7
View File
@@ -4624,10 +4624,6 @@
"is_paused": { "is_paused": {
"type": "boolean" "type": "boolean"
}, },
"namespace_id": {
"type": "integer",
"format": "int64"
},
"namespace_uid": { "namespace_uid": {
"type": "string" "type": "string"
}, },
@@ -7181,8 +7177,9 @@
} }
}, },
"URL": { "URL": {
"description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use the EscapedPath method, which preserves\nthe original encoding of Path.\n\nThe RawPath field is an optional field which is only set when the default\nencoding of Path is different from the escaped path. See the EscapedPath method\nfor more details.\n\nURL's String method uses the EscapedPath method to obtain the path.",
"type": "object", "type": "object",
"title": "URL is a custom URL type that allows validation at configuration load time.", "title": "A URL represents a parsed URL (technically, a URI reference).",
"properties": { "properties": {
"ForceQuery": { "ForceQuery": {
"type": "boolean" "type": "boolean"
@@ -7608,7 +7605,6 @@
"$ref": "#/definitions/gettableAlert" "$ref": "#/definitions/gettableAlert"
}, },
"gettableAlerts": { "gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/gettableAlert" "$ref": "#/definitions/gettableAlert"
@@ -7856,7 +7852,6 @@
"$ref": "#/definitions/postableSilence" "$ref": "#/definitions/postableSilence"
}, },
"receiver": { "receiver": {
"description": "Receiver receiver",
"type": "object", "type": "object",
"required": [ "required": [
"active", "active",
-1
View File
@@ -460,7 +460,6 @@ func (st DBstore) GetUserVisibleNamespaces(ctx context.Context, orgID int64, use
continue continue
} }
namespaceMap[hit.UID] = &folder.Folder{ namespaceMap[hit.UID] = &folder.Folder{
ID: hit.ID, // nolint:staticcheck
UID: hit.UID, UID: hit.UID,
Title: hit.Title, Title: hit.Title,
} }
@@ -772,7 +772,6 @@ func TestIntegrationDeleteFolderWithRules(t *testing.T) {
"version": 1, "version": 1,
"uid": "", "uid": "",
"namespace_uid": %q, "namespace_uid": %q,
"namespace_id": 1,
"rule_group": "arulegroup", "rule_group": "arulegroup",
"no_data_state": "NoData", "no_data_state": "NoData",
"exec_err_state": "Alerting" "exec_err_state": "Alerting"
@@ -1250,7 +1249,6 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
"version":1, "version":1,
"uid":"uid", "uid":"uid",
"namespace_uid":"nsuid", "namespace_uid":"nsuid",
"namespace_id":1,
"rule_group":"arulegroup", "rule_group":"arulegroup",
"no_data_state":"NoData", "no_data_state":"NoData",
"exec_err_state":"Alerting" "exec_err_state":"Alerting"
@@ -1287,7 +1285,6 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
"version":1, "version":1,
"uid":"uid", "uid":"uid",
"namespace_uid":"nsuid", "namespace_uid":"nsuid",
"namespace_id":1,
"rule_group":"arulegroup", "rule_group":"arulegroup",
"no_data_state":"Alerting", "no_data_state":"Alerting",
"exec_err_state":"Alerting" "exec_err_state":"Alerting"
@@ -1596,7 +1593,6 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
"version":2, "version":2,
"uid":"uid", "uid":"uid",
"namespace_uid":"nsuid", "namespace_uid":"nsuid",
"namespace_id":1,
"rule_group":"arulegroup", "rule_group":"arulegroup",
"no_data_state":"Alerting", "no_data_state":"Alerting",
"exec_err_state":"Alerting" "exec_err_state":"Alerting"
@@ -1706,7 +1702,6 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
"version":3, "version":3,
"uid":"uid", "uid":"uid",
"namespace_uid":"nsuid", "namespace_uid":"nsuid",
"namespace_id":1,
"rule_group":"arulegroup", "rule_group":"arulegroup",
"no_data_state":"Alerting", "no_data_state":"Alerting",
"exec_err_state":"Alerting" "exec_err_state":"Alerting"
@@ -1795,7 +1790,6 @@ func TestIntegrationAlertRuleCRUD(t *testing.T) {
"version":3, "version":3,
"uid":"uid", "uid":"uid",
"namespace_uid":"nsuid", "namespace_uid":"nsuid",
"namespace_id":1,
"rule_group":"arulegroup", "rule_group":"arulegroup",
"no_data_state":"Alerting", "no_data_state":"Alerting",
"exec_err_state":"Alerting" "exec_err_state":"Alerting"
@@ -2102,7 +2096,6 @@ func TestIntegrationQuota(t *testing.T) {
"version":2, "version":2,
"uid":"uid", "uid":"uid",
"namespace_uid":"nsuid", "namespace_uid":"nsuid",
"namespace_id":1,
"rule_group":"arulegroup", "rule_group":"arulegroup",
"no_data_state":"NoData", "no_data_state":"NoData",
"exec_err_state":"Alerting" "exec_err_state":"Alerting"
-5
View File
@@ -136,11 +136,9 @@ func TestIntegrationAlertRulePermissions(t *testing.T) {
for _, rule := range allRules["folder1"][0].Rules { for _, rule := range allRules["folder1"][0].Rules {
assert.Equal(t, "folder1", rule.GrafanaManagedAlert.NamespaceUID) assert.Equal(t, "folder1", rule.GrafanaManagedAlert.NamespaceUID)
assert.Equal(t, int64(1), rule.GrafanaManagedAlert.NamespaceID)
} }
for _, rule := range allRules["folder2"][0].Rules { for _, rule := range allRules["folder2"][0].Rules {
assert.Equal(t, "folder2", rule.GrafanaManagedAlert.NamespaceUID) assert.Equal(t, "folder2", rule.GrafanaManagedAlert.NamespaceUID)
assert.Equal(t, int64(2), rule.GrafanaManagedAlert.NamespaceID)
} }
}) })
@@ -664,7 +662,6 @@ func TestIntegrationRulerRulesFilterByDashboard(t *testing.T) {
"version": 1, "version": 1,
"uid": "uid", "uid": "uid",
"namespace_uid": "nsuid", "namespace_uid": "nsuid",
"namespace_id": 1,
"rule_group": "anotherrulegroup", "rule_group": "anotherrulegroup",
"no_data_state": "NoData", "no_data_state": "NoData",
"exec_err_state": "Alerting" "exec_err_state": "Alerting"
@@ -698,7 +695,6 @@ func TestIntegrationRulerRulesFilterByDashboard(t *testing.T) {
"version": 1, "version": 1,
"uid": "uid", "uid": "uid",
"namespace_uid": "nsuid", "namespace_uid": "nsuid",
"namespace_id": 1,
"rule_group": "anotherrulegroup", "rule_group": "anotherrulegroup",
"no_data_state": "Alerting", "no_data_state": "Alerting",
"exec_err_state": "Alerting" "exec_err_state": "Alerting"
@@ -744,7 +740,6 @@ func TestIntegrationRulerRulesFilterByDashboard(t *testing.T) {
"version": 1, "version": 1,
"uid": "uid", "uid": "uid",
"namespace_uid": "nsuid", "namespace_uid": "nsuid",
"namespace_id": 1,
"rule_group": "anotherrulegroup", "rule_group": "anotherrulegroup",
"no_data_state": "NoData", "no_data_state": "NoData",
"exec_err_state": "Alerting" "exec_err_state": "Alerting"
@@ -38,7 +38,6 @@
"version": 1, "version": 1,
"uid": "<dynamic>", "uid": "<dynamic>",
"namespace_uid": "<dynamic>", "namespace_uid": "<dynamic>",
"namespace_id": 0,
"rule_group": "Group1", "rule_group": "Group1",
"no_data_state": "NoData", "no_data_state": "NoData",
"exec_err_state": "Alerting", "exec_err_state": "Alerting",
@@ -81,7 +80,6 @@
"version": 1, "version": 1,
"uid": "<dynamic>", "uid": "<dynamic>",
"namespace_uid": "<dynamic>", "namespace_uid": "<dynamic>",
"namespace_id": 0,
"rule_group": "Group1", "rule_group": "Group1",
"no_data_state": "NoData", "no_data_state": "NoData",
"exec_err_state": "Alerting", "exec_err_state": "Alerting",
@@ -38,7 +38,6 @@
"version": 1, "version": 1,
"uid": "<dynamic>", "uid": "<dynamic>",
"namespace_uid": "<dynamic>", "namespace_uid": "<dynamic>",
"namespace_id": 0,
"rule_group": "Group2", "rule_group": "Group2",
"no_data_state": "NoData", "no_data_state": "NoData",
"exec_err_state": "Error", "exec_err_state": "Error",
-5
View File
@@ -14733,10 +14733,6 @@
"is_paused": { "is_paused": {
"type": "boolean" "type": "boolean"
}, },
"namespace_id": {
"type": "integer",
"format": "int64"
},
"namespace_uid": { "namespace_uid": {
"type": "string" "type": "string"
}, },
@@ -20962,7 +20958,6 @@
} }
}, },
"integration": { "integration": {
"description": "Integration integration",
"type": "object", "type": "object",
"required": [ "required": [
"name", "name",
@@ -145,7 +145,6 @@ describe('RuleEditor grafana managed rules', () => {
grafana_alert: { grafana_alert: {
uid, uid,
namespace_uid: 'abcd', namespace_uid: 'abcd',
namespace_id: 1,
condition: 'B', condition: 'B',
data: getDefaultQueries(), data: getDefaultQueries(),
exec_err_state: GrafanaAlertStateDecision.Error, exec_err_state: GrafanaAlertStateDecision.Error,
@@ -76,7 +76,6 @@ describe('GrafanaModifyExport', () => {
uid: 'test-rule-uid', uid: 'test-rule-uid',
title: 'cpu-usage', title: 'cpu-usage',
namespace_uid: 'folder-test-uid', namespace_uid: 'folder-test-uid',
namespace_id: 1,
data: [ data: [
{ {
refId: 'A', refId: 'A',
@@ -114,7 +114,6 @@ export const mockRulerGrafanaRule = (
uid: '123', uid: '123',
title: 'myalert', title: 'myalert',
namespace_uid: '123', namespace_uid: '123',
namespace_id: 1,
condition: 'A', condition: 'A',
no_data_state: GrafanaAlertStateDecision.Alerting, no_data_state: GrafanaAlertStateDecision.Alerting,
exec_err_state: GrafanaAlertStateDecision.Alerting, exec_err_state: GrafanaAlertStateDecision.Alerting,
@@ -212,7 +211,6 @@ export const mockGrafanaRulerRule = (partial: Partial<GrafanaRuleDefinition> = {
uid: '', uid: '',
title: 'my rule', title: 'my rule',
namespace_uid: 'NAMESPACE_UID', namespace_uid: 'NAMESPACE_UID',
namespace_id: 0,
condition: '', condition: '',
no_data_state: GrafanaAlertStateDecision.NoData, no_data_state: GrafanaAlertStateDecision.NoData,
exec_err_state: GrafanaAlertStateDecision.Error, exec_err_state: GrafanaAlertStateDecision.Error,
@@ -88,7 +88,6 @@ describe('alertRuleToQueries', () => {
const grafanaAlert = { const grafanaAlert = {
condition: 'B', condition: 'B',
exec_err_state: GrafanaAlertStateDecision.Alerting, exec_err_state: GrafanaAlertStateDecision.Alerting,
namespace_id: 11,
namespace_uid: 'namespaceuid123', namespace_uid: 'namespaceuid123',
no_data_state: GrafanaAlertStateDecision.NoData, no_data_state: GrafanaAlertStateDecision.NoData,
title: 'Test alert', title: 'Test alert',
@@ -46,7 +46,6 @@ describe('hashRulerRule', () => {
const grafanaAlertDefinition: GrafanaRuleDefinition = { const grafanaAlertDefinition: GrafanaRuleDefinition = {
uid: RULE_UID, uid: RULE_UID,
namespace_uid: 'namespace', namespace_uid: 'namespace',
namespace_id: 0,
title: 'my rule', title: 'my rule',
condition: '', condition: '',
data: [], data: [],
@@ -44,7 +44,6 @@ export function getRulerRulesResponse(folderName: string, folderUid: string, see
], ],
uid: random.guid(), uid: random.guid(),
namespace_uid: folderUid, namespace_uid: folderUid,
namespace_id: 0,
no_data_state: GrafanaAlertStateDecision.NoData, no_data_state: GrafanaAlertStateDecision.NoData,
exec_err_state: GrafanaAlertStateDecision.Error, exec_err_state: GrafanaAlertStateDecision.Error,
is_paused: false, is_paused: false,
-1
View File
@@ -210,7 +210,6 @@ export interface GrafanaRuleDefinition extends PostableGrafanaRuleDefinition {
id?: string; id?: string;
uid: string; uid: string;
namespace_uid: string; namespace_uid: string;
namespace_id: number;
provenance?: string; provenance?: string;
} }
-5
View File
@@ -5625,10 +5625,6 @@
"is_paused": { "is_paused": {
"type": "boolean" "type": "boolean"
}, },
"namespace_id": {
"format": "int64",
"type": "integer"
},
"namespace_uid": { "namespace_uid": {
"type": "string" "type": "string"
}, },
@@ -11853,7 +11849,6 @@
"type": "array" "type": "array"
}, },
"integration": { "integration": {
"description": "Integration integration",
"properties": { "properties": {
"lastNotifyAttempt": { "lastNotifyAttempt": {
"description": "A timestamp indicating the last attempt to deliver a notification regardless of the outcome.\nFormat: date-time", "description": "A timestamp indicating the last attempt to deliver a notification regardless of the outcome.\nFormat: date-time",