diff --git a/docs/sources/developers/http_api/annotations.md b/docs/sources/developers/http_api/annotations.md index 99c6a86195c..c0cd017b6b7 100644 --- a/docs/sources/developers/http_api/annotations.md +++ b/docs/sources/developers/http_api/annotations.md @@ -48,6 +48,7 @@ Query Parameters: - `limit`: number. Optional - default is 100. Max limit for results returned. - `alertId`: number. Optional. Find annotations for a specified alert. - `dashboardId`: number. Optional. Find annotations that are scoped to a specific dashboard +- `dashboardUID`: string. Optional. Find annotations that are scoped to a specific dashboard, when dashboardUID presents, dashboardId would be ignored. - `panelId`: number. Optional. Find annotations that are scoped to a specific panel - `userId`: number. Optional. Find annotations created by a specific user - `type`: string. Optional. `alert`|`annotation` Return alerts or user created annotations diff --git a/pkg/api/annotations.go b/pkg/api/annotations.go index 894f4382ead..5a44ebbc4fa 100644 --- a/pkg/api/annotations.go +++ b/pkg/api/annotations.go @@ -26,6 +26,7 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response { UserId: c.QueryInt64("userId"), AlertId: c.QueryInt64("alertId"), DashboardId: c.QueryInt64("dashboardId"), + DashboardUid: c.Query("dashboardUID"), PanelId: c.QueryInt64("panelId"), Limit: c.QueryInt64("limit"), Tags: c.QueryStrings("tags"), @@ -34,6 +35,16 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response { SignedInUser: c.SignedInUser, } + // When dashboard UID present in the request, we ignore dashboard ID + if query.DashboardUid != "" { + dq := models.GetDashboardQuery{Uid: query.DashboardUid, OrgId: c.OrgId} + err := hs.DashboardService.GetDashboard(c.Req.Context(), &dq) + if err != nil { + return response.Error(http.StatusBadRequest, "Invalid dashboard UID in the request", err) + } + query.DashboardId = dq.Id + } + repo := annotations.GetRepository() items, err := repo.Find(c.Req.Context(), query) diff --git a/pkg/api/docs/definitions/annotations.go b/pkg/api/docs/definitions/annotations.go index b7fa844daf0..4906a012381 100644 --- a/pkg/api/docs/definitions/annotations.go +++ b/pkg/api/docs/definitions/annotations.go @@ -149,6 +149,10 @@ type GetAnnotationsParams struct { // in:query // required:false DashboardID int64 `json:"dashboardId"` + // Find annotations that are scoped to a specific dashboard + // in:query + // required:false + DashboardUID string `json:"dashboardUID"` // Find annotations that are scoped to a specific panel // in:query // required:false diff --git a/pkg/services/annotations/annotations.go b/pkg/services/annotations/annotations.go index 60130735b29..4e1f07f2d75 100644 --- a/pkg/services/annotations/annotations.go +++ b/pkg/services/annotations/annotations.go @@ -33,6 +33,7 @@ type ItemQuery struct { UserId int64 `json:"userId"` AlertId int64 `json:"alertId"` DashboardId int64 `json:"dashboardId"` + DashboardUid string `json:"dashboardUID"` PanelId int64 `json:"panelId"` AnnotationId int64 `json:"annotationId"` Tags []string `json:"tags"` diff --git a/public/api-merged.json b/public/api-merged.json index cf805d740b3..b607a3b2630 100644 --- a/public/api-merged.json +++ b/public/api-merged.json @@ -2018,6 +2018,12 @@ "name": "dashboardId", "in": "query" }, + { + "type": "string", + "description": "Find annotations that are scoped to a specific dashboard", + "name": "dashboardUID", + "in": "query" + }, { "type": "integer", "format": "int64", diff --git a/public/api-spec.json b/public/api-spec.json index d5f8ac0f284..bfb1de36b1f 100644 --- a/public/api-spec.json +++ b/public/api-spec.json @@ -2018,6 +2018,12 @@ "name": "dashboardId", "in": "query" }, + { + "type": "string", + "description": "Find annotations that are scoped to a specific dashboard", + "name": "dashboardUID", + "in": "query" + }, { "type": "integer", "format": "int64",