Alerting: modify prometheus endpoints for proxying using the datasource UID (#48052)

* Modify prometheus endpoints to expect the data source UID

* Update frontend
This commit is contained in:
Sofia Papagiannaki 2022-05-06 22:05:02 +03:00 committed by GitHub
parent 30d9cc81ec
commit bb66c03f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 73 additions and 92 deletions

View File

@ -88,8 +88,8 @@ func (api *API) authorize(method, path string) web.Handler {
eval = ac.EvalPermission(ac.ActionAlertingInstancesExternalWrite, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID"))) 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/{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")))
// Lotex Rules testing // Lotex Rules testing
case http.MethodPost + "/api/v1/rule/test/{DatasourceID}": case http.MethodPost + "/api/v1/rule/test/{DatasourceID}":
@ -140,8 +140,8 @@ func (api *API) authorize(method, path string) web.Handler {
eval = ac.EvalPermission(ac.ActionAlertingInstancesExternalWrite, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID"))) eval = ac.EvalPermission(ac.ActionAlertingInstancesExternalWrite, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID")))
// Prometheus-compatible Paths // Prometheus-compatible Paths
case http.MethodGet + "/api/prometheus/{DatasourceID}/api/v1/alerts": case http.MethodGet + "/api/prometheus/{DatasourceUID}/api/v1/alerts":
eval = ac.EvalPermission(ac.ActionAlertingInstancesExternalRead, datasources.ScopeProvider.GetResourceScope(ac.Parameter(":DatasourceID"))) eval = ac.EvalPermission(ac.ActionAlertingInstancesExternalRead, datasources.ScopeProvider.GetResourceScopeUID(ac.Parameter(":DatasourceUID")))
// Notification Policies, Contact Points and Templates // Notification Policies, Contact Points and Templates

View File

@ -25,7 +25,7 @@ func NewForkedProm(datasourceCache datasources.CacheService, proxy *LotexProm, g
} }
func (f *ForkedPrometheusApi) forkRouteGetAlertStatuses(ctx *models.ReqContext) response.Response { func (f *ForkedPrometheusApi) forkRouteGetAlertStatuses(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 *ForkedPrometheusApi) forkRouteGetAlertStatuses(ctx *models.ReqContext)
} }
func (f *ForkedPrometheusApi) forkRouteGetRuleStatuses(ctx *models.ReqContext) response.Response { func (f *ForkedPrometheusApi) forkRouteGetRuleStatuses(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, "")
} }

View File

@ -43,11 +43,11 @@ func (f *ForkedPrometheusApi) RouteGetRuleStatuses(ctx *models.ReqContext) respo
func (api *API) RegisterPrometheusApiEndpoints(srv PrometheusApiForkingService, m *metrics.API) { func (api *API) RegisterPrometheusApiEndpoints(srv PrometheusApiForkingService, m *metrics.API) {
api.RouteRegister.Group("", func(group routing.RouteRegister) { api.RouteRegister.Group("", func(group routing.RouteRegister) {
group.Get( group.Get(
toMacaronPath("/api/prometheus/{DatasourceID}/api/v1/alerts"), toMacaronPath("/api/prometheus/{DatasourceUID}/api/v1/alerts"),
api.authorize(http.MethodGet, "/api/prometheus/{DatasourceID}/api/v1/alerts"), api.authorize(http.MethodGet, "/api/prometheus/{DatasourceUID}/api/v1/alerts"),
metrics.Instrument( metrics.Instrument(
http.MethodGet, http.MethodGet,
"/api/prometheus/{DatasourceID}/api/v1/alerts", "/api/prometheus/{DatasourceUID}/api/v1/alerts",
srv.RouteGetAlertStatuses, srv.RouteGetAlertStatuses,
m, m,
), ),
@ -73,11 +73,11 @@ func (api *API) RegisterPrometheusApiEndpoints(srv PrometheusApiForkingService,
), ),
) )
group.Get( group.Get(
toMacaronPath("/api/prometheus/{DatasourceID}/api/v1/rules"), toMacaronPath("/api/prometheus/{DatasourceUID}/api/v1/rules"),
api.authorize(http.MethodGet, "/api/prometheus/{DatasourceID}/api/v1/rules"), api.authorize(http.MethodGet, "/api/prometheus/{DatasourceUID}/api/v1/rules"),
metrics.Instrument( metrics.Instrument(
http.MethodGet, http.MethodGet,
"/api/prometheus/{DatasourceID}/api/v1/rules", "/api/prometheus/{DatasourceUID}/api/v1/rules",
srv.RouteGetRuleStatuses, srv.RouteGetRuleStatuses,
m, m,
), ),

View File

@ -3,7 +3,6 @@ package api
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"strconv"
"github.com/grafana/grafana/pkg/api/response" "github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
@ -78,12 +77,12 @@ func (p *LotexProm) RouteGetRuleStatuses(ctx *models.ReqContext) response.Respon
} }
func (p *LotexProm) getEndpoints(ctx *models.ReqContext) (*promEndpoints, error) { func (p *LotexProm) getEndpoints(ctx *models.ReqContext) (*promEndpoints, error) {
datasourceID, err := strconv.ParseInt(web.Params(ctx.Req)[":DatasourceID"], 10, 64) datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
if err != nil { if datasourceUID == "" {
return nil, fmt.Errorf("datasource ID is invalid") return nil, fmt.Errorf("datasource UID is invalid")
} }
ds, err := p.DataProxy.DataSourceCache.GetDatasource(ctx.Req.Context(), datasourceID, ctx.SignedInUser, ctx.SkipCache) ds, err := p.DataProxy.DataSourceCache.GetDatasourceByUID(ctx.Req.Context(), datasourceUID, ctx.SignedInUser, ctx.SkipCache)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -438,8 +438,6 @@ type BodyAlertingConfig struct {
Body PostableUserConfig Body PostableUserConfig
} }
// prom routes
// swagger:parameters RouteGetRuleStatuses RouteGetAlertStatuses
// testing routes // testing routes
// swagger:parameters RouteTestReceiverConfig RouteTestRuleConfig // swagger:parameters RouteTestReceiverConfig RouteTestRuleConfig
type DatasourceIDReference struct { type DatasourceIDReference struct {
@ -450,6 +448,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
// prom routes
// swagger:parameters RouteGetRuleStatuses RouteGetAlertStatuses
// ruler routes // ruler routes
// swagger:parameters RouteGetRulesConfig RoutePostNameRulesConfig RouteGetNamespaceRulesConfig RouteDeleteNamespaceRulesConfig RouteGetRulegGroupConfig RouteDeleteRuleGroupConfig // swagger:parameters RouteGetRulesConfig RoutePostNameRulesConfig RouteGetNamespaceRulesConfig RouteDeleteNamespaceRulesConfig RouteGetRulegGroupConfig RouteDeleteRuleGroupConfig
type DatasourceUIDReference struct { type DatasourceUIDReference struct {

View File

@ -13,7 +13,7 @@ import (
// Responses: // Responses:
// 200: RuleResponse // 200: RuleResponse
// swagger:route GET /api/prometheus/{DatasourceID}/api/v1/rules prometheus RouteGetRuleStatuses // swagger:route GET /api/prometheus/{DatasourceUID}/api/v1/rules prometheus RouteGetRuleStatuses
// //
// gets the evaluation statuses of all rules // gets the evaluation statuses of all rules
// //
@ -27,7 +27,7 @@ import (
// Responses: // Responses:
// 200: AlertResponse // 200: AlertResponse
// swagger:route GET /api/prometheus/{DatasourceID}/api/v1/alerts prometheus RouteGetAlertStatuses // swagger:route GET /api/prometheus/{DatasourceUID}/api/v1/alerts prometheus RouteGetAlertStatuses
// //
// gets the current alerts // gets the current alerts
// //

View File

@ -2883,7 +2883,6 @@
"x-go-package": "github.com/prometheus/alertmanager/timeinterval" "x-go-package": "github.com/prometheus/alertmanager/timeinterval"
}, },
"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 RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.",
"properties": { "properties": {
"ForceQuery": { "ForceQuery": {
"type": "boolean" "type": "boolean"
@ -2916,9 +2915,9 @@
"$ref": "#/definitions/Userinfo" "$ref": "#/definitions/Userinfo"
} }
}, },
"title": "A URL represents a parsed URL (technically, a URI reference).", "title": "URL is a custom URL type that allows validation at configuration load time.",
"type": "object", "type": "object",
"x-go-package": "net/url" "x-go-package": "github.com/prometheus/common/config"
}, },
"Userinfo": { "Userinfo": {
"description": "The Userinfo type is an immutable encapsulation of username and\npassword details for a URL. An existing Userinfo value is guaranteed\nto have a username set (potentially empty, as allowed by RFC 2396),\nand optionally a password.", "description": "The Userinfo type is an immutable encapsulation of username and\npassword details for a URL. An existing Userinfo value is guaranteed\nto have a username set (potentially empty, as allowed by RFC 2396),\nand optionally a password.",
@ -3115,7 +3114,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",
@ -3137,7 +3135,9 @@
"labels", "labels",
"receiver" "receiver"
], ],
"type": "object" "type": "object",
"x-go-name": "AlertGroup",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"alertGroups": { "alertGroups": {
"items": { "items": {
@ -3328,11 +3328,12 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models" "x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"gettableAlerts": { "gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"items": { "items": {
"$ref": "#/definitions/gettableAlert" "$ref": "#/definitions/gettableAlert"
}, },
"type": "array" "type": "array",
"x-go-name": "GettableAlerts",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"gettableSilence": { "gettableSilence": {
"description": "GettableSilence gettable silence", "description": "GettableSilence gettable silence",
@ -3524,7 +3525,6 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models" "x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"postableSilence": { "postableSilence": {
"description": "PostableSilence postable silence",
"properties": { "properties": {
"comment": { "comment": {
"description": "comment", "description": "comment",
@ -3564,7 +3564,9 @@
"matchers", "matchers",
"startsAt" "startsAt"
], ],
"type": "object" "type": "object",
"x-go-name": "PostableSilence",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"receiver": { "receiver": {
"description": "Receiver receiver", "description": "Receiver receiver",
@ -4745,18 +4747,17 @@
] ]
} }
}, },
"/api/prometheus/{DatasourceID}/api/v1/alerts": { "/api/prometheus/{DatasourceUID}/api/v1/alerts": {
"get": { "get": {
"description": "gets the current alerts", "description": "gets the current alerts",
"operationId": "RouteGetAlertStatuses", "operationId": "RouteGetAlertStatuses",
"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"
} }
], ],
"responses": { "responses": {
@ -4772,18 +4773,17 @@
] ]
} }
}, },
"/api/prometheus/{DatasourceID}/api/v1/rules": { "/api/prometheus/{DatasourceUID}/api/v1/rules": {
"get": { "get": {
"description": "gets the evaluation statuses of all rules", "description": "gets the evaluation statuses of all rules",
"operationId": "RouteGetRuleStatuses", "operationId": "RouteGetRuleStatuses",
"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"
} }
], ],
"responses": { "responses": {

View File

@ -1070,7 +1070,7 @@
} }
} }
}, },
"/api/prometheus/{DatasourceID}/api/v1/alerts": { "/api/prometheus/{DatasourceUID}/api/v1/alerts": {
"get": { "get": {
"description": "gets the current alerts", "description": "gets the current alerts",
"tags": [ "tags": [
@ -1079,10 +1079,9 @@
"operationId": "RouteGetAlertStatuses", "operationId": "RouteGetAlertStatuses",
"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
} }
@ -1097,7 +1096,7 @@
} }
} }
}, },
"/api/prometheus/{DatasourceID}/api/v1/rules": { "/api/prometheus/{DatasourceUID}/api/v1/rules": {
"get": { "get": {
"description": "gets the evaluation statuses of all rules", "description": "gets the evaluation statuses of all rules",
"tags": [ "tags": [
@ -1106,10 +1105,9 @@
"operationId": "RouteGetRuleStatuses", "operationId": "RouteGetRuleStatuses",
"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
} }
@ -4864,9 +4862,8 @@
"x-go-package": "github.com/prometheus/alertmanager/timeinterval" "x-go-package": "github.com/prometheus/alertmanager/timeinterval"
}, },
"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 RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.",
"type": "object", "type": "object",
"title": "A URL represents a parsed URL (technically, a URI reference).", "title": "URL is a custom URL type that allows validation at configuration load time.",
"properties": { "properties": {
"ForceQuery": { "ForceQuery": {
"type": "boolean" "type": "boolean"
@ -4899,7 +4896,7 @@
"$ref": "#/definitions/Userinfo" "$ref": "#/definitions/Userinfo"
} }
}, },
"x-go-package": "net/url" "x-go-package": "github.com/prometheus/common/config"
}, },
"Userinfo": { "Userinfo": {
"description": "The Userinfo type is an immutable encapsulation of username and\npassword details for a URL. An existing Userinfo value is guaranteed\nto have a username set (potentially empty, as allowed by RFC 2396),\nand optionally a password.", "description": "The Userinfo type is an immutable encapsulation of username and\npassword details for a URL. An existing Userinfo value is guaranteed\nto have a username set (potentially empty, as allowed by RFC 2396),\nand optionally a password.",
@ -5096,7 +5093,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",
@ -5119,6 +5115,8 @@
"$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": {
@ -5312,11 +5310,12 @@
"$ref": "#/definitions/gettableAlert" "$ref": "#/definitions/gettableAlert"
}, },
"gettableAlerts": { "gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/gettableAlert" "$ref": "#/definitions/gettableAlert"
}, },
"x-go-name": "GettableAlerts",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/gettableAlerts" "$ref": "#/definitions/gettableAlerts"
}, },
"gettableSilence": { "gettableSilence": {
@ -5511,7 +5510,6 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models" "x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"postableSilence": { "postableSilence": {
"description": "PostableSilence postable silence",
"type": "object", "type": "object",
"required": [ "required": [
"comment", "comment",
@ -5552,6 +5550,8 @@
"x-go-name": "StartsAt" "x-go-name": "StartsAt"
} }
}, },
"x-go-name": "PostableSilence",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/postableSilence" "$ref": "#/definitions/postableSilence"
}, },
"receiver": { "receiver": {

View File

@ -35,23 +35,6 @@ func toMacaronPath(path string) string {
})) }))
} }
func backendType(ctx *models.ReqContext, cache datasources.CacheService) (apimodels.Backend, error) {
datasourceID := web.Params(ctx.Req)[":DatasourceID"]
if datasourceID, err := strconv.ParseInt(datasourceID, 10, 64); err == nil {
if ds, err := cache.GetDatasource(ctx.Req.Context(), datasourceID, ctx.SignedInUser, ctx.SkipCache); err == nil {
switch ds.Type {
case "loki", "prometheus":
return apimodels.LoTexRulerBackend, nil
case "alertmanager":
return apimodels.AlertmanagerBackend, nil
default:
return 0, fmt.Errorf("unexpected backend type (%v)", ds.Type)
}
}
}
return 0, fmt.Errorf("unexpected backend type (%v)", datasourceID)
}
func backendTypeByUID(ctx *models.ReqContext, cache datasources.CacheService) (apimodels.Backend, error) { func backendTypeByUID(ctx *models.ReqContext, cache datasources.CacheService) (apimodels.Backend, error) {
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"] datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
if ds, err := cache.GetDatasourceByUID(ctx.Req.Context(), datasourceUID, ctx.SignedInUser, ctx.SkipCache); err == nil { if ds, err := cache.GetDatasourceByUID(ctx.Req.Context(), datasourceUID, ctx.SignedInUser, ctx.SkipCache); err == nil {

View File

@ -6620,17 +6620,16 @@
} }
} }
}, },
"/prometheus/{DatasourceID}/api/v1/alerts": { "/prometheus/{DatasourceUID}/api/v1/alerts": {
"get": { "get": {
"description": "gets the current alerts", "description": "gets the current alerts",
"tags": ["prometheus"], "tags": ["prometheus"],
"operationId": "RouteGetAlertStatuses", "operationId": "RouteGetAlertStatuses",
"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
} }
@ -6645,17 +6644,16 @@
} }
} }
}, },
"/prometheus/{DatasourceID}/api/v1/rules": { "/prometheus/{DatasourceUID}/api/v1/rules": {
"get": { "get": {
"description": "gets the evaluation statuses of all rules", "description": "gets the evaluation statuses of all rules",
"tags": ["prometheus"], "tags": ["prometheus"],
"operationId": "RouteGetRuleStatuses", "operationId": "RouteGetRuleStatuses",
"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
} }
@ -16375,9 +16373,8 @@
"x-go-package": "github.com/grafana/grafana/pkg/api/dtos" "x-go-package": "github.com/grafana/grafana/pkg/api/dtos"
}, },
"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 RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.",
"type": "object", "type": "object",
"title": "A URL represents a parsed URL (technically, a URI reference).", "title": "URL is a custom URL type that allows validation at configuration load time.",
"properties": { "properties": {
"ForceQuery": { "ForceQuery": {
"type": "boolean" "type": "boolean"
@ -16410,7 +16407,7 @@
"$ref": "#/definitions/Userinfo" "$ref": "#/definitions/Userinfo"
} }
}, },
"x-go-package": "net/url" "x-go-package": "github.com/prometheus/common/config"
}, },
"UpdateAlertNotificationCommand": { "UpdateAlertNotificationCommand": {
"type": "object", "type": "object",
@ -17487,11 +17484,12 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models" "x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"gettableAlerts": { "gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/gettableAlert" "$ref": "#/definitions/gettableAlert"
} },
"x-go-name": "GettableAlerts",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"gettableSilence": { "gettableSilence": {
"description": "GettableSilence gettable silence", "description": "GettableSilence gettable silence",
@ -17665,7 +17663,6 @@
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models" "x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"postableSilence": { "postableSilence": {
"description": "PostableSilence postable silence",
"type": "object", "type": "object",
"required": ["comment", "createdBy", "endsAt", "matchers", "startsAt"], "required": ["comment", "createdBy", "endsAt", "matchers", "startsAt"],
"properties": { "properties": {
@ -17699,7 +17696,9 @@
"format": "date-time", "format": "date-time",
"x-go-name": "StartsAt" "x-go-name": "StartsAt"
} }
} },
"x-go-name": "PostableSilence",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models"
}, },
"receiver": { "receiver": {
"type": "object", "type": "object",

View File

@ -4,7 +4,7 @@ import { getBackendSrv } from '@grafana/runtime';
import { RuleNamespace } from 'app/types/unified-alerting'; import { RuleNamespace } from 'app/types/unified-alerting';
import { PromRulesResponse } from 'app/types/unified-alerting-dto'; import { PromRulesResponse } from 'app/types/unified-alerting-dto';
import { getDatasourceAPIId, GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource'; import { getDatasourceAPIUid, GRAFANA_RULES_SOURCE_NAME } from '../utils/datasource';
export interface FetchPromRulesFilter { export interface FetchPromRulesFilter {
dashboardUID: string; dashboardUID: string;
@ -24,7 +24,7 @@ export function prometheusUrlBuilder(dataSourceConfig: PrometheusDataSourceConfi
const params = prepareRulesFilterQueryParams(searchParams, filter); const params = prepareRulesFilterQueryParams(searchParams, filter);
return { return {
url: `/api/prometheus/${getDatasourceAPIId(dataSourceName)}/api/v1/rules`, url: `/api/prometheus/${getDatasourceAPIUid(dataSourceName)}/api/v1/rules`,
params: params, params: params,
}; };
}, },