From af6ea9f0b0dedc31d7e01b7c6c93c0e3a70607d7 Mon Sep 17 00:00:00 2001 From: asalem Date: Wed, 11 Mar 2020 09:12:49 -0700 Subject: [PATCH] fix(ui): fixed dashboard cells and check query builder update bug --- dashboard.go | 27 ++-- notification/check/check_test.go | 10 +- notification/check/deadman_test.go | 20 +-- pkger/models.go | 2 +- pkger/service_test.go | 2 +- testing/checks.go | 125 +++++++++++------- ui/cypress/fixtures/view.json | 3 +- ui/mocks/dummyData.ts | 1 + ui/src/alerting/utils/customCheck.test.ts | 5 +- .../shared/utils/mocks/resourceToTemplate.ts | 2 + .../shared/utils/resourceToTemplate.test.ts | 1 + ui/src/timeMachine/reducers/index.ts | 2 +- ui/src/timeMachine/selectors/index.test.ts | 1 + ui/src/views/helpers/index.ts | 18 ++- 14 files changed, 138 insertions(+), 81 deletions(-) diff --git a/dashboard.go b/dashboard.go index df336a82e45..49d1d61ded7 100644 --- a/dashboard.go +++ b/dashboard.go @@ -873,8 +873,9 @@ type DashboardQuery struct { type BuilderConfig struct { Buckets []string `json:"buckets"` Tags []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` } `json:"tags"` Functions []struct { Name string `json:"name"` @@ -895,8 +896,9 @@ func (b BuilderConfig) MarshalJSON() ([]byte, error) { } if copyCfg.Tags == nil { copyCfg.Tags = []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{} } if copyCfg.Functions == nil { @@ -911,16 +913,19 @@ func (b BuilderConfig) MarshalJSON() ([]byte, error) { // isn't technically required, but working with struct literals with embedded // struct tags is really painful. This is to get around that bit. Would be nicer // to have these as actual types maybe. -func NewBuilderTag(key string, values ...string) struct { - Key string `json:"key"` - Values []string `json:"values"` +func NewBuilderTag(key string, values []string, functionType string) struct { + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` } { return struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ - Key: key, - Values: values, + Key: key, + Values: values, + AggregateFunctionType: functionType, } } diff --git a/notification/check/check_test.go b/notification/check/check_test.go index 37322551a1c..b20236913cb 100644 --- a/notification/check/check_test.go +++ b/notification/check/check_test.go @@ -191,8 +191,9 @@ func TestJSON(t *testing.T) { BuilderConfig: influxdb.BuilderConfig{ Buckets: []string{}, Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{}, Functions: []struct { Name string `json:"name"` @@ -232,8 +233,9 @@ func TestJSON(t *testing.T) { BuilderConfig: influxdb.BuilderConfig{ Buckets: []string{}, Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{}, Functions: []struct { Name string `json:"name"` diff --git a/notification/check/deadman_test.go b/notification/check/deadman_test.go index b8a8769c383..226c2129f77 100644 --- a/notification/check/deadman_test.go +++ b/notification/check/deadman_test.go @@ -38,12 +38,14 @@ func TestDeadman_GenerateFlux(t *testing.T) { Text: `from(bucket: "foo") |> range(start: -1d, stop: now()) |> aggregateWindow(fn: mean, every: 1m) |> yield()`, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, @@ -99,12 +101,14 @@ data Text: `from(bucket: "foo") |> range(start: -1d, stop: now()) |> yield()`, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, diff --git a/pkger/models.go b/pkger/models.go index 81991dbd43b..d9defdfddea 100644 --- a/pkger/models.go +++ b/pkger/models.go @@ -2638,7 +2638,7 @@ func (q queries) influxDashQueries() []influxdb.DashboardQuery { EditMode: "advanced", } // TODO: axe this builder configs when issue https://github.com/influxdata/influxdb/issues/15708 is fixed up - newQuery.BuilderConfig.Tags = append(newQuery.BuilderConfig.Tags, influxdb.NewBuilderTag("_measurement", "")) + newQuery.BuilderConfig.Tags = append(newQuery.BuilderConfig.Tags, influxdb.NewBuilderTag("_measurement", []string{""}, "filter")) iQueries = append(iQueries, newQuery) } return iQueries diff --git a/pkger/service_test.go b/pkger/service_test.go index 09b0e6eef45..04f3052a2d9 100644 --- a/pkger/service_test.go +++ b/pkger/service_test.go @@ -1577,7 +1577,7 @@ func TestService(t *testing.T) { EditMode: "advanced", } // TODO: remove this when issue that forced the builder tag to be here to render in UI. - q.BuilderConfig.Tags = append(q.BuilderConfig.Tags, influxdb.NewBuilderTag("_measurement", "")) + q.BuilderConfig.Tags = append(q.BuilderConfig.Tags, influxdb.NewBuilderTag("_measurement", []string{"usage_user"}, "filter")) return q } diff --git a/testing/checks.go b/testing/checks.go index 8ce0fc43069..9062c97258b 100644 --- a/testing/checks.go +++ b/testing/checks.go @@ -46,12 +46,14 @@ var deadman1 = &check.Deadman{ BuilderConfig: influxdb.BuilderConfig{ Buckets: []string{}, Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, Functions: []struct { @@ -91,8 +93,9 @@ var threshold1 = &check.Threshold{ BuilderConfig: influxdb.BuilderConfig{ Buckets: []string{}, Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{}, Functions: []struct { Name string `json:"name"` @@ -270,12 +273,14 @@ func CreateCheck( Text: script, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, @@ -326,12 +331,14 @@ func CreateCheck( BuilderConfig: influxdb.BuilderConfig{ Buckets: []string{}, Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, Functions: []struct { @@ -519,12 +526,14 @@ func CreateCheck( Text: script, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, @@ -611,12 +620,14 @@ func CreateCheck( Text: script, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, @@ -657,12 +668,14 @@ func CreateCheck( BuilderConfig: influxdb.BuilderConfig{ Buckets: []string{}, Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, Functions: []struct { @@ -705,12 +718,14 @@ func CreateCheck( Text: script, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, @@ -1495,12 +1510,14 @@ data = from(bucket: "telegraf") |> range(start: -1m)`, Text: script, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, @@ -1555,12 +1572,14 @@ data = from(bucket: "telegraf") |> range(start: -1m)`, Text: script, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, @@ -1624,12 +1643,14 @@ data = from(bucket: "telegraf") |> range(start: -1m)`, Text: script, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, @@ -1763,12 +1784,14 @@ data = from(bucket: "telegraf") |> range(start: -1m)`, BuilderConfig: influxdb.BuilderConfig{ Buckets: []string{}, Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, Functions: []struct { @@ -1816,12 +1839,14 @@ data = from(bucket: "telegraf") |> range(start: -1m)`, Text: script, BuilderConfig: influxdb.BuilderConfig{ Tags: []struct { - Key string `json:"key"` - Values []string `json:"values"` + Key string `json:"key"` + Values []string `json:"values"` + AggregateFunctionType string `json:"aggregateFunctionType"` }{ { - Key: "_field", - Values: []string{"usage_user"}, + Key: "_field", + Values: []string{"usage_user"}, + AggregateFunctionType: "filter", }, }, }, diff --git a/ui/cypress/fixtures/view.json b/ui/cypress/fixtures/view.json index abdaba9cbf3..f345c37713f 100644 --- a/ui/cypress/fixtures/view.json +++ b/ui/cypress/fixtures/view.json @@ -16,7 +16,8 @@ "tags": [ { "key": "", - "values": [] + "values": [], + "aggregateFunctionType": "" } ], "functions": [], diff --git a/ui/mocks/dummyData.ts b/ui/mocks/dummyData.ts index 706a5164713..e6966e8c4ab 100644 --- a/ui/mocks/dummyData.ts +++ b/ui/mocks/dummyData.ts @@ -926,6 +926,7 @@ export const viewProperties: ViewProperties = { { key: '_measurement', values: [], + aggregateFunctionType: 'filter', }, ], functions: [], diff --git a/ui/src/alerting/utils/customCheck.test.ts b/ui/src/alerting/utils/customCheck.test.ts index f6e82199494..d098b518d71 100644 --- a/ui/src/alerting/utils/customCheck.test.ts +++ b/ui/src/alerting/utils/customCheck.test.ts @@ -4,7 +4,10 @@ import {AlertBuilderState} from '../reducers/alertBuilder' const bc1: BuilderConfig = { buckets: ['bestBuck'], - tags: [{key: 'k1', values: ['v1']}, {key: '_field', values: ['v2']}], + tags: [ + {key: 'k1', values: ['v1'], aggregateFunctionType: 'filter'}, + {key: '_field', values: ['v2'], aggregateFunctionType: 'filter'}, + ], functions: [{name: 'mean'}], } diff --git a/ui/src/shared/utils/mocks/resourceToTemplate.ts b/ui/src/shared/utils/mocks/resourceToTemplate.ts index b1dd3b37733..8bdd3593956 100644 --- a/ui/src/shared/utils/mocks/resourceToTemplate.ts +++ b/ui/src/shared/utils/mocks/resourceToTemplate.ts @@ -43,10 +43,12 @@ export const myView: View = { { key: '_measurement', values: ['cpu'], + aggregateFunctionType: 'filter', }, { key: '_field', values: [], + aggregateFunctionType: 'filter', }, ], functions: [], diff --git a/ui/src/shared/utils/resourceToTemplate.test.ts b/ui/src/shared/utils/resourceToTemplate.test.ts index 0ba48fa6644..5cf0de81b4a 100644 --- a/ui/src/shared/utils/resourceToTemplate.test.ts +++ b/ui/src/shared/utils/resourceToTemplate.test.ts @@ -364,6 +364,7 @@ describe('resourceToTemplate', () => { { key: '_measurement', values: [], + aggregateFunctionType: 'filter', }, ], functions: [], diff --git a/ui/src/timeMachine/reducers/index.ts b/ui/src/timeMachine/reducers/index.ts index 2c941fda3a6..4c673760ce5 100644 --- a/ui/src/timeMachine/reducers/index.ts +++ b/ui/src/timeMachine/reducers/index.ts @@ -803,6 +803,7 @@ export const timeMachineReducer = ( tag.key = key tag.values = [] + tag.aggregateFunctionType = 'filter' }) } @@ -812,7 +813,6 @@ export const timeMachineReducer = ( const draftQuery = draftState.draftQueries[draftState.activeQueryIndex] draftQuery.builderConfig.tags[index].values = values - buildActiveQuery(draftState) }) } diff --git a/ui/src/timeMachine/selectors/index.test.ts b/ui/src/timeMachine/selectors/index.test.ts index bd26e181602..a6e6325a386 100644 --- a/ui/src/timeMachine/selectors/index.test.ts +++ b/ui/src/timeMachine/selectors/index.test.ts @@ -12,6 +12,7 @@ const custom = 'custom' as 'custom' describe('TimeMachine.Selectors.Index', () => { const thirty = moment() .subtract(30, 'days') + .subtract(moment().isDST() ? 1 : 0, 'hours') // added to account for DST .valueOf() it(`getStartTime should return ${thirty} when lower is now() - 30d`, () => { expect(getStartTime(pastThirtyDaysTimeRange)).toBeGreaterThanOrEqual(thirty) diff --git a/ui/src/views/helpers/index.ts b/ui/src/views/helpers/index.ts index c134cb8b32d..2775a3b614e 100644 --- a/ui/src/views/helpers/index.ts +++ b/ui/src/views/helpers/index.ts @@ -52,7 +52,7 @@ export function defaultViewQuery(): DashboardQuery { export function defaultBuilderConfig(): BuilderConfig { return { buckets: [], - tags: [{key: '_measurement', values: []}], + tags: [{key: '_measurement', values: [], aggregateFunctionType: 'filter'}], functions: [], aggregateWindow: {period: 'auto'}, } @@ -269,7 +269,13 @@ const NEW_VIEW_CREATORS = { editMode: 'builder', builderConfig: { buckets: [], - tags: [{key: '_measurement', values: []}], + tags: [ + { + key: '_measurement', + values: [], + aggregateFunctionType: 'filter', + }, + ], functions: [{name: 'mean'}], aggregateWindow: {period: DEFAULT_CHECK_EVERY}, }, @@ -291,7 +297,13 @@ const NEW_VIEW_CREATORS = { editMode: 'builder', builderConfig: { buckets: [], - tags: [{key: '_measurement', values: []}], + tags: [ + { + key: '_measurement', + values: [], + aggregateFunctionType: 'filter', + }, + ], functions: [], }, },