Merge pull request #14778 from influxdata/query_endpoint_notification_rule
feat(http): add rule query endpointpull/14964/head
commit
5e5b0ea4c1
|
@ -20,11 +20,12 @@ type NotificationRuleBackend struct {
|
|||
influxdb.HTTPErrorHandler
|
||||
Logger *zap.Logger
|
||||
|
||||
NotificationRuleStore influxdb.NotificationRuleStore
|
||||
UserResourceMappingService influxdb.UserResourceMappingService
|
||||
LabelService influxdb.LabelService
|
||||
UserService influxdb.UserService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
NotificationRuleStore influxdb.NotificationRuleStore
|
||||
NotificationEndpointService influxdb.NotificationEndpointService
|
||||
UserResourceMappingService influxdb.UserResourceMappingService
|
||||
LabelService influxdb.LabelService
|
||||
UserService influxdb.UserService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
}
|
||||
|
||||
// NewNotificationRuleBackend returns a new instance of NotificationRuleBackend.
|
||||
|
@ -33,11 +34,12 @@ func NewNotificationRuleBackend(b *APIBackend) *NotificationRuleBackend {
|
|||
HTTPErrorHandler: b.HTTPErrorHandler,
|
||||
Logger: b.Logger.With(zap.String("handler", "notification_rule")),
|
||||
|
||||
NotificationRuleStore: b.NotificationRuleStore,
|
||||
UserResourceMappingService: b.UserResourceMappingService,
|
||||
LabelService: b.LabelService,
|
||||
UserService: b.UserService,
|
||||
OrganizationService: b.OrganizationService,
|
||||
NotificationRuleStore: b.NotificationRuleStore,
|
||||
NotificationEndpointService: b.NotificationEndpointService,
|
||||
UserResourceMappingService: b.UserResourceMappingService,
|
||||
LabelService: b.LabelService,
|
||||
UserService: b.UserService,
|
||||
OrganizationService: b.OrganizationService,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,16 +49,18 @@ type NotificationRuleHandler struct {
|
|||
influxdb.HTTPErrorHandler
|
||||
Logger *zap.Logger
|
||||
|
||||
NotificationRuleStore influxdb.NotificationRuleStore
|
||||
UserResourceMappingService influxdb.UserResourceMappingService
|
||||
LabelService influxdb.LabelService
|
||||
UserService influxdb.UserService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
NotificationRuleStore influxdb.NotificationRuleStore
|
||||
NotificationEndpointService influxdb.NotificationEndpointService
|
||||
UserResourceMappingService influxdb.UserResourceMappingService
|
||||
LabelService influxdb.LabelService
|
||||
UserService influxdb.UserService
|
||||
OrganizationService influxdb.OrganizationService
|
||||
}
|
||||
|
||||
const (
|
||||
notificationRulesPath = "/api/v2/notificationRules"
|
||||
notificationRulesIDPath = "/api/v2/notificationRules/:id"
|
||||
notificationRulesIDQueryPath = "/api/v2/notificationRules/:id/query"
|
||||
notificationRulesIDMembersPath = "/api/v2/notificationRules/:id/members"
|
||||
notificationRulesIDMembersIDPath = "/api/v2/notificationRules/:id/members/:userID"
|
||||
notificationRulesIDOwnersPath = "/api/v2/notificationRules/:id/owners"
|
||||
|
@ -72,15 +76,17 @@ func NewNotificationRuleHandler(b *NotificationRuleBackend) *NotificationRuleHan
|
|||
HTTPErrorHandler: b.HTTPErrorHandler,
|
||||
Logger: b.Logger,
|
||||
|
||||
NotificationRuleStore: b.NotificationRuleStore,
|
||||
UserResourceMappingService: b.UserResourceMappingService,
|
||||
LabelService: b.LabelService,
|
||||
UserService: b.UserService,
|
||||
OrganizationService: b.OrganizationService,
|
||||
NotificationRuleStore: b.NotificationRuleStore,
|
||||
NotificationEndpointService: b.NotificationEndpointService,
|
||||
UserResourceMappingService: b.UserResourceMappingService,
|
||||
LabelService: b.LabelService,
|
||||
UserService: b.UserService,
|
||||
OrganizationService: b.OrganizationService,
|
||||
}
|
||||
h.HandlerFunc("POST", notificationRulesPath, h.handlePostNotificationRule)
|
||||
h.HandlerFunc("GET", notificationRulesPath, h.handleGetNotificationRules)
|
||||
h.HandlerFunc("GET", notificationRulesIDPath, h.handleGetNotificationRule)
|
||||
h.HandlerFunc("GET", notificationRulesIDQueryPath, h.handleGetNotificationRuleQuery)
|
||||
h.HandlerFunc("DELETE", notificationRulesIDPath, h.handleDeleteNotificationRule)
|
||||
h.HandlerFunc("PUT", notificationRulesIDPath, h.handlePutNotificationRule)
|
||||
h.HandlerFunc("PATCH", notificationRulesIDPath, h.handlePatchNotificationRule)
|
||||
|
@ -230,6 +236,39 @@ func (h *NotificationRuleHandler) handleGetNotificationRules(w http.ResponseWrit
|
|||
}
|
||||
}
|
||||
|
||||
func (h *NotificationRuleHandler) handleGetNotificationRuleQuery(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
id, err := decodeGetNotificationRuleRequest(ctx, r)
|
||||
if err != nil {
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
return
|
||||
}
|
||||
nr, err := h.NotificationRuleStore.FindNotificationRuleByID(ctx, id)
|
||||
if err != nil {
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
return
|
||||
}
|
||||
edp, err := h.NotificationEndpointService.FindNotificationEndpointByID(ctx, nr.GetEndpointID())
|
||||
if err != nil {
|
||||
h.HandleHTTPError(ctx, &influxdb.Error{
|
||||
Code: influxdb.EInternal,
|
||||
Op: "http/handleGetNotificationRuleQuery",
|
||||
Err: err,
|
||||
}, w)
|
||||
return
|
||||
}
|
||||
flux, err := nr.GenerateFlux(edp)
|
||||
if err != nil {
|
||||
h.HandleHTTPError(ctx, err, w)
|
||||
return
|
||||
}
|
||||
h.Logger.Debug("notification rule query retrieved", zap.String("notificationRuleQuery", fmt.Sprint(flux)))
|
||||
if err := encodeResponse(ctx, w, http.StatusOK, newFluxResponse(flux)); err != nil {
|
||||
logEncodingError(h.Logger, r, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (h *NotificationRuleHandler) handleGetNotificationRule(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
h.Logger.Debug("notification rule retrieve request", zap.String("r", fmt.Sprint(r)))
|
||||
|
|
|
@ -5691,6 +5691,45 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
'/notificationRules/{ruleID}/query':
|
||||
get:
|
||||
operationId: GetNotificationRulesIDQuery
|
||||
tags:
|
||||
- Rules
|
||||
summary: Get a notification rule query
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/TraceSpan'
|
||||
- in: path
|
||||
name: ruleID
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: ID of notification rule
|
||||
responses:
|
||||
'200':
|
||||
description: the notification rule query requested
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/FluxResponse"
|
||||
'400':
|
||||
description: invalid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
'404':
|
||||
description: notification rule not found
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/notificationEndpoints:
|
||||
get:
|
||||
operationId: GetNotificationEndpoints
|
||||
|
|
Loading…
Reference in New Issue