Merge pull request #16543 from influxdata/zs-validatecheckparams16448

fix(tasks): validate check params new backend error message
pull/16564/head
Zoe Steinkamp 2020-01-16 09:10:52 -07:00 committed by GitHub
commit 06f7c1ea9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

View File

@ -1077,6 +1077,7 @@ func TestService_handleUpdateCheck(t *testing.T) {
Name: "hello",
OrgID: influxTesting.MustIDBase16("020f755c3c082000"),
TaskID: 3,
Every: mustDuration("1m"),
},
}
@ -1099,6 +1100,7 @@ func TestService_handleUpdateCheck(t *testing.T) {
TaskID: 3,
OwnerID: 42,
OrgID: influxTesting.MustIDBase16("020f755c3c082000"),
Every: mustDuration("1m"),
},
Level: notification.Critical,
},
@ -1118,6 +1120,7 @@ func TestService_handleUpdateCheck(t *testing.T) {
"createdAt": "0001-01-01T00:00:00Z",
"updatedAt": "0001-01-01T00:00:00Z",
"id": "020f755c3c082000",
"every": "1m",
"orgID": "020f755c3c082000",
"ownerID": "000000000000002a",
"level": "CRIT",
@ -1166,6 +1169,7 @@ func TestService_handleUpdateCheck(t *testing.T) {
Name: "example",
OwnerID: 42,
OrgID: influxTesting.MustIDBase16("020f755c3c082000"),
Every: mustDuration("1m"),
},
},
},

View File

@ -61,7 +61,25 @@ func (b Base) Valid() error {
Msg: "Check OrgID is invalid",
}
}
if b.Offset != nil && b.Every != nil && b.Offset.TimeDuration() >= b.Every.TimeDuration() {
if b.Every == nil {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "Check Every must exist",
}
}
if len(b.Every.Values) == 0 {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "Check Every can't be empty",
}
}
if b.Offset != nil && len(b.Offset.Values) == 0 {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "Check Offset can't be empty",
}
}
if b.Offset != nil && b.Offset.TimeDuration() >= b.Every.TimeDuration() {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "Offset should not be equal or greater than the interval",

View File

@ -29,6 +29,7 @@ var goodBase = check.Base{
OwnerID: influxTesting.MustIDBase16(id2),
OrgID: influxTesting.MustIDBase16(id3),
StatusMessageTemplate: "temp1",
Every: mustDuration("1m"),
Tags: []influxdb.Tag{
{Key: "k1", Value: "v1"},
{Key: "k2", Value: "v2"},
@ -88,6 +89,23 @@ func TestValidCheck(t *testing.T) {
Msg: "Check OrgID is invalid",
},
},
{
name: "nil every",
src: &check.Deadman{
Base: check.Base{
ID: influxTesting.MustIDBase16(id1),
Name: "name1",
OwnerID: influxTesting.MustIDBase16(id2),
OrgID: influxTesting.MustIDBase16(id3),
StatusMessageTemplate: "temp1",
Tags: []influxdb.Tag{{Key: "key1"}},
},
},
err: &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "Check Every must exist",
},
},
{
name: "offset greater then interval",
src: &check.Deadman{
@ -114,6 +132,7 @@ func TestValidCheck(t *testing.T) {
OwnerID: influxTesting.MustIDBase16(id2),
OrgID: influxTesting.MustIDBase16(id3),
StatusMessageTemplate: "temp1",
Every: mustDuration("1m"),
Tags: []influxdb.Tag{{Key: "key1"}},
},
},