Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {binaryPrefixFormatter} from '@influxdata/giraffe'
// Types
import {Notification, NotificationStyle} from 'src/types'
// Constants
import {
FIVE_SECONDS,
TEN_SECONDS,
FIFTEEN_SECONDS,
} from 'src/shared/constants/index'
import {QUICKSTART_SCRAPER_TARGET_URL} from 'src/dataLoaders/constants/pluginConfigs'
import {QUICKSTART_DASHBOARD_NAME} from 'src/onboarding/constants/index'
import {IconFont} from '@influxdata/clockface'
const bytesFormatter = binaryPrefixFormatter({
suffix: 'B',
significantDigits: 2,
trimZeros: true,
})
type NotificationExcludingMessage = Pick<
Notification,
Exclude
>
const defaultErrorNotification: NotificationExcludingMessage = {
style: NotificationStyle.Error,
icon: IconFont.AlertTriangle,
duration: TEN_SECONDS,
}
export function extractCol(csv: string, colName: string): string[] {
const {table} = fromFlux(csv)
return table.getColumn(colName, 'string') || []
}
const promise = queryPromise.then(resp => {
if (resp.type !== 'SUCCESS') {
return Promise.reject(new Error(resp.message))
}
const {table} = fromFlux(resp.csv)
const rows: Row[] = []
for (let i = 0; i < table.length; i++) {
const row = {}
for (const key of table.columnKeys) {
row[key] = table.getColumn(key)[i]
}
rows.push(row)
}
return rows
})
const getMatchingRules = async (): Promise => {
const checkTags = tags
.filter(t => t.key && t.value)
.map(t => [t.key, t.value])
const queryTags = []
if (queryResults) {
const joined = queryResults.join('\n\n')
const table = fromFlux(joined).table
const fluxGroupKeyUnion = fromFlux(joined).fluxGroupKeyUnion.filter(
v => v !== '_start' && v !== '_stop'
)
fluxGroupKeyUnion.forEach(gk => {
const values = uniq(table.getColumn(gk, 'string'))
values.forEach(v => {
queryTags.push([gk, v])
})
})
}
const tagsList = [...checkTags, ...queryTags].map(t => [
'tag',
`${t[0].trim()}:${t[1].trim()}`,
])
throw new Error(result.message)
}
if (result.didTruncate) {
notify(resultTooLarge(result.bytesRead))
}
}
const files = (results as RunQuerySuccessResult[]).map(r => r.csv)
let giraffeResult
if (isFlagEnabled('fluxParser')) {
giraffeResult = fromFlux(files.join('\n\n'))
} else {
giraffeResult = fromFluxGiraffe(files.join('\n\n'))
}
this.pendingReload = false
this.setState({
giraffeResult,
errorMessage,
files,
duration,
loading: RemoteDataState.Done,
statuses,
})
} catch (error) {
if (error.name === 'CancellationError') {
return
}
const getMatchingRules = async (): Promise => {
const checkTags = tags
.filter(t => t.key && t.value)
.map(t => [t.key, t.value])
const queryTags = []
if (queryResults) {
const joined = queryResults.join('\n\n')
const table = fromFlux(joined).table
const fluxGroupKeyUnion = fromFlux(joined).fluxGroupKeyUnion.filter(
v => v !== '_start' && v !== '_stop'
)
fluxGroupKeyUnion.forEach(gk => {
const values = uniq(table.getColumn(gk, 'string'))
values.forEach(v => {
queryTags.push([gk, v])
})
})
}
const tagsList = [...checkTags, ...queryTags].map(t => [
'tag',
`${t[0].trim()}:${t[1].trim()}`,
])
.then(raw => {
return {
source: text,
raw: raw.csv,
parsed: parse(raw.csv),
error: null,
}
})
}
throw new Error(result.message)
}
if (result.didTruncate) {
notify(resultTooLarge(result.bytesRead))
}
}
const files = (results as RunQuerySuccessResult[]).map(r => r.csv)
let giraffeResult
if (isFlagEnabled('fluxParser')) {
giraffeResult = fromFlux(files.join('\n\n'))
} else {
giraffeResult = fromFluxGiraffe(files.join('\n\n'))
}
this.pendingReload = false
this.setState({
giraffeResult,
errorMessage,
files,
duration,
loading: RemoteDataState.Done,
statuses,
})
} catch (error) {
if (error.name === 'CancellationError') {
return
}
.then(raw => parse(raw.csv).schema)
const promise = queryPromise.then(resp => {
if (resp.type !== 'SUCCESS') {
return Promise.reject(new Error(resp.message))
}
const {table} = fromFlux(resp.csv)
const rows: Row[][] = [[]]
for (let i = 0; i < table.length; i++) {
const row = {}
for (const key of table.columnKeys) {
row[key] = table.getColumn(key)[i]
}
const tableIndex = row['table']
if (!rows[tableIndex]) {
rows[tableIndex] = [row]
} else {
rows[tableIndex].push(row)
}