Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pkger): add support for check resource to pkger parser #16259

Merged
merged 2 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

1. [16234](https://github.com/influxdata/influxdb/pull/16234): add support for notification endpoints to influx templates/pkgs.
2. [16242](https://github.com/influxdata/influxdb/pull/16242): drop id prefix for secret key requirement for notification endpoints
3. [16259](https://github.com/influxdata/influxdb/pull/16259): add support for check resource to pkger parser

### Bug Fixes

Expand Down
7 changes: 3 additions & 4 deletions http/check_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func decodePostCheckRequest(r *http.Request) (postCheckRequest, error) {
}
}
defer r.Body.Close()

chk, err := check.UnmarshalJSON(b)
if err != nil {
return postCheckRequest{}, &influxdb.Error{
Expand All @@ -387,17 +388,15 @@ func decodePostCheckRequest(r *http.Request) (postCheckRequest, error) {
}

var ds decodeStatus
err = json.Unmarshal(b, &ds)
if err != nil {
if err := json.Unmarshal(b, &ds); err != nil {
return postCheckRequest{}, &influxdb.Error{
Code: influxdb.EInvalid,
Err: err,
}
}

var dl decodeLabels
err = json.Unmarshal(b, &dl)
if err != nil {
if err := json.Unmarshal(b, &dl); err != nil {
return postCheckRequest{}, &influxdb.Error{
Code: influxdb.EInvalid,
Err: err,
Expand Down
2 changes: 1 addition & 1 deletion http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10083,7 +10083,7 @@ components:
query:
description: URL to retrieve flux script for this check
$ref: "#/components/schemas/Link"
required: [name, type, orgID, query]
required: [name, orgID, query]
ThresholdCheck:
allOf:
- $ref: "#/components/schemas/CheckBase"
Expand Down
12 changes: 5 additions & 7 deletions notification/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,20 @@ var typeToCheck = map[string](func() influxdb.Check){
"threshold": func() influxdb.Check { return &Threshold{} },
}

type rawRuleJSON struct {
Typ string `json:"type"`
}

// UnmarshalJSON will convert
func UnmarshalJSON(b []byte) (influxdb.Check, error) {
var raw rawRuleJSON
var raw struct {
Type string `json:"type"`
}
if err := json.Unmarshal(b, &raw); err != nil {
return nil, &influxdb.Error{
Msg: "unable to detect the check type from json",
}
}
convertedFunc, ok := typeToCheck[raw.Typ]
convertedFunc, ok := typeToCheck[raw.Type]
if !ok {
return nil, &influxdb.Error{
Msg: fmt.Sprintf("invalid check type %s", raw.Typ),
Msg: fmt.Sprintf("invalid check type %s", raw.Type),
}
}
converted := convertedFunc()
Expand Down
9 changes: 3 additions & 6 deletions notification/check/threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,9 @@ func (td Lesser) Type() string {
return "lesser"
}

type lesserAlias Lesser

// MarshalJSON implement json.Marshaler interface.
func (td Lesser) MarshalJSON() ([]byte, error) {
type lesserAlias Lesser
return json.Marshal(
struct {
lesserAlias
Expand All @@ -412,10 +411,9 @@ func (td Greater) Type() string {
return "greater"
}

type greaterAlias Greater

// MarshalJSON implement json.Marshaler interface.
func (td Greater) MarshalJSON() ([]byte, error) {
type greaterAlias Greater
return json.Marshal(
struct {
greaterAlias
Expand All @@ -439,10 +437,9 @@ func (td Range) Type() string {
return "range"
}

type rangeAlias Range

// MarshalJSON implement json.Marshaler interface.
func (td Range) MarshalJSON() ([]byte, error) {
type rangeAlias Range
return json.Marshal(
struct {
rangeAlias
Expand Down
9 changes: 9 additions & 0 deletions notification/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ func (d *Duration) UnmarshalJSON(b []byte) error {

return nil
}

// FromTimeDuration converts a time.Duration to a notification.Duration type.
func FromTimeDuration(d time.Duration) (Duration, error) {
dur, err := parser.ParseDuration(d.String())
if err != nil {
return Duration{}, err
}
return Duration(*dur), nil
}
Loading