Skip to content

Commit f34dfcf

Browse files
authored
feat: set the function up everywhere (#4606)
1 parent 7e0f015 commit f34dfcf

File tree

7 files changed

+56
-22
lines changed

7 files changed

+56
-22
lines changed

cypress/e2e/cloud/flows.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ describe('Flows', () => {
282282
})
283283
})
284284

285-
describe('Flows with queryBuilderUseMetadataCaching flag on', () => {
285+
describe('Flows with newQueryBuilder flag on', () => {
286286
beforeEach(() => {
287287
cy.flush()
288288
cy.signin()
289289
cy.get('@org').then(({id}: Organization) =>
290290
cy.fixture('routes').then(({orgs}) => {
291-
cy.setFeatureFlags({queryBuilderUseMetadataCaching: true}).then(() => {
291+
cy.setFeatureFlags({newQueryBuilder: true}).then(() => {
292292
cy.visit(`${orgs}/${id}`)
293293
})
294294
})

src/checks/reducers/checks.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const CHECK_FIXTURE_3: GenDeadmanCheck = {
9292
describe('checksReducer', () => {
9393
describe('setChecks', () => {
9494
it('sets list and status properties of state.', () => {
95-
const initialState = defaultChecksState
95+
const initialState = defaultChecksState()
9696
const cid_1 = CHECK_FIXTURE_1.id
9797
const cid_2 = CHECK_FIXTURE_2.id
9898

@@ -125,7 +125,7 @@ describe('checksReducer', () => {
125125

126126
describe('setCheck', () => {
127127
it('adds check to list if it is new', () => {
128-
const initialState = defaultChecksState
128+
const initialState = defaultChecksState()
129129
const id = CHECK_FIXTURE_2.id
130130

131131
const check = normalize<Check, CheckEntities, string>(
@@ -150,7 +150,7 @@ describe('checksReducer', () => {
150150

151151
describe('removeCheck', () => {
152152
it('removes check from state', () => {
153-
const initialState = defaultChecksState
153+
const initialState = defaultChecksState()
154154
const id = CHECK_FIXTURE_1.id
155155

156156
initialState.byID[id] = {

src/checks/reducers/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import {
2222

2323
export type ChecksState = ResourceState['checks']
2424

25-
export const defaultChecksState: ChecksState = {
25+
export const defaultChecksState = (): ChecksState => ({
2626
status: RemoteDataState.NotStarted,
2727
byID: {},
2828
allIDs: [],
29-
}
29+
})
3030

3131
export interface ResourceIDs {
3232
checkIDs: {[x: string]: boolean}
@@ -35,7 +35,7 @@ export interface ResourceIDs {
3535
}
3636

3737
export default (
38-
state: ChecksState = defaultChecksState,
38+
state: ChecksState = defaultChecksState(),
3939
action: Action
4040
): ChecksState =>
4141
produce(state, draftState => {

src/flows/pipes/QueryBuilder/context.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ export const QueryBuilderProvider: FC = ({children}) => {
281281
|> sort()
282282
|> limit(n: ${limit})`
283283

284-
if (
285-
data.buckets[0].type !== 'sample' &&
286-
isFlagEnabled('queryBuilderUseMetadataCaching')
287-
) {
284+
if (data.buckets[0].type !== 'sample' && isFlagEnabled('newQueryBuilder')) {
288285
_source = `import "regexp"
289286
import "influxdata/influxdb/schema"`
290287
queryText = `${_source}
@@ -409,10 +406,7 @@ export const QueryBuilderProvider: FC = ({children}) => {
409406
|> limit(n: ${limit})
410407
|> sort()`
411408

412-
if (
413-
data.buckets[0].type !== 'sample' &&
414-
isFlagEnabled('queryBuilderUseMetadataCaching')
415-
) {
409+
if (data.buckets[0].type !== 'sample' && isFlagEnabled('newQueryBuilder')) {
416410
_source = `import "regexp"
417411
import "influxdata/influxdb/schema"`
418412
queryText = `${_source}

src/timeMachine/apis/queryBuilder.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {formatExpression} from 'src/variables/utils/formatExpression'
1010
import {tagToFlux} from 'src/timeMachine/utils/queryBuilder'
1111
import {event} from 'src/cloud/utils/reporting'
1212
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
13+
import {
14+
CACHING_REQUIRED_END_DATE,
15+
CACHING_REQUIRED_START_DATE,
16+
} from 'src/utils/datetime/constants'
1317

1418
// Types
1519
import {TimeRange, BuilderConfig} from 'src/types'
@@ -53,7 +57,7 @@ export function findKeys({
5357

5458
// TODO: Use the `v1.tagKeys` function from the Flux standard library once
5559
// this issue is resolved: https://github.com/influxdata/flux/issues/1071
56-
const query = `import "regexp"
60+
let query = `import "regexp"
5761
5862
from(bucket: "${bucket}")
5963
|> range(${timeRangeArguments})
@@ -65,6 +69,21 @@ export function findKeys({
6569
|> sort()
6670
|> limit(n: ${adjustedLimit})`
6771

72+
if (bucket !== 'sample' && isFlagEnabled('newQueryBuilder')) {
73+
query = `import "regexp"
74+
import "influxdata/influxdb/schema"
75+
76+
schema.tagKeys(
77+
bucket: "${bucket}",
78+
predicate: (r) => ${tagFilters},
79+
start: ${CACHING_REQUIRED_START_DATE},
80+
stop: ${CACHING_REQUIRED_END_DATE},
81+
)${searchFilter}${previousKeyFilter}
82+
|> filter(fn: (r) => r._value != "_time" and r._value != "_start" and r._value != "_stop" and r._value != "_value")
83+
|> sort()
84+
|> limit(n: ${limit})`
85+
}
86+
6887
event('runQuery', {
6988
context: 'queryBuilder-findKeys',
7089
})
@@ -106,7 +125,7 @@ export function findValues({
106125

107126
// TODO: Use the `v1.tagValues` function from the Flux standard library once
108127
// this issue is resolved: https://github.com/influxdata/flux/issues/1071
109-
const query = `import "regexp"
128+
let query = `import "regexp"
110129
111130
from(bucket: "${bucket}")
112131
|> range(${timeRangeArguments})
@@ -117,6 +136,21 @@ export function findValues({
117136
|> limit(n: ${adjustedLimit})
118137
|> sort()`
119138

139+
if (bucket !== 'sample' && isFlagEnabled('newQueryBuilder')) {
140+
query = `import "regexp"
141+
import "influxdata/influxdb/schema"
142+
143+
schema.tagKeys(
144+
bucket: "${bucket}",
145+
predicate: (r) => ${tagFilters},
146+
start: ${CACHING_REQUIRED_START_DATE},
147+
stop: ${CACHING_REQUIRED_END_DATE},
148+
)${searchFilter}
149+
|> filter(fn: (r) => r._value != "_time" and r._value != "_start" and r._value != "_stop" and r._value != "_value")
150+
|> sort()
151+
|> limit(n: ${limit})`
152+
}
153+
120154
event('runQuery', {
121155
context: 'queryBuilder-findValues',
122156
})

src/timeMachine/selectors/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Libraries
22
import memoizeOne from 'memoize-one'
33
import {get} from 'lodash'
4-
import {fromFlux, Table} from '@influxdata/giraffe'
4+
import {fromFlux, fastFromFlux, Table} from '@influxdata/giraffe'
55

66
// Utils
77
import {
@@ -13,6 +13,7 @@ import {
1313
getStringColumns as getStringColumnsUtil,
1414
getMainColumnName,
1515
} from 'src/shared/utils/vis'
16+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
1617

1718
import {
1819
calcWindowPeriodForDuration,
@@ -111,7 +112,9 @@ export const getWindowPeriodFromTimeRange = (state: AppState): string => {
111112
)
112113
}
113114

114-
const getVisTableMemoized = memoizeOne(fromFlux)
115+
const getVisTableMemoized = isFlagEnabled('fastFromFlux')
116+
? memoizeOne(fastFromFlux)
117+
: memoizeOne(fromFlux)
115118

116119
export const getVisTable = (
117120
state: AppState

src/variables/utils/ValueFetcher.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// APIs
22
import {runQuery} from 'src/shared/apis/query'
3-
import {fromFlux} from '@influxdata/giraffe'
3+
import {fromFlux, fastFromFlux} from '@influxdata/giraffe'
44

55
// Utils
66
import {resolveSelectedKey} from 'src/variables/utils/resolveSelectedValue'
77
import {formatVarsOption} from 'src/variables/utils/formatVarsOption'
88
import {buildUsedVarsOption} from 'src/variables/utils/buildVarsOption'
99
import {event} from 'src/cloud/utils/reporting'
10+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
1011

1112
// Types
1213
import {
@@ -40,7 +41,9 @@ export const extractValues = (
4041
prevSelection?: string,
4142
defaultSelection?: string
4243
): VariableValues => {
43-
const {table} = fromFlux(csv)
44+
const {table} = isFlagEnabled('fastFromFlux')
45+
? fastFromFlux(csv)
46+
: fromFlux(csv)
4447
if (!table || !table.getColumn('_value', 'string')) {
4548
return {
4649
values: [],

0 commit comments

Comments
 (0)