Merge pull request #4159 from influxdata/flux/update-queries

Update flux queries based on flux api changes
pull/4166/head
Iris Scholten 2018-08-10 11:27:46 -07:00 committed by GitHub
commit 84dd8eed58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -52,12 +52,16 @@ export const getTimeSeries = async (
service: Service,
script: string
): Promise<GetTimeSeriesResult> => {
const and = encodeURIComponent('&')
const mark = encodeURIComponent('?')
const garbage = script.replace(/\s/g, '') // server cannot handle whitespace
const url = `${window.basepath}${
service.links.proxy
}?path=/v1/query${mark}orgName=defaulorgname${and}q=${garbage}`
}?path=/query${mark}organization=defaultorgname`
const dialect = {annotations: ['group', 'datatype', 'default']}
const data = JSON.stringify({
query: garbage,
dialect,
})
let responseBody: string
let responseByteLength: number
@ -69,7 +73,13 @@ export const getTimeSeries = async (
// seems to be broken at the moment. We might use this option instead of
// the `fetch` API in the future, if it is ever fixed. See
// https://github.com/axios/axios/issues/1491.
const resp = await fetch(url, {method: 'POST'})
const resp = await fetch(url, {
method: 'POST',
body: data,
headers: {
'Content-Type': 'application/json',
},
})
const {body, byteLength} = await decodeFluxRespWithLimit(resp)
responseBody = body

View File

@ -114,16 +114,18 @@ const tagsetFilter = (filter: SchemaFilter[]): string => {
}
const proxy = async (service: Service, script: string) => {
const and = encodeURIComponent('&')
const mark = encodeURIComponent('?')
const garbage = script.replace(/\s/g, '') // server cannot handle whitespace
const dialect = {annotations: ['group', 'datatype', 'default']}
const data = {query: garbage, dialect}
try {
const response = await AJAX({
method: 'POST',
url: `${
service.links.proxy
}?path=/v1/query${mark}orgName=defaulorgname${and}q=${garbage}`,
}?path=/query${mark}organization=defaultorgname`,
data,
headers: {'Content-Type': 'application/json'},
})
return response.data