Alerting: modify ruler endpoints for proxying using the datasource UID (#48046)

* Modify ruler endpoints to expect the data source UID

* Update frontend

* Apply suggestion from code review
This commit is contained in:
Sofia Papagiannaki 2022-05-05 14:58:32 +03:00 committed by GitHub
parent 65d7d466d7
commit 610247d52a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 200 additions and 199 deletions

View File

@ -74,18 +74,18 @@ func (api *API) authorize(method, path string) web.Handler {
eval = ac.EvalPermission(ac.ActionAlertingRuleRead) eval = ac.EvalPermission(ac.ActionAlertingRuleRead)
// Lotex Paths // Lotex Paths
case http.MethodDelete + "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}": case http.MethodDelete + "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}":
eval = ac.EvalPermission(ac.ActionAlertingRuleExternalWrite, datasources.ScopeProvider.GetResourceScope(ac.Parameter(":DatasourceID"))) eval = ac.EvalPermission(ac.ActionAlertingRuleExternalWrite, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID")))
case http.MethodDelete + "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}": case http.MethodDelete + "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}":
eval = ac.EvalPermission(ac.ActionAlertingRuleExternalWrite, datasources.ScopeProvider.GetResourceScope(ac.Parameter(":DatasourceID"))) eval = ac.EvalPermission(ac.ActionAlertingRuleExternalWrite, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID")))
case http.MethodGet + "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}": case http.MethodGet + "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}":
eval = ac.EvalPermission(ac.ActionAlertingRuleExternalRead, datasources.ScopeProvider.GetResourceScope(ac.Parameter(":DatasourceID"))) eval = ac.EvalPermission(ac.ActionAlertingRuleExternalRead, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID")))
case http.MethodGet + "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}": case http.MethodGet + "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}":
eval = ac.EvalPermission(ac.ActionAlertingRuleExternalRead, datasources.ScopeProvider.GetResourceScope(ac.Parameter(":DatasourceID"))) eval = ac.EvalPermission(ac.ActionAlertingRuleExternalRead, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID")))
case http.MethodGet + "/api/ruler/{DatasourceID}/api/v1/rules": case http.MethodGet + "/api/ruler/{DatasourceUID}/api/v1/rules":
eval = ac.EvalPermission(ac.ActionAlertingRuleExternalRead, datasources.ScopeProvider.GetResourceScope(ac.Parameter(":DatasourceID"))) eval = ac.EvalPermission(ac.ActionAlertingRuleExternalRead, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID")))
case http.MethodPost + "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}": case http.MethodPost + "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}":
eval = ac.EvalPermission(ac.ActionAlertingInstancesExternalWrite, datasources.ScopeProvider.GetResourceScope(ac.Parameter(":DatasourceID"))) eval = ac.EvalPermission(ac.ActionAlertingInstancesExternalWrite, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID")))
// Lotex Prometheus-compatible Paths // Lotex Prometheus-compatible Paths
case http.MethodGet + "/api/prometheus/{DatasourceID}/api/v1/rules": case http.MethodGet + "/api/prometheus/{DatasourceID}/api/v1/rules":

View File

@ -26,7 +26,7 @@ func NewForkedRuler(datasourceCache datasources.CacheService, lotex *LotexRuler,
} }
func (f *ForkedRulerApi) forkRouteDeleteNamespaceRulesConfig(ctx *models.ReqContext) response.Response { func (f *ForkedRulerApi) forkRouteDeleteNamespaceRulesConfig(ctx *models.ReqContext) response.Response {
t, err := backendType(ctx, f.DatasourceCache) t, err := backendTypeByUID(ctx, f.DatasourceCache)
if err != nil { if err != nil {
return ErrResp(400, err, "") return ErrResp(400, err, "")
} }
@ -39,7 +39,7 @@ func (f *ForkedRulerApi) forkRouteDeleteNamespaceRulesConfig(ctx *models.ReqCont
} }
func (f *ForkedRulerApi) forkRouteDeleteRuleGroupConfig(ctx *models.ReqContext) response.Response { func (f *ForkedRulerApi) forkRouteDeleteRuleGroupConfig(ctx *models.ReqContext) response.Response {
t, err := backendType(ctx, f.DatasourceCache) t, err := backendTypeByUID(ctx, f.DatasourceCache)
if err != nil { if err != nil {
return ErrResp(400, err, "") return ErrResp(400, err, "")
} }
@ -52,7 +52,7 @@ func (f *ForkedRulerApi) forkRouteDeleteRuleGroupConfig(ctx *models.ReqContext)
} }
func (f *ForkedRulerApi) forkRouteGetNamespaceRulesConfig(ctx *models.ReqContext) response.Response { func (f *ForkedRulerApi) forkRouteGetNamespaceRulesConfig(ctx *models.ReqContext) response.Response {
t, err := backendType(ctx, f.DatasourceCache) t, err := backendTypeByUID(ctx, f.DatasourceCache)
if err != nil { if err != nil {
return ErrResp(400, err, "") return ErrResp(400, err, "")
} }
@ -65,7 +65,7 @@ func (f *ForkedRulerApi) forkRouteGetNamespaceRulesConfig(ctx *models.ReqContext
} }
func (f *ForkedRulerApi) forkRouteGetRulegGroupConfig(ctx *models.ReqContext) response.Response { func (f *ForkedRulerApi) forkRouteGetRulegGroupConfig(ctx *models.ReqContext) response.Response {
t, err := backendType(ctx, f.DatasourceCache) t, err := backendTypeByUID(ctx, f.DatasourceCache)
if err != nil { if err != nil {
return ErrResp(400, err, "") return ErrResp(400, err, "")
} }
@ -78,7 +78,7 @@ func (f *ForkedRulerApi) forkRouteGetRulegGroupConfig(ctx *models.ReqContext) re
} }
func (f *ForkedRulerApi) forkRouteGetRulesConfig(ctx *models.ReqContext) response.Response { func (f *ForkedRulerApi) forkRouteGetRulesConfig(ctx *models.ReqContext) response.Response {
t, err := backendType(ctx, f.DatasourceCache) t, err := backendTypeByUID(ctx, f.DatasourceCache)
if err != nil { if err != nil {
return ErrResp(400, err, "") return ErrResp(400, err, "")
} }
@ -91,7 +91,7 @@ func (f *ForkedRulerApi) forkRouteGetRulesConfig(ctx *models.ReqContext) respons
} }
func (f *ForkedRulerApi) forkRoutePostNameRulesConfig(ctx *models.ReqContext, conf apimodels.PostableRuleGroupConfig) response.Response { func (f *ForkedRulerApi) forkRoutePostNameRulesConfig(ctx *models.ReqContext, conf apimodels.PostableRuleGroupConfig) response.Response {
backendType, err := backendType(ctx, f.DatasourceCache) backendType, err := backendTypeByUID(ctx, f.DatasourceCache)
if err != nil { if err != nil {
return ErrResp(400, err, "") return ErrResp(400, err, "")
} }

View File

@ -113,21 +113,21 @@ func (api *API) RegisterRulerApiEndpoints(srv RulerApiForkingService, m *metrics
), ),
) )
group.Delete( group.Delete(
toMacaronPath("/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}"), toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
api.authorize(http.MethodDelete, "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}"), api.authorize(http.MethodDelete, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
metrics.Instrument( metrics.Instrument(
http.MethodDelete, http.MethodDelete,
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}", "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}",
srv.RouteDeleteNamespaceRulesConfig, srv.RouteDeleteNamespaceRulesConfig,
m, m,
), ),
) )
group.Delete( group.Delete(
toMacaronPath("/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}"), toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
api.authorize(http.MethodDelete, "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}"), api.authorize(http.MethodDelete, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
metrics.Instrument( metrics.Instrument(
http.MethodDelete, http.MethodDelete,
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}", "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}",
srv.RouteDeleteRuleGroupConfig, srv.RouteDeleteRuleGroupConfig,
m, m,
), ),
@ -163,31 +163,31 @@ func (api *API) RegisterRulerApiEndpoints(srv RulerApiForkingService, m *metrics
), ),
) )
group.Get( group.Get(
toMacaronPath("/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}"), toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
api.authorize(http.MethodGet, "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}"), api.authorize(http.MethodGet, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
metrics.Instrument( metrics.Instrument(
http.MethodGet, http.MethodGet,
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}", "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}",
srv.RouteGetNamespaceRulesConfig, srv.RouteGetNamespaceRulesConfig,
m, m,
), ),
) )
group.Get( group.Get(
toMacaronPath("/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}"), toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
api.authorize(http.MethodGet, "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}"), api.authorize(http.MethodGet, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}"),
metrics.Instrument( metrics.Instrument(
http.MethodGet, http.MethodGet,
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}", "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}",
srv.RouteGetRulegGroupConfig, srv.RouteGetRulegGroupConfig,
m, m,
), ),
) )
group.Get( group.Get(
toMacaronPath("/api/ruler/{DatasourceID}/api/v1/rules"), toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules"),
api.authorize(http.MethodGet, "/api/ruler/{DatasourceID}/api/v1/rules"), api.authorize(http.MethodGet, "/api/ruler/{DatasourceUID}/api/v1/rules"),
metrics.Instrument( metrics.Instrument(
http.MethodGet, http.MethodGet,
"/api/ruler/{DatasourceID}/api/v1/rules", "/api/ruler/{DatasourceUID}/api/v1/rules",
srv.RouteGetRulesConfig, srv.RouteGetRulesConfig,
m, m,
), ),
@ -203,11 +203,11 @@ func (api *API) RegisterRulerApiEndpoints(srv RulerApiForkingService, m *metrics
), ),
) )
group.Post( group.Post(
toMacaronPath("/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}"), toMacaronPath("/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
api.authorize(http.MethodPost, "/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}"), api.authorize(http.MethodPost, "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}"),
metrics.Instrument( metrics.Instrument(
http.MethodPost, http.MethodPost,
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}", "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}",
srv.RoutePostNameRulesConfig, srv.RoutePostNameRulesConfig,
m, m,
), ),

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
"github.com/grafana/grafana/pkg/web" "github.com/grafana/grafana/pkg/web"
@ -176,12 +175,12 @@ func (r *LotexRuler) RoutePostNameRulesConfig(ctx *models.ReqContext, conf apimo
} }
func (r *LotexRuler) validateAndGetPrefix(ctx *models.ReqContext) (string, error) { func (r *LotexRuler) validateAndGetPrefix(ctx *models.ReqContext) (string, error) {
datasourceID, err := strconv.ParseInt(web.Params(ctx.Req)[":DatasourceID"], 10, 64) datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
if err != nil { if datasourceUID == "" {
return "", fmt.Errorf("datasource ID is invalid") return "", fmt.Errorf("datasource UID is invalid")
} }
ds, err := r.DataProxy.DataSourceCache.GetDatasource(ctx.Req.Context(), datasourceID, ctx.SignedInUser, ctx.SkipCache) ds, err := r.DataProxy.DataSourceCache.GetDatasourceByUID(ctx.Req.Context(), datasourceUID, ctx.SignedInUser, ctx.SkipCache)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -25,64 +25,64 @@ func TestLotexRuler_ValidateAndGetPrefix(t *testing.T) {
err error err error
}{ }{
{ {
name: "with an invalid datasource ID", name: "with an empty datasource UID",
namedParams: map[string]string{":DatasourceID": "AAABBB"}, namedParams: map[string]string{":DatasourceUID": ""},
err: errors.New("datasource ID is invalid"), err: errors.New("datasource UID is invalid"),
}, },
{ {
name: "with an error while trying to fetch the datasource", name: "with an error while trying to fetch the datasource",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
datasourceCache: fakeCacheService{err: models.ErrDataSourceNotFound}, datasourceCache: fakeCacheService{err: models.ErrDataSourceNotFound},
err: errors.New("data source not found"), err: errors.New("data source not found"),
}, },
{ {
name: "with an empty datasource URL", name: "with an empty datasource URL",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
datasourceCache: fakeCacheService{datasource: &models.DataSource{}}, datasourceCache: fakeCacheService{datasource: &models.DataSource{}},
err: errors.New("URL for this data source is empty"), err: errors.New("URL for this data source is empty"),
}, },
{ {
name: "with an unsupported datasource type", name: "with an unsupported datasource type",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com"}}, datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com"}},
err: errors.New("unexpected datasource type. expecting loki or prometheus"), err: errors.New("unexpected datasource type. expecting loki or prometheus"),
}, },
{ {
name: "with a Loki datasource", name: "with a Loki datasource",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: LokiDatasourceType}}, datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: LokiDatasourceType}},
expected: "/api/prom/rules", expected: "/api/prom/rules",
}, },
{ {
name: "with a Prometheus datasource", name: "with a Prometheus datasource",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}}, datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
expected: "/rules", expected: "/rules",
}, },
{ {
name: "with a Prometheus datasource and subtype of Cortex", name: "with a Prometheus datasource and subtype of Cortex",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
urlParams: "?subtype=cortex", urlParams: "?subtype=cortex",
datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}}, datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
expected: "/rules", expected: "/rules",
}, },
{ {
name: "with a Prometheus datasource and subtype of Mimir", name: "with a Prometheus datasource and subtype of Mimir",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
urlParams: "?subtype=mimir", urlParams: "?subtype=mimir",
datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}}, datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
expected: "/config/v1/rules", expected: "/config/v1/rules",
}, },
{ {
name: "with a Prometheus datasource and subtype of Prometheus", name: "with a Prometheus datasource and subtype of Prometheus",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
urlParams: "?subtype=prometheus", urlParams: "?subtype=prometheus",
datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}}, datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
expected: "/rules", expected: "/rules",
}, },
{ {
name: "with a Prometheus datasource and no subtype", name: "with a Prometheus datasource and no subtype",
namedParams: map[string]string{":DatasourceID": "164"}, namedParams: map[string]string{":DatasourceUID": "d164"},
datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}}, datasourceCache: fakeCacheService{datasource: &models.DataSource{Url: "http://loki.com", Type: PrometheusDatasourceType}},
expected: "/rules", expected: "/rules",
}, },

View File

@ -1,10 +1,10 @@
@prometheusDatasourceID = 35 @prometheusDatasourceUID = 7DEsN5_Mk
// should point to an existing folder named alerting // should point to an existing folder named alerting
@namespace1 = test @namespace1 = test
// create/update test namespace group42 rulegroup // create/update test namespace group42 rulegroup
POST http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} POST http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}
content-type: application/json content-type: application/json
{ {
@ -20,7 +20,7 @@ content-type: application/json
### ###
// create group101 // create group101
POST http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} POST http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}
content-type: application/json content-type: application/json
{ {
@ -36,40 +36,41 @@ content-type: application/json
### ###
// get group42 rules // get group42 rules
GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}}/group42 GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}/group42
### ###
// get group101 rules // get group101 rules
GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}}/group101 GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}/group101
### ###
// get namespace rules // get namespace rules
GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}
### ###
// get org rules // get org rules
GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules
### ###
// delete group42 rules // delete group42 rules
DELETE http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}}/group42 DELETE http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}/group42
### ###
// get namespace rules - only group101 should be listed // get namespace rules - only group101 should be listed
GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}
### ###
// delete namespace rules // delete namespace rules
DELETE http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} DELETE http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}
### ###
// get namespace rules - no rules // get namespace rules - no rules
GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}
### ###
// get group42 rules // get group42 rules
GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}}/group42 GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}/group42
### ###
// get namespace rules // get namespace rules
GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceID}}/api/v1/rules/{{namespace1}} GET http://admin:admin@localhost:3000/api/ruler/{{prometheusDatasourceUID}}/api/v1/rules/{{namespace1}}
U

View File

@ -1,10 +1,10 @@
@lokiDatasourceID = 32 @lokiDatasourceUID = 9w8X2zlMz
// should point to an existing folder named alerting // should point to an existing folder named alerting
@namespace1 = test @namespace1 = test
// create/update test namespace group42 rulegroup // create/update test namespace group42 rulegroup
POST http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} POST http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}
content-type: application/json content-type: application/json
{ {
@ -20,7 +20,7 @@ content-type: application/json
### ###
// create group101 // create group101
POST http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} POST http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}
content-type: application/json content-type: application/json
{ {
@ -36,40 +36,40 @@ content-type: application/json
### ###
// get group42 rules // get group42 rules
GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}}/group42 GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}/group42
### ###
// get group101 rules // get group101 rules
GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}}/group101 GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}/group101
### ###
// get namespace rules // get namespace rules
GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}
### ###
// get org rules // get org rules
GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules
### ###
// delete group42 rules // delete group42 rules
DELETE http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}}/group42 DELETE http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}/group42
### ###
// get namespace rules - only group101 should be listed // get namespace rules - only group101 should be listed
GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}
### ###
// delete namespace rules // delete namespace rules
DELETE http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} DELETE http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}
### ###
// get namespace rules - no rules // get namespace rules - no rules
GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}
### ###
// get group42 rules // get group42 rules
GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}}/group42 GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}/group42
### ###
// get namespace rules // get namespace rules
GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceID}}/api/v1/rules/{{namespace1}} GET http://admin:admin@localhost:3000/api/ruler/{{lokiDatasourceUID}}/api/v1/rules/{{namespace1}}

View File

@ -427,21 +427,17 @@ type AlertsParams struct {
} }
// swagger:parameters RoutePostAMAlerts RoutePostGrafanaAMAlerts // swagger:parameters RoutePostAMAlerts RoutePostGrafanaAMAlerts
// swagger:parameters RoutePostAMAlerts
type PostableAlerts struct { type PostableAlerts struct {
// in:body // in:body
PostableAlerts []amv2.PostableAlert `yaml:"" json:""` PostableAlerts []amv2.PostableAlert `yaml:"" json:""`
} }
// swagger:parameters RoutePostAlertingConfig RoutePostGrafanaAlertingConfig // swagger:parameters RoutePostAlertingConfig RoutePostGrafanaAlertingConfig
// swagger:parameters RoutePostAlertingConfig
type BodyAlertingConfig struct { type BodyAlertingConfig struct {
// in:body // in:body
Body PostableUserConfig Body PostableUserConfig
} }
// ruler routes
// swagger:parameters RouteGetRulesConfig RoutePostNameRulesConfig RouteGetNamespaceRulesConfig RouteDeleteNamespaceRulesConfig RouteGetRulegGroupConfig RouteDeleteRuleGroupConfig
// prom routes // prom routes
// swagger:parameters RouteGetRuleStatuses RouteGetAlertStatuses // swagger:parameters RouteGetRuleStatuses RouteGetAlertStatuses
// testing routes // testing routes
@ -454,6 +450,8 @@ type DatasourceIDReference struct {
// alertmanager routes // alertmanager routes
// swagger:parameters RoutePostAlertingConfig RouteGetAlertingConfig RouteDeleteAlertingConfig RouteGetAMStatus RouteGetAMAlerts RoutePostAMAlerts RouteGetAMAlertGroups RouteGetSilences RouteCreateSilence RouteGetSilence RouteDeleteSilence RoutePostAlertingConfig RoutePostTestReceivers // swagger:parameters RoutePostAlertingConfig RouteGetAlertingConfig RouteDeleteAlertingConfig RouteGetAMStatus RouteGetAMAlerts RoutePostAMAlerts RouteGetAMAlertGroups RouteGetSilences RouteCreateSilence RouteGetSilence RouteDeleteSilence RoutePostAlertingConfig RoutePostTestReceivers
// ruler routes
// swagger:parameters RouteGetRulesConfig RoutePostNameRulesConfig RouteGetNamespaceRulesConfig RouteDeleteNamespaceRulesConfig RouteGetRulegGroupConfig RouteDeleteRuleGroupConfig
type DatasourceUIDReference struct { type DatasourceUIDReference struct {
// DatasoureUID should be the datasource UID identifier // DatasoureUID should be the datasource UID identifier
// in:path // in:path

View File

@ -21,7 +21,7 @@ import (
// 202: NamespaceConfigResponse // 202: NamespaceConfigResponse
// //
// swagger:route Get /api/ruler/{DatasourceID}/api/v1/rules ruler RouteGetRulesConfig // swagger:route Get /api/ruler/{DatasourceUID}/api/v1/rules ruler RouteGetRulesConfig
// //
// List rule groups // List rule groups
// //
@ -43,7 +43,7 @@ import (
// 202: Ack // 202: Ack
// //
// swagger:route POST /api/ruler/{DatasourceID}/api/v1/rules/{Namespace} ruler RoutePostNameRulesConfig // swagger:route POST /api/ruler/{DatasourceUID}/api/v1/rules/{Namespace} ruler RoutePostNameRulesConfig
// //
// Creates or updates a rule group // Creates or updates a rule group
// //
@ -64,7 +64,7 @@ import (
// Responses: // Responses:
// 202: NamespaceConfigResponse // 202: NamespaceConfigResponse
// swagger:route Get /api/ruler/{DatasourceID}/api/v1/rules/{Namespace} ruler RouteGetNamespaceRulesConfig // swagger:route Get /api/ruler/{DatasourceUID}/api/v1/rules/{Namespace} ruler RouteGetNamespaceRulesConfig
// //
// Get rule groups by namespace // Get rule groups by namespace
// //
@ -81,7 +81,7 @@ import (
// Responses: // Responses:
// 202: Ack // 202: Ack
// swagger:route Delete /api/ruler/{DatasourceID}/api/v1/rules/{Namespace} ruler RouteDeleteNamespaceRulesConfig // swagger:route Delete /api/ruler/{DatasourceUID}/api/v1/rules/{Namespace} ruler RouteDeleteNamespaceRulesConfig
// //
// Delete namespace // Delete namespace
// //
@ -98,7 +98,7 @@ import (
// Responses: // Responses:
// 202: RuleGroupConfigResponse // 202: RuleGroupConfigResponse
// swagger:route Get /api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname} ruler RouteGetRulegGroupConfig // swagger:route Get /api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname} ruler RouteGetRulegGroupConfig
// //
// Get rule group // Get rule group
// //
@ -115,7 +115,7 @@ import (
// Responses: // Responses:
// 202: Ack // 202: Ack
// swagger:route Delete /api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname} ruler RouteDeleteRuleGroupConfig // swagger:route Delete /api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname} ruler RouteDeleteRuleGroupConfig
// //
// Delete rule group // Delete rule group
// //

View File

@ -977,6 +977,9 @@
"type": "integer", "type": "integer",
"x-go-name": "OrgID" "x-go-name": "OrgID"
}, },
"provenance": {
"$ref": "#/definitions/Provenance"
},
"rule_group": { "rule_group": {
"type": "string", "type": "string",
"x-go-name": "RuleGroup" "x-go-name": "RuleGroup"
@ -3103,7 +3106,6 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models" "x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"alertGroup": { "alertGroup": {
"description": "AlertGroup alert group",
"properties": { "properties": {
"alerts": { "alerts": {
"description": "alerts", "description": "alerts",
@ -3125,14 +3127,17 @@
"labels", "labels",
"receiver" "receiver"
], ],
"type": "object" "type": "object",
"x-go-name": "AlertGroup",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"alertGroups": { "alertGroups": {
"description": "AlertGroups alert groups",
"items": { "items": {
"$ref": "#/definitions/alertGroup" "$ref": "#/definitions/alertGroup"
}, },
"type": "array" "type": "array",
"x-go-name": "AlertGroups",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"alertStatus": { "alertStatus": {
"description": "AlertStatus alert status", "description": "AlertStatus alert status",
@ -3252,7 +3257,6 @@
"$ref": "#/definitions/Duration" "$ref": "#/definitions/Duration"
}, },
"gettableAlert": { "gettableAlert": {
"description": "GettableAlert gettable alert",
"properties": { "properties": {
"annotations": { "annotations": {
"$ref": "#/definitions/labelSet" "$ref": "#/definitions/labelSet"
@ -3311,7 +3315,9 @@
"status", "status",
"updatedAt" "updatedAt"
], ],
"type": "object" "type": "object",
"x-go-name": "GettableAlert",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"gettableAlerts": { "gettableAlerts": {
"description": "GettableAlerts gettable alerts", "description": "GettableAlerts gettable alerts",
@ -3376,11 +3382,12 @@
"type": "object" "type": "object"
}, },
"gettableSilences": { "gettableSilences": {
"description": "GettableSilences gettable silences",
"items": { "items": {
"$ref": "#/definitions/gettableSilence" "$ref": "#/definitions/gettableSilence"
}, },
"type": "array" "type": "array",
"x-go-name": "GettableSilences",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"labelSet": { "labelSet": {
"additionalProperties": { "additionalProperties": {
@ -5162,18 +5169,17 @@
] ]
} }
}, },
"/api/ruler/{DatasourceID}/api/v1/rules": { "/api/ruler/{DatasourceUID}/api/v1/rules": {
"get": { "get": {
"description": "List rule groups", "description": "List rule groups",
"operationId": "RouteGetRulesConfig", "operationId": "RouteGetRulesConfig",
"parameters": [ "parameters": [
{ {
"description": "DatasourceID should be the numeric datasource identifier", "description": "DatasoureUID should be the datasource UID identifier",
"format": "int64",
"in": "path", "in": "path",
"name": "DatasourceID", "name": "DatasourceUID",
"required": true, "required": true,
"type": "integer" "type": "string"
}, },
{ {
"in": "query", "in": "query",
@ -5203,18 +5209,17 @@
] ]
} }
}, },
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}": { "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}": {
"delete": { "delete": {
"description": "Delete namespace", "description": "Delete namespace",
"operationId": "RouteDeleteNamespaceRulesConfig", "operationId": "RouteDeleteNamespaceRulesConfig",
"parameters": [ "parameters": [
{ {
"description": "DatasourceID should be the numeric datasource identifier", "description": "DatasoureUID should be the datasource UID identifier",
"format": "int64",
"in": "path", "in": "path",
"name": "DatasourceID", "name": "DatasourceUID",
"required": true, "required": true,
"type": "integer" "type": "string"
}, },
{ {
"in": "path", "in": "path",
@ -5240,12 +5245,11 @@
"operationId": "RouteGetNamespaceRulesConfig", "operationId": "RouteGetNamespaceRulesConfig",
"parameters": [ "parameters": [
{ {
"description": "DatasourceID should be the numeric datasource identifier", "description": "DatasoureUID should be the datasource UID identifier",
"format": "int64",
"in": "path", "in": "path",
"name": "DatasourceID", "name": "DatasourceUID",
"required": true, "required": true,
"type": "integer" "type": "string"
}, },
{ {
"in": "path", "in": "path",
@ -5278,12 +5282,11 @@
"operationId": "RoutePostNameRulesConfig", "operationId": "RoutePostNameRulesConfig",
"parameters": [ "parameters": [
{ {
"description": "DatasourceID should be the numeric datasource identifier", "description": "DatasoureUID should be the datasource UID identifier",
"format": "int64",
"in": "path", "in": "path",
"name": "DatasourceID", "name": "DatasourceUID",
"required": true, "required": true,
"type": "integer" "type": "string"
}, },
{ {
"in": "path", "in": "path",
@ -5312,18 +5315,17 @@
] ]
} }
}, },
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}": { "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}": {
"delete": { "delete": {
"description": "Delete rule group", "description": "Delete rule group",
"operationId": "RouteDeleteRuleGroupConfig", "operationId": "RouteDeleteRuleGroupConfig",
"parameters": [ "parameters": [
{ {
"description": "DatasourceID should be the numeric datasource identifier", "description": "DatasoureUID should be the datasource UID identifier",
"format": "int64",
"in": "path", "in": "path",
"name": "DatasourceID", "name": "DatasourceUID",
"required": true, "required": true,
"type": "integer" "type": "string"
}, },
{ {
"in": "path", "in": "path",
@ -5355,12 +5357,11 @@
"operationId": "RouteGetRulegGroupConfig", "operationId": "RouteGetRulegGroupConfig",
"parameters": [ "parameters": [
{ {
"description": "DatasourceID should be the numeric datasource identifier", "description": "DatasoureUID should be the datasource UID identifier",
"format": "int64",
"in": "path", "in": "path",
"name": "DatasourceID", "name": "DatasourceUID",
"required": true, "required": true,
"type": "integer" "type": "string"
}, },
{ {
"in": "path", "in": "path",

View File

@ -1501,7 +1501,7 @@
} }
} }
}, },
"/api/ruler/{DatasourceID}/api/v1/rules": { "/api/ruler/{DatasourceUID}/api/v1/rules": {
"get": { "get": {
"description": "List rule groups", "description": "List rule groups",
"produces": [ "produces": [
@ -1513,10 +1513,9 @@
"operationId": "RouteGetRulesConfig", "operationId": "RouteGetRulesConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -1542,7 +1541,7 @@
} }
} }
}, },
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}": { "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}": {
"get": { "get": {
"description": "Get rule groups by namespace", "description": "Get rule groups by namespace",
"produces": [ "produces": [
@ -1554,10 +1553,9 @@
"operationId": "RouteGetNamespaceRulesConfig", "operationId": "RouteGetNamespaceRulesConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -1589,10 +1587,9 @@
"operationId": "RoutePostNameRulesConfig", "operationId": "RoutePostNameRulesConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -1627,10 +1624,9 @@
"operationId": "RouteDeleteNamespaceRulesConfig", "operationId": "RouteDeleteNamespaceRulesConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -1651,7 +1647,7 @@
} }
} }
}, },
"/api/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}": { "/api/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}": {
"get": { "get": {
"description": "Get rule group", "description": "Get rule group",
"produces": [ "produces": [
@ -1663,10 +1659,9 @@
"operationId": "RouteGetRulegGroupConfig", "operationId": "RouteGetRulegGroupConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -1700,10 +1695,9 @@
"operationId": "RouteDeleteRuleGroupConfig", "operationId": "RouteDeleteRuleGroupConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -2922,6 +2916,9 @@
"format": "int64", "format": "int64",
"x-go-name": "OrgID" "x-go-name": "OrgID"
}, },
"provenance": {
"$ref": "#/definitions/Provenance"
},
"rule_group": { "rule_group": {
"type": "string", "type": "string",
"x-go-name": "RuleGroup" "x-go-name": "RuleGroup"
@ -5048,7 +5045,6 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models" "x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"alertGroup": { "alertGroup": {
"description": "AlertGroup alert group",
"type": "object", "type": "object",
"required": [ "required": [
"alerts", "alerts",
@ -5071,14 +5067,17 @@
"$ref": "#/definitions/receiver" "$ref": "#/definitions/receiver"
} }
}, },
"x-go-name": "AlertGroup",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/alertGroup" "$ref": "#/definitions/alertGroup"
}, },
"alertGroups": { "alertGroups": {
"description": "AlertGroups alert groups",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/alertGroup" "$ref": "#/definitions/alertGroup"
}, },
"x-go-name": "AlertGroups",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/alertGroups" "$ref": "#/definitions/alertGroups"
}, },
"alertStatus": { "alertStatus": {
@ -5199,7 +5198,6 @@
"$ref": "#/definitions/Duration" "$ref": "#/definitions/Duration"
}, },
"gettableAlert": { "gettableAlert": {
"description": "GettableAlert gettable alert",
"type": "object", "type": "object",
"required": [ "required": [
"labels", "labels",
@ -5259,6 +5257,8 @@
"x-go-name": "UpdatedAt" "x-go-name": "UpdatedAt"
} }
}, },
"x-go-name": "GettableAlert",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/gettableAlert" "$ref": "#/definitions/gettableAlert"
}, },
"gettableAlerts": { "gettableAlerts": {
@ -5326,11 +5326,12 @@
"$ref": "#/definitions/gettableSilence" "$ref": "#/definitions/gettableSilence"
}, },
"gettableSilences": { "gettableSilences": {
"description": "GettableSilences gettable silences",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/gettableSilence" "$ref": "#/definitions/gettableSilence"
}, },
"x-go-name": "GettableSilences",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/gettableSilences" "$ref": "#/definitions/gettableSilences"
}, },
"labelSet": { "labelSet": {

View File

@ -7590,7 +7590,7 @@
} }
} }
}, },
"/ruler/{DatasourceID}/api/v1/rules": { "/ruler/{DatasourceUID}/api/v1/rules": {
"get": { "get": {
"description": "List rule groups", "description": "List rule groups",
"produces": ["application/json"], "produces": ["application/json"],
@ -7598,10 +7598,9 @@
"operationId": "RouteGetRulesConfig", "operationId": "RouteGetRulesConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -7627,7 +7626,7 @@
} }
} }
}, },
"/ruler/{DatasourceID}/api/v1/rules/{Namespace}": { "/ruler/{DatasourceUID}/api/v1/rules/{Namespace}": {
"get": { "get": {
"description": "Get rule groups by namespace", "description": "Get rule groups by namespace",
"produces": ["application/json"], "produces": ["application/json"],
@ -7635,10 +7634,9 @@
"operationId": "RouteGetNamespaceRulesConfig", "operationId": "RouteGetNamespaceRulesConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -7665,10 +7663,9 @@
"operationId": "RoutePostNameRulesConfig", "operationId": "RoutePostNameRulesConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -7701,10 +7698,9 @@
"operationId": "RouteDeleteNamespaceRulesConfig", "operationId": "RouteDeleteNamespaceRulesConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -7725,7 +7721,7 @@
} }
} }
}, },
"/ruler/{DatasourceID}/api/v1/rules/{Namespace}/{Groupname}": { "/ruler/{DatasourceUID}/api/v1/rules/{Namespace}/{Groupname}": {
"get": { "get": {
"description": "Get rule group", "description": "Get rule group",
"produces": ["application/json"], "produces": ["application/json"],
@ -7733,10 +7729,9 @@
"operationId": "RouteGetRulegGroupConfig", "operationId": "RouteGetRulegGroupConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -7768,10 +7763,9 @@
"operationId": "RouteDeleteRuleGroupConfig", "operationId": "RouteDeleteRuleGroupConfig",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "string",
"format": "int64", "description": "DatasoureUID should be the datasource UID identifier",
"description": "DatasourceID should be the numeric datasource identifier", "name": "DatasourceUID",
"name": "DatasourceID",
"in": "path", "in": "path",
"required": true "required": true
}, },
@ -12629,6 +12623,9 @@
"format": "int64", "format": "int64",
"x-go-name": "OrgID" "x-go-name": "OrgID"
}, },
"provenance": {
"$ref": "#/definitions/Provenance"
},
"rule_group": { "rule_group": {
"type": "string", "type": "string",
"x-go-name": "RuleGroup" "x-go-name": "RuleGroup"
@ -17306,7 +17303,6 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models" "x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"alertGroup": { "alertGroup": {
"description": "AlertGroup alert group",
"type": "object", "type": "object",
"required": ["alerts", "labels", "receiver"], "required": ["alerts", "labels", "receiver"],
"properties": { "properties": {
@ -17324,14 +17320,17 @@
"receiver": { "receiver": {
"$ref": "#/definitions/receiver" "$ref": "#/definitions/receiver"
} }
} },
"x-go-name": "AlertGroup",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"alertGroups": { "alertGroups": {
"description": "AlertGroups alert groups",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/alertGroup" "$ref": "#/definitions/alertGroup"
} },
"x-go-name": "AlertGroups",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"alertStatus": { "alertStatus": {
"description": "AlertStatus alert status", "description": "AlertStatus alert status",
@ -17434,7 +17433,6 @@
"$ref": "#/definitions/Duration" "$ref": "#/definitions/Duration"
}, },
"gettableAlert": { "gettableAlert": {
"description": "GettableAlert gettable alert",
"type": "object", "type": "object",
"required": ["labels", "annotations", "endsAt", "fingerprint", "receivers", "startsAt", "status", "updatedAt"], "required": ["labels", "annotations", "endsAt", "fingerprint", "receivers", "startsAt", "status", "updatedAt"],
"properties": { "properties": {
@ -17484,7 +17482,9 @@
"format": "date-time", "format": "date-time",
"x-go-name": "UpdatedAt" "x-go-name": "UpdatedAt"
} }
} },
"x-go-name": "GettableAlert",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"gettableAlerts": { "gettableAlerts": {
"description": "GettableAlerts gettable alerts", "description": "GettableAlerts gettable alerts",
@ -17540,11 +17540,12 @@
} }
}, },
"gettableSilences": { "gettableSilences": {
"description": "GettableSilences gettable silences",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/gettableSilence" "$ref": "#/definitions/gettableSilence"
} },
"x-go-name": "GettableSilences",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"labelSet": { "labelSet": {
"description": "LabelSet label set", "description": "LabelSet label set",

View File

@ -1,13 +1,13 @@
import { RulerDataSourceConfig } from 'app/types/unified-alerting'; import { RulerDataSourceConfig } from 'app/types/unified-alerting';
import { getDatasourceAPIId } from '../utils/datasource'; import { getDatasourceAPIUid } from '../utils/datasource';
import { rulerUrlBuilder } from './ruler'; import { rulerUrlBuilder } from './ruler';
jest.mock('../utils/datasource'); jest.mock('../utils/datasource');
const mocks = { const mocks = {
getDatasourceAPIId: jest.mocked(getDatasourceAPIId), getDatasourceAPIUId: jest.mocked(getDatasourceAPIUid),
}; };
describe('rulerUrlBuilder', () => { describe('rulerUrlBuilder', () => {
@ -18,7 +18,7 @@ describe('rulerUrlBuilder', () => {
apiVersion: 'legacy', apiVersion: 'legacy',
}; };
mocks.getDatasourceAPIId.mockReturnValue('ds-uid'); mocks.getDatasourceAPIUId.mockReturnValue('ds-uid');
// Act // Act
const builder = rulerUrlBuilder(config); const builder = rulerUrlBuilder(config);
@ -45,7 +45,7 @@ describe('rulerUrlBuilder', () => {
apiVersion: 'config', apiVersion: 'config',
}; };
mocks.getDatasourceAPIId.mockReturnValue('ds-uid'); mocks.getDatasourceAPIUId.mockReturnValue('ds-uid');
// Act // Act
const builder = rulerUrlBuilder(config); const builder = rulerUrlBuilder(config);
@ -72,7 +72,7 @@ describe('rulerUrlBuilder', () => {
apiVersion: 'config', apiVersion: 'config',
}; };
mocks.getDatasourceAPIId.mockReturnValue('ds-uid'); mocks.getDatasourceAPIUId.mockReturnValue('ds-uid');
// Act // Act
const builder = rulerUrlBuilder(config); const builder = rulerUrlBuilder(config);
@ -94,7 +94,7 @@ describe('rulerUrlBuilder', () => {
apiVersion: 'config', apiVersion: 'config',
}; };
mocks.getDatasourceAPIId.mockReturnValue('ds-uid'); mocks.getDatasourceAPIUId.mockReturnValue('ds-uid');
// Act // Act
const builder = rulerUrlBuilder(config); const builder = rulerUrlBuilder(config);

View File

@ -5,7 +5,7 @@ import { RulerDataSourceConfig } from 'app/types/unified-alerting';
import { PostableRulerRuleGroupDTO, RulerRuleGroupDTO, RulerRulesConfigDTO } from 'app/types/unified-alerting-dto'; import { PostableRulerRuleGroupDTO, RulerRuleGroupDTO, RulerRulesConfigDTO } from 'app/types/unified-alerting-dto';
import { RULER_NOT_SUPPORTED_MSG } from '../utils/constants'; import { RULER_NOT_SUPPORTED_MSG } from '../utils/constants';
import { getDatasourceAPIId, GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource'; import { getDatasourceAPIUid, GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource';
import { prepareRulesFilterQueryParams } from './prometheus'; import { prepareRulesFilterQueryParams } from './prometheus';
@ -20,7 +20,7 @@ export interface RulerRequestUrl {
} }
export function rulerUrlBuilder(rulerConfig: RulerDataSourceConfig) { export function rulerUrlBuilder(rulerConfig: RulerDataSourceConfig) {
const grafanaServerPath = `/api/ruler/${getDatasourceAPIId(rulerConfig.dataSourceName)}`; const grafanaServerPath = `/api/ruler/${getDatasourceAPIUid(rulerConfig.dataSourceName)}`;
const rulerPath = `${grafanaServerPath}/api/v1/rules`; const rulerPath = `${grafanaServerPath}/api/v1/rules`;
const rulerSearchParams = new URLSearchParams(); const rulerSearchParams = new URLSearchParams();
@ -94,7 +94,7 @@ export async function fetchRulerRulesNamespace(rulerConfig: RulerDataSourceConfi
// will throw with { status: 404 } if rule group does not exist // will throw with { status: 404 } if rule group does not exist
export async function fetchTestRulerRulesGroup(dataSourceName: string): Promise<RulerRuleGroupDTO | null> { export async function fetchTestRulerRulesGroup(dataSourceName: string): Promise<RulerRuleGroupDTO | null> {
return rulerGetRequest<RulerRuleGroupDTO | null>( return rulerGetRequest<RulerRuleGroupDTO | null>(
`/api/ruler/${getDatasourceAPIId(dataSourceName)}/api/v1/rules/test/test`, `/api/ruler/${getDatasourceAPIUid(dataSourceName)}/api/v1/rules/test/test`,
null null
); );
} }