parent
1ace31eb2d
commit
06dc4e2222
|
@ -14,6 +14,7 @@ import CEOBottom from 'src/dashboards/components/CEOBottom'
|
||||||
|
|
||||||
// APIs
|
// APIs
|
||||||
import {getQueryConfigAndStatus} from 'src/shared/apis'
|
import {getQueryConfigAndStatus} from 'src/shared/apis'
|
||||||
|
import {replace as replaceTempVars} from 'src/shared/apis/query'
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import {getDeep} from 'src/utils/wrappers'
|
import {getDeep} from 'src/utils/wrappers'
|
||||||
|
@ -21,7 +22,6 @@ import * as queryTransitions from 'src/utils/queryTransitions'
|
||||||
import defaultQueryConfig from 'src/utils/defaultQueryConfig'
|
import defaultQueryConfig from 'src/utils/defaultQueryConfig'
|
||||||
import {buildQuery} from 'src/utils/influxql'
|
import {buildQuery} from 'src/utils/influxql'
|
||||||
import {nextSource} from 'src/dashboards/utils/sources'
|
import {nextSource} from 'src/dashboards/utils/sources'
|
||||||
import replaceTemplate, {replaceInterval} from 'src/tempVars/utils/replace'
|
|
||||||
import {editCellQueryStatus} from 'src/dashboards/actions'
|
import {editCellQueryStatus} from 'src/dashboards/actions'
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
@ -33,7 +33,6 @@ import {
|
||||||
AUTO_GROUP_BY,
|
AUTO_GROUP_BY,
|
||||||
PREDEFINED_TEMP_VARS,
|
PREDEFINED_TEMP_VARS,
|
||||||
TEMP_VAR_DASHBOARD_TIME,
|
TEMP_VAR_DASHBOARD_TIME,
|
||||||
DEFAULT_DURATION_MS,
|
|
||||||
DEFAULT_PIXELS,
|
DEFAULT_PIXELS,
|
||||||
} from 'src/shared/constants'
|
} from 'src/shared/constants'
|
||||||
import {getCellTypeColors} from 'src/dashboards/constants/cellEditor'
|
import {getCellTypeColors} from 'src/dashboards/constants/cellEditor'
|
||||||
|
@ -47,7 +46,7 @@ import {Template} from 'src/types/tempVars'
|
||||||
|
|
||||||
type QueryTransitions = typeof queryTransitions
|
type QueryTransitions = typeof queryTransitions
|
||||||
type EditRawTextAsyncFunc = (
|
type EditRawTextAsyncFunc = (
|
||||||
url: string,
|
source: SourcesModels.Source,
|
||||||
id: string,
|
id: string,
|
||||||
text: string
|
text: string
|
||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
|
@ -409,23 +408,13 @@ class CellEditorOverlay extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getConfig = async (
|
private getConfig = async (
|
||||||
url,
|
source: SourcesModels.Source,
|
||||||
id: string,
|
id: string,
|
||||||
query: string,
|
query: string,
|
||||||
templates: Template[]
|
templates: Template[]
|
||||||
): Promise<QueriesModels.QueryConfig> => {
|
): Promise<QueriesModels.QueryConfig> => {
|
||||||
// replace all templates but :interval:
|
|
||||||
query = replaceTemplate(query, templates)
|
|
||||||
let queries = []
|
|
||||||
let durationMs = DEFAULT_DURATION_MS
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// get durationMs to calculate interval
|
query = await replaceTempVars(query, source, templates, DEFAULT_PIXELS)
|
||||||
queries = await getQueryConfigAndStatus(url, [{query, id}])
|
|
||||||
durationMs = _.get(queries, '0.durationMs', DEFAULT_DURATION_MS)
|
|
||||||
|
|
||||||
// calc and replace :interval:
|
|
||||||
query = replaceInterval(query, DEFAULT_PIXELS, durationMs)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
throw error
|
throw error
|
||||||
|
@ -433,15 +422,16 @@ class CellEditorOverlay extends Component<Props, State> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// fetch queryConfig for with all template variables replaced
|
// fetch queryConfig for with all template variables replaced
|
||||||
queries = await getQueryConfigAndStatus(url, [{query, id}])
|
const queries = await getQueryConfigAndStatus(source.links.queries, [
|
||||||
|
{query, id},
|
||||||
|
])
|
||||||
|
const {queryConfig} = queries.find(q => q.id === id)
|
||||||
|
|
||||||
|
return queryConfig
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
const {queryConfig} = queries.find(q => q.id === id)
|
|
||||||
|
|
||||||
return queryConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The schema explorer is not built to handle user defined template variables
|
// The schema explorer is not built to handle user defined template variables
|
||||||
|
@ -449,7 +439,7 @@ class CellEditorOverlay extends Component<Props, State> {
|
||||||
// the query config in order to disable the fields column down stream because
|
// the query config in order to disable the fields column down stream because
|
||||||
// at this point the query string is disconnected from the schema explorer.
|
// at this point the query string is disconnected from the schema explorer.
|
||||||
private handleEditRawText = async (
|
private handleEditRawText = async (
|
||||||
url: string,
|
source: SourcesModels.Source,
|
||||||
id: string,
|
id: string,
|
||||||
text: string
|
text: string
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
|
@ -462,7 +452,7 @@ class CellEditorOverlay extends Component<Props, State> {
|
||||||
const isUsingUserDefinedTempVars: boolean = !!userDefinedTempVarsInQuery.length
|
const isUsingUserDefinedTempVars: boolean = !!userDefinedTempVarsInQuery.length
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const queryConfig = await this.getConfig(url, id, text, templates)
|
const queryConfig = await this.getConfig(source, id, text, templates)
|
||||||
const nextQueries = this.state.queriesWorkingDraft.map(q => {
|
const nextQueries = this.state.queriesWorkingDraft.map(q => {
|
||||||
if (q.id === id) {
|
if (q.id === id) {
|
||||||
const isQuerySupportedByExplorer = !isUsingUserDefinedTempVars
|
const isQuerySupportedByExplorer = !isUsingUserDefinedTempVars
|
||||||
|
|
|
@ -5,22 +5,12 @@ import EmptyQuery from 'src/shared/components/EmptyQuery'
|
||||||
import QueryTabList from 'src/shared/components/QueryTabList'
|
import QueryTabList from 'src/shared/components/QueryTabList'
|
||||||
import InfluxQLEditor from 'src/dashboards/components/InfluxQLEditor'
|
import InfluxQLEditor from 'src/dashboards/components/InfluxQLEditor'
|
||||||
import SchemaExplorer from 'src/shared/components/SchemaExplorer'
|
import SchemaExplorer from 'src/shared/components/SchemaExplorer'
|
||||||
import {buildQuery} from 'src/utils/influxql'
|
|
||||||
import {TYPE_QUERY_CONFIG} from 'src/dashboards/constants'
|
|
||||||
import {TEMPLATE_RANGE} from 'src/tempVars/constants'
|
|
||||||
|
|
||||||
import {QueryConfig, Source, SourceLinks, TimeRange, Template} from 'src/types'
|
import {buildText, rawTextBinder} from 'src/dashboards/utils/queryMaker'
|
||||||
|
|
||||||
|
import {QueryConfig, Source, TimeRange, Template} from 'src/types'
|
||||||
import {CellEditorOverlayActions} from 'src/dashboards/components/CellEditorOverlay'
|
import {CellEditorOverlayActions} from 'src/dashboards/components/CellEditorOverlay'
|
||||||
|
|
||||||
const rawTextBinder = (
|
|
||||||
links: SourceLinks,
|
|
||||||
id: string,
|
|
||||||
action: (linksQueries: string, id: string, text: string) => void
|
|
||||||
) => (text: string) => action(links.queries, id, text)
|
|
||||||
|
|
||||||
const buildText = (q: QueryConfig): string =>
|
|
||||||
q.rawText || buildQuery(TYPE_QUERY_CONFIG, q.range || TEMPLATE_RANGE, q) || ''
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
source: Source
|
source: Source
|
||||||
queries: QueryConfig[]
|
queries: QueryConfig[]
|
||||||
|
@ -63,7 +53,7 @@ const QueryMaker: SFC<Props> = ({
|
||||||
query={buildText(activeQuery)}
|
query={buildText(activeQuery)}
|
||||||
config={activeQuery}
|
config={activeQuery}
|
||||||
onUpdate={rawTextBinder(
|
onUpdate={rawTextBinder(
|
||||||
source.links,
|
source,
|
||||||
activeQuery.id,
|
activeQuery.id,
|
||||||
actions.editRawTextAsync
|
actions.editRawTextAsync
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
import {buildQuery} from 'src/utils/influxql'
|
||||||
|
import {TYPE_QUERY_CONFIG} from 'src/dashboards/constants'
|
||||||
|
import {TEMPLATE_RANGE} from 'src/tempVars/constants'
|
||||||
|
|
||||||
|
import {QueryConfig, Source} from 'src/types'
|
||||||
|
|
||||||
|
export const rawTextBinder = (
|
||||||
|
source: Source,
|
||||||
|
id: string,
|
||||||
|
action: (source: Source, id: string, text: string) => void
|
||||||
|
) => (text: string) => action(source, id, text)
|
||||||
|
|
||||||
|
export const buildText = (q: QueryConfig): string =>
|
||||||
|
q.rawText || buildQuery(TYPE_QUERY_CONFIG, q.range || TEMPLATE_RANGE, q) || ''
|
|
@ -6,9 +6,10 @@ import download from 'src/external/download'
|
||||||
import {proxy} from 'src/utils/queryUrlGenerator'
|
import {proxy} from 'src/utils/queryUrlGenerator'
|
||||||
import {timeSeriesToTableGraph} from 'src/utils/timeSeriesTransformers'
|
import {timeSeriesToTableGraph} from 'src/utils/timeSeriesTransformers'
|
||||||
import {dataToCSV} from 'src/shared/parsing/dataToCSV'
|
import {dataToCSV} from 'src/shared/parsing/dataToCSV'
|
||||||
|
|
||||||
|
import {replace as replaceTempVars} from 'src/shared/apis/query'
|
||||||
|
|
||||||
import {Source, QueryConfig} from 'src/types'
|
import {Source, QueryConfig} from 'src/types'
|
||||||
import {duration} from 'src/shared/apis/query'
|
|
||||||
import {replaceInterval} from 'src/tempVars/utils/replace'
|
|
||||||
|
|
||||||
export const writeLineProtocol = async (
|
export const writeLineProtocol = async (
|
||||||
source: Source,
|
source: Source,
|
||||||
|
@ -34,13 +35,7 @@ export const getDataForCSV = (
|
||||||
errorThrown
|
errorThrown
|
||||||
) => async () => {
|
) => async () => {
|
||||||
try {
|
try {
|
||||||
let queryString = query.text
|
const queryString = await replaceTempVars(query.text, source, [], null)
|
||||||
|
|
||||||
if (queryString.includes(':interval:')) {
|
|
||||||
const queryDuration = await duration(query.text, source)
|
|
||||||
|
|
||||||
queryString = replaceInterval(query.text, null, queryDuration)
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetchTimeSeriesForCSV({
|
const response = await fetchTimeSeriesForCSV({
|
||||||
source: source.links.proxy,
|
source: source.links.proxy,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
handleLoading,
|
handleLoading,
|
||||||
} from 'src/shared/actions/timeSeries'
|
} from 'src/shared/actions/timeSeries'
|
||||||
import {analyzeQueries} from 'src/shared/apis'
|
import {analyzeQueries} from 'src/shared/apis'
|
||||||
import {DEFAULT_DURATION_MS} from 'src/shared/constants'
|
import {DEFAULT_DURATION_MS, TEMP_VAR_INTERVAL} from 'src/shared/constants'
|
||||||
import replaceTemplates, {replaceInterval} from 'src/tempVars/utils/replace'
|
import replaceTemplates, {replaceInterval} from 'src/tempVars/utils/replace'
|
||||||
import {proxy} from 'src/utils/queryUrlGenerator'
|
import {proxy} from 'src/utils/queryUrlGenerator'
|
||||||
|
|
||||||
|
@ -82,14 +82,26 @@ export const replace = async (
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
try {
|
try {
|
||||||
query = replaceTemplates(query, templates)
|
query = replaceTemplates(query, templates)
|
||||||
const durationMs = await duration(query, source)
|
return replaceIntervalAsync(query, source, resolution)
|
||||||
return replaceInterval(query, Math.floor(resolution / 3), durationMs)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const replaceIntervalAsync = async (
|
||||||
|
query: string,
|
||||||
|
source: Source,
|
||||||
|
resolution: number
|
||||||
|
): Promise<string> => {
|
||||||
|
if (query.includes(TEMP_VAR_INTERVAL)) {
|
||||||
|
const durationMs = await duration(query, source)
|
||||||
|
return replaceInterval(query, Math.floor(resolution / 3), durationMs)
|
||||||
|
} else {
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const duration = async (
|
export const duration = async (
|
||||||
query: string,
|
query: string,
|
||||||
source: Source
|
source: Source
|
||||||
|
|
Loading…
Reference in New Issue