influxdb/check.go

145 lines
3.3 KiB
Go
Raw Normal View History

2019-07-19 09:42:01 +00:00
package influxdb
import (
"context"
"encoding/json"
)
// consts for checks config.
const (
CheckDefaultPageSize = 100
CheckMaxPageSize = 500
)
// Check represents the information required to generate a periodic check task.
type Check interface {
Valid(lang FluxLanguageService) error
2019-07-19 09:42:01 +00:00
Type() string
feat(checks): add first pass at creating tasks from checks First pass at flux AST generation from check Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): format call expression Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): cleanup CheckDefinition Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): clean up threshold functions Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): clean up message function Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): misc fixes Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): remove dead code Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): move threshold flux generation to check pkg Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): move base ast generation to its own package Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> fix(notification/check): add comment for GenerateFluxAST Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> docs(notification/flux): add comments to each exported function Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> feat(notification/check): add tests for GenerateFlux Co-authored-by: Michael Desa <mjdesa@gmail.com> Co-authored-by: Deniz Kusefoglu <deniz@influxdata.com> feat(notification/check): add task options to generated flux fix(notification/check): use flux compatible duration type test(notification/check): add task option to task definition test(http): use check Duration in checks http handlers feat(check): add TaskID to checks base fix(notification/check): hack around issue with formatting ast package wtih multiple files test(check): create task when check is created A lot of little changes had to happen as a result of this. This change was rather painful. feat(checks): add update and delete of task for check fix(notifications/check): hack around the alerts package not being available test(kv): temporarily skip check tests while we merge the pr above
2019-08-07 22:34:07 +00:00
ClearPrivateData()
SetTaskID(ID)
GetTaskID() ID
GetOwnerID() ID
SetOwnerID(ID)
GenerateFlux(lang FluxLanguageService) (string, error)
2019-07-19 09:42:01 +00:00
json.Marshaler
2019-09-18 20:19:51 +00:00
CRUDLogSetter
SetID(id ID)
SetOrgID(id ID)
SetName(name string)
SetDescription(description string)
GetID() ID
GetCRUDLog() CRUDLog
GetOrgID() ID
GetName() string
GetDescription() string
2019-07-19 09:42:01 +00:00
}
// ops for checks error
var (
OpFindCheckByID = "FindCheckByID"
OpFindCheck = "FindCheck"
OpFindChecks = "FindChecks"
OpCreateCheck = "CreateCheck"
OpUpdateCheck = "UpdateCheck"
OpDeleteCheck = "DeleteCheck"
)
// CheckService represents a service for managing checks.
type CheckService interface {
// FindCheckByID returns a single check by ID.
FindCheckByID(ctx context.Context, id ID) (Check, error)
// FindCheck returns the first check that matches filter.
FindCheck(ctx context.Context, filter CheckFilter) (Check, error)
2020-02-26 16:34:10 +00:00
// FindChecks returns a list of checks that match filter and the total count of matching checks.
2019-07-19 09:42:01 +00:00
// Additional options provide pagination & sorting.
FindChecks(ctx context.Context, filter CheckFilter, opt ...FindOptions) ([]Check, int, error)
// CreateCheck creates a new check and sets b.ID with the new identifier.
2019-09-18 20:19:51 +00:00
CreateCheck(ctx context.Context, c CheckCreate, userID ID) error
2019-07-19 09:42:01 +00:00
// UpdateCheck updates the whole check.
// Returns the new check state after update.
2019-09-18 20:19:51 +00:00
UpdateCheck(ctx context.Context, id ID, c CheckCreate) (Check, error)
2019-07-19 09:42:01 +00:00
// PatchCheck updates a single bucket with changeset.
// Returns the new check state after update.
PatchCheck(ctx context.Context, id ID, upd CheckUpdate) (Check, error)
// DeleteCheck will delete the check by id.
DeleteCheck(ctx context.Context, id ID) error
}
// CheckUpdate are properties than can be updated on a check
type CheckUpdate struct {
Name *string `json:"name,omitempty"`
Status *Status `json:"status,omitempty"`
Description *string `json:"description,omitempty"`
}
2019-09-18 20:19:51 +00:00
// CheckCreate represent data to create a new Check
type CheckCreate struct {
Check
Status Status `json:"status"`
}
2019-07-19 09:42:01 +00:00
// Valid returns err is the update is invalid.
func (n *CheckUpdate) Valid() error {
if n.Name != nil && *n.Name == "" {
return &Error{
Code: EInvalid,
Msg: "Check Name can't be empty",
}
}
if n.Description != nil && *n.Description == "" {
return &Error{
Code: EInvalid,
Msg: "Check Description can't be empty",
}
}
if n.Status != nil {
if err := n.Status.Valid(); err != nil {
return err
}
}
return nil
}
// CheckFilter represents a set of filters that restrict the returned results.
type CheckFilter struct {
ID *ID
Name *string
OrgID *ID
Org *string
2019-10-21 18:11:08 +00:00
UserResourceMappingFilter
2019-07-19 09:42:01 +00:00
}
// QueryParams Converts CheckFilter fields to url query params.
func (f CheckFilter) QueryParams() map[string][]string {
qp := map[string][]string{}
if f.ID != nil {
qp["id"] = []string{f.ID.String()}
}
if f.Name != nil {
qp["name"] = []string{*f.Name}
}
if f.OrgID != nil {
qp["orgID"] = []string{f.OrgID.String()}
}
if f.Org != nil {
qp["org"] = []string{*f.Org}
}
return qp
}