Skip to content

Commit fb68d60

Browse files
authored
fix: bump the bytes number for cloud (#5625)
1 parent 542fd6f commit fb68d60

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed

src/dataExplorer/components/ResultsPane.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const ResultsPane: FC = () => {
9191
selection,
9292
} = useContext(PersistanceContext)
9393

94-
const submitButtonDisabled = !text || !selection.measurement
94+
const submitButtonDisabled = !text && !selection.measurement
9595

9696
const disabledTitleText = submitButtonDisabled
9797
? 'Select measurement before running script'

src/shared/apis/query.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import {CancelBox} from 'src/types/promises'
1212
import {File, Query, CancellationError} from 'src/types'
1313
import {event} from 'src/cloud/utils/reporting'
14+
import {getFlagValue} from 'src/shared/utils/featureFlag'
1415

1516
export type RunQueryResult =
1617
| RunQuerySuccessResult
@@ -103,12 +104,15 @@ const processSuccessResponse = async (
103104

104105
let read = await reader.read()
105106

107+
const BYTE_LIMIT =
108+
getFlagValue('increaseCsvLimit') ?? FLUX_RESPONSE_BYTES_LIMIT
109+
106110
while (!read.done) {
107111
const text = decoder.decode(read.value)
108112

109113
bytesRead += read.value.byteLength
110114

111-
if (bytesRead > FLUX_RESPONSE_BYTES_LIMIT) {
115+
if (bytesRead > BYTE_LIMIT) {
112116
csv += trimPartialLines(text)
113117
didTruncate = true
114118
break

src/shared/contexts/query.tsx

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, {FC, useEffect, useRef} from 'react'
2+
import {useDispatch} from 'react-redux'
23
import {useSelector} from 'react-redux'
34
import {nanoid} from 'nanoid'
45
import {parse, format_from_js_file} from '@influxdata/flux-lsp-browser'
@@ -9,14 +10,17 @@ import {FluxResult} from 'src/types/flows'
910
import {propertyTime} from 'src/shared/utils/getMinDurationFromAST'
1011

1112
// Constants
13+
import {FLUX_RESPONSE_BYTES_LIMIT} from 'src/shared/constants'
1214
import {SELECTABLE_TIME_RANGES} from 'src/shared/constants/timeRanges'
1315
import {
1416
RATE_LIMIT_ERROR_STATUS,
1517
RATE_LIMIT_ERROR_TEXT,
1618
GATEWAY_TIMEOUT_STATUS,
1719
REQUEST_TIMEOUT_STATUS,
1820
} from 'src/cloud/constants'
19-
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
21+
import {isFlagEnabled, getFlagValue} from 'src/shared/utils/featureFlag'
22+
import {notify} from 'src/shared/actions/notifications'
23+
import {resultTooLarge} from 'src/shared/copy/notifications'
2024

2125
// Types
2226
import {CancellationError, File} from 'src/types'
@@ -57,6 +61,35 @@ interface RequestBody {
5761
extern?: any
5862
}
5963

64+
/*
65+
Given an arbitrary text chunk of a Flux CSV, trim partial lines off of the end
66+
of the text.
67+
68+
For example, given the following partial Flux response,
69+
70+
r,baz,3
71+
foo,bar,baz,2
72+
foo,bar,b
73+
74+
we want to trim the last incomplete line, so that the result is
75+
76+
r,baz,3
77+
foo,bar,baz,2
78+
79+
*/
80+
const trimPartialLines = (partialResp: string): string => {
81+
let i = partialResp.length - 1
82+
83+
while (partialResp[i] !== '\n') {
84+
if (i <= 0) {
85+
return partialResp
86+
}
87+
88+
i -= 1
89+
}
90+
91+
return partialResp.slice(0, i + 1)
92+
}
6093
export interface QueryContextType {
6194
basic: (text: string, override?: QueryScope, options?: QueryOptions) => any
6295
query: (
@@ -485,6 +518,7 @@ const updateWindowPeriod = (
485518
}
486519

487520
export const QueryProvider: FC = ({children}) => {
521+
const dispatch = useDispatch()
488522
const pending = useRef({} as CancelMap)
489523
const org = useSelector(getOrg)
490524

@@ -552,31 +586,34 @@ export const QueryProvider: FC = ({children}) => {
552586

553587
let csv = ''
554588
let bytesRead = 0
555-
589+
let didTruncate = false
556590
let read = await reader.read()
557591

592+
const BYTE_LIMIT =
593+
getFlagValue('increaseCsvLimit') ?? FLUX_RESPONSE_BYTES_LIMIT
594+
558595
while (!read.done) {
559-
if (!pending.current[id]) {
560-
throw new CancellationError()
561-
}
562596
const text = decoder.decode(read.value)
563597

564598
bytesRead += read.value.byteLength
565599

566-
csv += text
567-
read = await reader.read()
600+
if (bytesRead > BYTE_LIMIT) {
601+
csv += trimPartialLines(text)
602+
didTruncate = true
603+
break
604+
} else {
605+
csv += text
606+
read = await reader.read()
607+
}
568608
}
569609

570610
reader.cancel()
571-
if (pending.current[id]) {
572-
delete pending.current[id]
573-
}
574611

575612
return {
576613
type: 'SUCCESS',
577614
csv,
578615
bytesRead,
579-
didTruncate: false,
616+
didTruncate,
580617
}
581618
}
582619

@@ -667,6 +704,10 @@ export const QueryProvider: FC = ({children}) => {
667704
throw new Error(raw.message)
668705
}
669706

707+
if (raw.didTruncate) {
708+
dispatch(notify(resultTooLarge(raw.bytesRead)))
709+
}
710+
670711
return raw
671712
})
672713
.then(raw => fromFlux(raw.csv))

src/shared/utils/featureFlag.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ export const isFlagEnabled = (flagName: string, equals?: string | boolean) => {
1919
return false
2020
}
2121

22+
export const getFlagValue = (flagName: string) => {
23+
const flags = activeFlags(getStore().getState())
24+
25+
if (flags.hasOwnProperty(flagName)) {
26+
return flags[flagName]
27+
}
28+
29+
return null
30+
}
31+
2232
// type influx.toggle('myFlag') to disable / enable any feature flag
2333
export const FeatureFlag: FunctionComponent<{
2434
name: string

0 commit comments

Comments
 (0)