Skip to content

Commit

Permalink
fix: filter excluded queries at higher level
Browse files Browse the repository at this point in the history
  • Loading branch information
vlastahajek committed Oct 18, 2024
1 parent 2711c1a commit e904a25
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 73 deletions.
12 changes: 5 additions & 7 deletions ui/src/dashboards/components/InfluxQLEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ class InfluxQLEditor extends Component<Props, State> {
} else {
isSubmitted = submitted
}
// const isSubmitted = isQueryConfigChanged
// ? isExcludedStatement(query)
// ? config.isManuallySubmitted
// : true
// : submitted
if ((isSubmitted && isQueryTextChanged) || isQueryConfigChanged) {
return {
...BLURRED_EDITOR_STATE,
Expand Down Expand Up @@ -185,7 +180,7 @@ class InfluxQLEditor extends Component<Props, State> {
<QueryStatus
status={config.status}
isShowingTemplateValues={isShowingTemplateValues}
isSubmitted={submitted && config.status?.error !== 'skipped'}
isSubmitted={submitted && !config.status?.loading}
>
{this.queryStatusButtons}
</QueryStatus>
Expand Down Expand Up @@ -300,7 +295,10 @@ class InfluxQLEditor extends Component<Props, State> {
private handleUpdate = async (isAutoSubmitted?: boolean): Promise<void> => {
const {onUpdate, config} = this.props
const {editedQueryText, submitted, isExcluded} = this.state
if (!this.isDisabled && (!submitted || !config.isManuallySubmitted)) {
if (
!this.isDisabled &&
(!submitted || (!config.isManuallySubmitted && isExcluded))
) {
this.cancelPendingUpdates()
const update = onUpdate(editedQueryText, isAutoSubmitted)
const cancelableUpdate = makeCancelable(update)
Expand Down
5 changes: 1 addition & 4 deletions ui/src/dashboards/utils/cellGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ export const getConfig = async (
url,
id: string,
query: string,
templates: Template[],
isManuallySubmitted = false
templates: Template[]
): Promise<QueryConfig> => {
const renderedQuery = templateReplace(query, templates)
const queries = await getQueryConfigAndStatus(url, [
Expand All @@ -191,8 +190,6 @@ export const getConfig = async (
queryConfig.rawText = query
}

queryConfig.isManuallySubmitted = isManuallySubmitted

return {
...queryConfig,
originalQuery: query,
Expand Down
32 changes: 10 additions & 22 deletions ui/src/shared/apis/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import {TEMP_VAR_INTERVAL, DEFAULT_DURATION_MS} from 'src/shared/constants'
import replaceTemplates, {replaceInterval} from 'src/tempVars/utils/replace'
import {proxy} from 'src/utils/queryUrlGenerator'

import {Query, Source, Template} from 'src/types'
import {Source, Template} from 'src/types'
import {TimeSeriesResponse} from 'src/types/series'
import {isExcludedStatement} from '../../utils/queryFilter'

// REVIEW: why is this different than the `Query` in src/types?
// interface Query {
// text: string
// id: string
// database?: string
// db?: string
// rp?: string
// }
interface Query {
text: string
id: string
database?: string
db?: string
rp?: string
}

interface QueryResult {
value: TimeSeriesResponse | null
Expand All @@ -34,17 +33,6 @@ export function executeQueries(
let counter = queries.length

for (let i = 0; i < queries.length; i++) {
if (
isExcludedStatement(queries[i].text) &&
!queries[i].queryConfig.isManuallySubmitted
) {
results[i] = {value: null, error: 'skipped'}
counter -= 1
if (counter === 0) {
resolve(results)
}
continue
}
executeQuery(source, queries[i], templates, uuid)
.then(result => (results[i] = {value: result, error: null}))
.catch(result => (results[i] = {value: null, error: result}))
Expand All @@ -70,9 +58,9 @@ export const executeQuery = async (

const {data} = await proxy({
source: source.links.proxy,
rp: query.queryConfig.retentionPolicy,
rp: query.rp,
query: text,
db: query.queryConfig.database,
db: query.db || query.database,
uuid,
})

Expand Down
11 changes: 4 additions & 7 deletions ui/src/shared/components/TimeMachine/TimeMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,7 @@ class TimeMachine extends PureComponent<Props, State> {
let newQueryConfig

try {
newQueryConfig = await getConfig(
url,
activeID,
text,
templates,
!isAutoSubmitted
)
newQueryConfig = await getConfig(url, activeID, text, templates)
} catch {
notify(analyzeQueryFailed)
return
Expand All @@ -454,11 +448,14 @@ class TimeMachine extends PureComponent<Props, State> {
query: text,
queryConfig: {
...newQueryConfig,
isManuallySubmitted: !isAutoSubmitted,
rawText: text,
status: {loading: true},
},
}
})
// Update global query status to loading, skipped query will remain in this state
this.handleEditQueryStatus(activeID, {loading: true})
onUpdateQueryDrafts(updatedQueryDrafts)
}

Expand Down
14 changes: 2 additions & 12 deletions ui/src/shared/components/time_series/TimeSeries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,8 @@ class TimeSeries extends PureComponent<Props, State> {
}

public async componentDidUpdate(prevProps: Props) {
const prevQueries = _.map(prevProps.queries, q => {
return {
text: q.text,
isManuallySubmitted: q.queryConfig?.isManuallySubmitted,
}
})
const currQueries = _.map(this.props.queries, q => {
return {
text: q.text,
isManuallySubmitted: q.queryConfig?.isManuallySubmitted,
}
})
const prevQueries = _.map(prevProps.queries, q => q.text)
const currQueries = _.map(this.props.queries, q => q.text)
const queriesDifferent = !_.isEqual(prevQueries, currQueries)

const prevTemplates = _.get(prevProps, 'templates')
Expand Down
46 changes: 26 additions & 20 deletions ui/src/utils/buildQueriesForGraphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {buildQuery} from 'src/utils/influxql'
import {TYPE_QUERY_CONFIG, TYPE_SHIFTED} from 'src/dashboards/constants'

import {Query, QueryConfig, TimeRange, QueryType} from 'src/types'
import {isExcludedStatement} from './queryFilter'

interface Statement {
queryConfig: QueryConfig
Expand All @@ -15,28 +16,33 @@ const buildQueries = (queryConfigs: QueryConfig[], tR: TimeRange): Query[] => {
return []
}

const statements: Statement[] = queryConfigs.map((query: QueryConfig) => {
const {rawText, range, id, shifts, database, measurement, fields} = query
const timeRange: TimeRange = range || tR
const text: string =
rawText || buildQuery(TYPE_QUERY_CONFIG, timeRange, query)
const isParsable: boolean =
!_.isEmpty(database) && !_.isEmpty(measurement) && fields.length > 0

if (shifts && shifts.length && isParsable) {
const shiftedQueries: string[] = shifts
.filter(s => s.unit)
.map(s => buildQuery(TYPE_SHIFTED, timeRange, query, s))

return {
text: `${text};${shiftedQueries.join(';')}`,
id,
queryConfig: query,
const statements: Statement[] = queryConfigs
.filter(
(query: QueryConfig) =>
!isExcludedStatement(query.rawText) || query.isManuallySubmitted
)
.map((query: QueryConfig) => {
const {rawText, range, id, shifts, database, measurement, fields} = query
const timeRange: TimeRange = range || tR
const text: string =
rawText || buildQuery(TYPE_QUERY_CONFIG, timeRange, query)
const isParsable: boolean =
!_.isEmpty(database) && !_.isEmpty(measurement) && fields.length > 0

if (shifts && shifts.length && isParsable) {
const shiftedQueries: string[] = shifts
.filter(s => s.unit)
.map(s => buildQuery(TYPE_SHIFTED, timeRange, query, s))

return {
text: `${text};${shiftedQueries.join(';')}`,
id,
queryConfig: query,
}
}
}

return {text, id, queryConfig: query}
})
return {text, id, queryConfig: query}
})

const queries: Query[] = statements
.filter(s => s.text !== null)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/queryFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ const excludedStatements: string[] = [

export const isExcludedStatement = (query: string): boolean => {
return excludedStatements.some(statement =>
query.toLowerCase().startsWith(statement)
query?.toLowerCase().startsWith(statement)
)
}

0 comments on commit e904a25

Please sign in to comment.