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
|
influxdb.HTTPErrorHandler
|
||||||
Logger *zap.Logger
|
Logger *zap.Logger
|
||||||
|
|
||||||
NotificationRuleStore influxdb.NotificationRuleStore
|
NotificationRuleStore influxdb.NotificationRuleStore
|
||||||
UserResourceMappingService influxdb.UserResourceMappingService
|
NotificationEndpointService influxdb.NotificationEndpointService
|
||||||
LabelService influxdb.LabelService
|
UserResourceMappingService influxdb.UserResourceMappingService
|
||||||
UserService influxdb.UserService
|
LabelService influxdb.LabelService
|
||||||
OrganizationService influxdb.OrganizationService
|
UserService influxdb.UserService
|
||||||
|
OrganizationService influxdb.OrganizationService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNotificationRuleBackend returns a new instance of NotificationRuleBackend.
|
// NewNotificationRuleBackend returns a new instance of NotificationRuleBackend.
|
||||||
|
@ -33,11 +34,12 @@ func NewNotificationRuleBackend(b *APIBackend) *NotificationRuleBackend {
|
||||||
HTTPErrorHandler: b.HTTPErrorHandler,
|
HTTPErrorHandler: b.HTTPErrorHandler,
|
||||||
Logger: b.Logger.With(zap.String("handler", "notification_rule")),
|
Logger: b.Logger.With(zap.String("handler", "notification_rule")),
|
||||||
|
|
||||||
NotificationRuleStore: b.NotificationRuleStore,
|
NotificationRuleStore: b.NotificationRuleStore,
|
||||||
UserResourceMappingService: b.UserResourceMappingService,
|
NotificationEndpointService: b.NotificationEndpointService,
|
||||||
LabelService: b.LabelService,
|
UserResourceMappingService: b.UserResourceMappingService,
|
||||||
UserService: b.UserService,
|
LabelService: b.LabelService,
|
||||||
OrganizationService: b.OrganizationService,
|
UserService: b.UserService,
|
||||||
|
OrganizationService: b.OrganizationService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,16 +49,18 @@ type NotificationRuleHandler struct {
|
||||||
influxdb.HTTPErrorHandler
|
influxdb.HTTPErrorHandler
|
||||||
Logger *zap.Logger
|
Logger *zap.Logger
|
||||||
|
|
||||||
NotificationRuleStore influxdb.NotificationRuleStore
|
NotificationRuleStore influxdb.NotificationRuleStore
|
||||||
UserResourceMappingService influxdb.UserResourceMappingService
|
NotificationEndpointService influxdb.NotificationEndpointService
|
||||||
LabelService influxdb.LabelService
|
UserResourceMappingService influxdb.UserResourceMappingService
|
||||||
UserService influxdb.UserService
|
LabelService influxdb.LabelService
|
||||||
OrganizationService influxdb.OrganizationService
|
UserService influxdb.UserService
|
||||||
|
OrganizationService influxdb.OrganizationService
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
notificationRulesPath = "/api/v2/notificationRules"
|
notificationRulesPath = "/api/v2/notificationRules"
|
||||||
notificationRulesIDPath = "/api/v2/notificationRules/:id"
|
notificationRulesIDPath = "/api/v2/notificationRules/:id"
|
||||||
|
notificationRulesIDQueryPath = "/api/v2/notificationRules/:id/query"
|
||||||
notificationRulesIDMembersPath = "/api/v2/notificationRules/:id/members"
|
notificationRulesIDMembersPath = "/api/v2/notificationRules/:id/members"
|
||||||
notificationRulesIDMembersIDPath = "/api/v2/notificationRules/:id/members/:userID"
|
notificationRulesIDMembersIDPath = "/api/v2/notificationRules/:id/members/:userID"
|
||||||
notificationRulesIDOwnersPath = "/api/v2/notificationRules/:id/owners"
|
notificationRulesIDOwnersPath = "/api/v2/notificationRules/:id/owners"
|
||||||
|
@ -72,15 +76,17 @@ func NewNotificationRuleHandler(b *NotificationRuleBackend) *NotificationRuleHan
|
||||||
HTTPErrorHandler: b.HTTPErrorHandler,
|
HTTPErrorHandler: b.HTTPErrorHandler,
|
||||||
Logger: b.Logger,
|
Logger: b.Logger,
|
||||||
|
|
||||||
NotificationRuleStore: b.NotificationRuleStore,
|
NotificationRuleStore: b.NotificationRuleStore,
|
||||||
UserResourceMappingService: b.UserResourceMappingService,
|
NotificationEndpointService: b.NotificationEndpointService,
|
||||||
LabelService: b.LabelService,
|
UserResourceMappingService: b.UserResourceMappingService,
|
||||||
UserService: b.UserService,
|
LabelService: b.LabelService,
|
||||||
OrganizationService: b.OrganizationService,
|
UserService: b.UserService,
|
||||||
|
OrganizationService: b.OrganizationService,
|
||||||
}
|
}
|
||||||
h.HandlerFunc("POST", notificationRulesPath, h.handlePostNotificationRule)
|
h.HandlerFunc("POST", notificationRulesPath, h.handlePostNotificationRule)
|
||||||
h.HandlerFunc("GET", notificationRulesPath, h.handleGetNotificationRules)
|
h.HandlerFunc("GET", notificationRulesPath, h.handleGetNotificationRules)
|
||||||
h.HandlerFunc("GET", notificationRulesIDPath, h.handleGetNotificationRule)
|
h.HandlerFunc("GET", notificationRulesIDPath, h.handleGetNotificationRule)
|
||||||
|
h.HandlerFunc("GET", notificationRulesIDQueryPath, h.handleGetNotificationRuleQuery)
|
||||||
h.HandlerFunc("DELETE", notificationRulesIDPath, h.handleDeleteNotificationRule)
|
h.HandlerFunc("DELETE", notificationRulesIDPath, h.handleDeleteNotificationRule)
|
||||||
h.HandlerFunc("PUT", notificationRulesIDPath, h.handlePutNotificationRule)
|
h.HandlerFunc("PUT", notificationRulesIDPath, h.handlePutNotificationRule)
|
||||||
h.HandlerFunc("PATCH", notificationRulesIDPath, h.handlePatchNotificationRule)
|
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) {
|
func (h *NotificationRuleHandler) handleGetNotificationRule(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
h.Logger.Debug("notification rule retrieve request", zap.String("r", fmt.Sprint(r)))
|
h.Logger.Debug("notification rule retrieve request", zap.String("r", fmt.Sprint(r)))
|
||||||
|
|
|
@ -5691,6 +5691,45 @@ paths:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/Error"
|
$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:
|
/notificationEndpoints:
|
||||||
get:
|
get:
|
||||||
operationId: GetNotificationEndpoints
|
operationId: GetNotificationEndpoints
|
||||||
|
|
Loading…
Reference in New Issue