@grafana/scenes 5.3.0 → 5.3.1--canary.802.9679960553.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -104,8 +104,8 @@ class SceneTimeRangeCompare extends SceneObjectBase {
104
104
  }
105
105
  return extraQueries;
106
106
  }
107
- shouldRerun(prev, next) {
108
- return prev.compareWith !== next.compareWith;
107
+ shouldRerun(prev, next, queries) {
108
+ return prev.compareWith !== next.compareWith && queries.find((query) => query.timeRangeCompare !== false) !== void 0;
109
109
  }
110
110
  getCompareTimeRange(timeRange) {
111
111
  let compareFrom;
@@ -1 +1 @@
1
- {"version":3,"file":"SceneTimeRangeCompare.js","sources":["../../../src/components/SceneTimeRangeCompare.tsx"],"sourcesContent":["import { DataQueryRequest, DateTime, dateTime, FieldType, GrafanaTheme2, rangeUtil, TimeRange } from '@grafana/data';\nimport { config } from '@grafana/runtime';\nimport { ButtonGroup, ButtonSelect, Checkbox, ToolbarButton, useStyles2 } from '@grafana/ui';\nimport React from 'react';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { SceneComponentProps, SceneObjectState, SceneObjectUrlValues } from '../core/types';\nimport { DataQueryExtended } from '../querying/SceneQueryRunner';\nimport { ExtraQueryDescriptor, ExtraQueryDataProcessor, ExtraQueryProvider } from '../querying/ExtraQueryProvider';\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\nimport { getCompareSeriesRefId } from '../utils/getCompareSeriesRefId';\nimport { parseUrlParam } from '../utils/parseUrlParam';\nimport { css } from '@emotion/css';\nimport { of } from 'rxjs';\n\ninterface SceneTimeRangeCompareState extends SceneObjectState {\n compareWith?: string;\n compareOptions: Array<{ label: string; value: string }>;\n}\n\nconst PREVIOUS_PERIOD_VALUE = '__previousPeriod';\nconst NO_PERIOD_VALUE = '__noPeriod';\n\nexport const PREVIOUS_PERIOD_COMPARE_OPTION = {\n label: 'Previous period',\n value: PREVIOUS_PERIOD_VALUE,\n};\n\nexport const NO_COMPARE_OPTION = {\n label: 'No comparison',\n value: NO_PERIOD_VALUE,\n};\n\nexport const DEFAULT_COMPARE_OPTIONS = [\n { label: 'Day before', value: '24h' },\n { label: 'Week before', value: '1w' },\n { label: 'Month before', value: '1M' },\n];\n\nexport class SceneTimeRangeCompare\n extends SceneObjectBase<SceneTimeRangeCompareState>\n implements ExtraQueryProvider<SceneTimeRangeCompareState> {\n\n static Component = SceneTimeRangeCompareRenderer;\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['compareWith'] });\n\n public constructor(state: Partial<SceneTimeRangeCompareState>) {\n super({ compareOptions: DEFAULT_COMPARE_OPTIONS, ...state });\n this.addActivationHandler(this._onActivate);\n }\n\n private _onActivate = () => {\n const sceneTimeRange = sceneGraph.getTimeRange(this);\n this.setState({ compareOptions: this.getCompareOptions(sceneTimeRange.state.value) });\n\n this._subs.add(\n sceneTimeRange.subscribeToState((timeRange) => {\n const compareOptions = this.getCompareOptions(timeRange.value);\n const stateUpdate: Partial<SceneTimeRangeCompareState> = { compareOptions };\n\n // if current compareWith is not applicable to the new time range, set it to previous period comparison\n if (Boolean(this.state.compareWith) && !compareOptions.find(({ value }) => value === this.state.compareWith)) {\n stateUpdate.compareWith = PREVIOUS_PERIOD_VALUE;\n }\n\n this.setState(stateUpdate);\n })\n );\n };\n\n public getCompareOptions = (timeRange: TimeRange) => {\n const diffDays = Math.ceil(timeRange.to.diff(timeRange.from));\n\n const matchIndex = DEFAULT_COMPARE_OPTIONS.findIndex(({ value }) => {\n const intervalInMs = rangeUtil.intervalToMs(value);\n return intervalInMs >= diffDays;\n });\n\n return [\n NO_COMPARE_OPTION,\n PREVIOUS_PERIOD_COMPARE_OPTION,\n ...DEFAULT_COMPARE_OPTIONS.slice(matchIndex).map(({ label, value }) => ({ label, value })),\n ];\n };\n\n public onCompareWithChanged = (compareWith: string) => {\n if (compareWith === NO_PERIOD_VALUE) {\n this.onClearCompare();\n } else {\n this.setState({ compareWith });\n }\n };\n\n public onClearCompare = () => {\n this.setState({ compareWith: undefined });\n };\n\n // Get a time shifted request to compare with the primary request.\n public getExtraQueries(request: DataQueryRequest): ExtraQueryDescriptor[] {\n const extraQueries: ExtraQueryDescriptor[] = [];\n const compareRange = this.getCompareTimeRange(request.range);\n if (!compareRange) {\n return extraQueries;\n }\n\n const targets = request.targets.filter((query: DataQueryExtended) => query.timeRangeCompare !== false);\n if (targets.length) {\n extraQueries.push({\n req: {\n ...request,\n targets,\n range: compareRange,\n },\n processor: timeShiftAlignmentProcessor,\n });\n }\n return extraQueries;\n }\n\n // The query runner should rerun the comparison query if the compareWith value has changed.\n public shouldRerun(prev: SceneTimeRangeCompareState, next: SceneTimeRangeCompareState): boolean {\n return prev.compareWith !== next.compareWith;\n }\n\n public getCompareTimeRange(timeRange: TimeRange): TimeRange | undefined {\n let compareFrom: DateTime;\n let compareTo: DateTime;\n\n if (this.state.compareWith) {\n if (this.state.compareWith === PREVIOUS_PERIOD_VALUE) {\n const diffMs = timeRange.to.diff(timeRange.from);\n compareFrom = dateTime(timeRange.from!).subtract(diffMs);\n compareTo = dateTime(timeRange.to!).subtract(diffMs);\n } else {\n compareFrom = dateTime(timeRange.from!).subtract(rangeUtil.intervalToMs(this.state.compareWith));\n compareTo = dateTime(timeRange.to!).subtract(rangeUtil.intervalToMs(this.state.compareWith));\n }\n return {\n from: compareFrom,\n to: compareTo,\n raw: {\n from: compareFrom,\n to: compareTo,\n },\n };\n }\n\n return undefined;\n }\n\n public getUrlState(): SceneObjectUrlValues {\n return {\n compareWith: this.state.compareWith,\n };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n if (!values.compareWith) {\n return;\n }\n\n const compareWith = parseUrlParam(values.compareWith);\n\n if (compareWith) {\n const compareOptions = this.getCompareOptions(sceneGraph.getTimeRange(this).state.value);\n\n if (compareOptions.find(({ value }) => value === compareWith)) {\n this.setState({\n compareWith,\n });\n } else {\n this.setState({\n compareWith: '__previousPeriod',\n });\n }\n }\n }\n}\n\n// Processor function for use with time shifted comparison series.\n// This aligns the secondary series with the primary and adds custom\n// metadata and config to the secondary series' fields so that it is\n// rendered appropriately.\nconst timeShiftAlignmentProcessor: ExtraQueryDataProcessor = (primary, secondary) => {\n const diff = secondary.timeRange.from.diff(primary.timeRange.from);\n secondary.series.forEach((series) => {\n series.refId = getCompareSeriesRefId(series.refId || '');\n series.meta = {\n ...series.meta,\n // @ts-ignore Remove when https://github.com/grafana/grafana/pull/71129 is released\n timeCompare: {\n diffMs: diff,\n isTimeShiftQuery: true,\n },\n };\n series.fields.forEach((field) => {\n // Align compare series time stamps with reference series\n if (field.type === FieldType.time) {\n field.values = field.values.map((v) => {\n return diff < 0 ? v - diff : v + diff;\n });\n }\n\n field.config = {\n ...field.config,\n color: {\n mode: 'fixed',\n fixedColor: config.theme.palette.gray60,\n },\n };\n return field;\n });\n });\n return of(secondary);\n}\n\nfunction SceneTimeRangeCompareRenderer({ model }: SceneComponentProps<SceneTimeRangeCompare>) {\n const styles = useStyles2(getStyles);\n const { compareWith, compareOptions } = model.useState();\n\n const [previousCompare, setPreviousCompare] = React.useState(compareWith);\n const previousValue = compareOptions.find(({ value }) => value === previousCompare) ?? PREVIOUS_PERIOD_COMPARE_OPTION;\n\n const value = compareOptions.find(({ value }) => value === compareWith);\n const enabled = Boolean(value);\n\n const onClick = () => {\n if (enabled) {\n setPreviousCompare(compareWith);\n model.onClearCompare();\n } else if (!enabled) {\n model.onCompareWithChanged(previousValue.value);\n }\n };\n\n return (\n <ButtonGroup>\n <ToolbarButton\n variant=\"canvas\"\n tooltip=\"Enable time frame comparison\"\n onClick={(e) => {\n e.stopPropagation();\n e.preventDefault();\n onClick();\n }}\n >\n <Checkbox label=\" \" value={enabled} onClick={onClick} />\n Comparison\n </ToolbarButton>\n\n {enabled ? (\n <ButtonSelect\n variant=\"canvas\"\n value={value}\n options={compareOptions}\n onChange={(v) => {\n model.onCompareWithChanged(v.value!);\n }}\n />\n ) : (\n <ToolbarButton className={styles.previewButton} disabled variant=\"canvas\" isOpen={false}>\n {previousValue.label}\n </ToolbarButton>\n )}\n </ButtonGroup>\n );\n}\n\nfunction getStyles(theme: GrafanaTheme2) {\n return {\n previewButton: css({\n '&:disabled': {\n border: `1px solid ${theme.colors.secondary.border}`,\n color: theme.colors.text.disabled,\n opacity: 1,\n },\n }),\n };\n}\n"],"names":["value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,qBAAwB,GAAA,kBAAA,CAAA;AAC9B,MAAM,eAAkB,GAAA,YAAA,CAAA;AAEjB,MAAM,8BAAiC,GAAA;AAAA,EAC5C,KAAO,EAAA,iBAAA;AAAA,EACP,KAAO,EAAA,qBAAA;AACT,EAAA;AAEO,MAAM,iBAAoB,GAAA;AAAA,EAC/B,KAAO,EAAA,eAAA;AAAA,EACP,KAAO,EAAA,eAAA;AACT,EAAA;AAEO,MAAM,uBAA0B,GAAA;AAAA,EACrC,EAAE,KAAA,EAAO,YAAc,EAAA,KAAA,EAAO,KAAM,EAAA;AAAA,EACpC,EAAE,KAAA,EAAO,aAAe,EAAA,KAAA,EAAO,IAAK,EAAA;AAAA,EACpC,EAAE,KAAA,EAAO,cAAgB,EAAA,KAAA,EAAO,IAAK,EAAA;AACvC,EAAA;AAEO,MAAM,8BACH,eACkD,CAAA;AAAA,EAKnD,YAAY,KAA4C,EAAA;AAC7D,IAAM,KAAA,CAAA,cAAA,CAAA,EAAE,cAAgB,EAAA,uBAAA,EAAA,EAA4B,KAAO,CAAA,CAAA,CAAA;AAH7D,IAAU,IAAA,CAAA,QAAA,GAAW,IAAI,wBAAyB,CAAA,IAAA,EAAM,EAAE,IAAM,EAAA,CAAC,aAAa,CAAA,EAAG,CAAA,CAAA;AAOjF,IAAA,IAAA,CAAQ,cAAc,MAAM;AAC1B,MAAM,MAAA,cAAA,GAAiB,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AACnD,MAAK,IAAA,CAAA,QAAA,CAAS,EAAE,cAAgB,EAAA,IAAA,CAAK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aAAA,EAAA;AAAA,IAAc,WAAW,MAAO,CAAA,aAAA;AAAA,IAAe,QAAQ,EAAA,IAAA;AAAA,IAAC,OAAQ,EAAA,QAAA;AAAA,IAAS,MAAQ,EAAA,KAAA;AAAA,GAC/E,EAAA,aAAA,CAAc,KACjB,CAEJ,CAAA,CAAA;AAEJ,CAAA;AAEA,SAAS,UAAU,KAAsB,EAAA;AACvC,EAAO,OAAA;AAAA,IACL,eAAe,GAAI,CAAA;AAAA,MACjB,YAAc,EAAA;AAAA,QACZ,MAAQ,EAAA,CAAA,UAAA,EAAa,KAAM,CAAA,MAAA,CAAO,SAAU,CAAA,MAAA,CAAA,CAAA;AAAA,QAC5C,KAAA,EAAO,KAAM,CAAA,MAAA,CAAO,IAAK,CAAA,QAAA;AAAA,QACzB,OAAS,EAAA,CAAA;AAAA,OACX;AAAA,KACD,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"SceneTimeRangeCompare.js","sources":["../../../src/components/SceneTimeRangeCompare.tsx"],"sourcesContent":["import { DataQueryRequest, DateTime, dateTime, FieldType, GrafanaTheme2, rangeUtil, TimeRange } from '@grafana/data';\nimport { config } from '@grafana/runtime';\nimport { ButtonGroup, ButtonSelect, Checkbox, ToolbarButton, useStyles2 } from '@grafana/ui';\nimport React from 'react';\nimport { sceneGraph } from '../core/sceneGraph';\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { SceneComponentProps, SceneDataQuery, SceneObjectState, SceneObjectUrlValues } from '../core/types';\nimport { DataQueryExtended } from '../querying/SceneQueryRunner';\nimport { ExtraQueryDescriptor, ExtraQueryDataProcessor, ExtraQueryProvider } from '../querying/ExtraQueryProvider';\nimport { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig';\nimport { getCompareSeriesRefId } from '../utils/getCompareSeriesRefId';\nimport { parseUrlParam } from '../utils/parseUrlParam';\nimport { css } from '@emotion/css';\nimport { of } from 'rxjs';\n\ninterface SceneTimeRangeCompareState extends SceneObjectState {\n compareWith?: string;\n compareOptions: Array<{ label: string; value: string }>;\n}\n\nconst PREVIOUS_PERIOD_VALUE = '__previousPeriod';\nconst NO_PERIOD_VALUE = '__noPeriod';\n\nexport const PREVIOUS_PERIOD_COMPARE_OPTION = {\n label: 'Previous period',\n value: PREVIOUS_PERIOD_VALUE,\n};\n\nexport const NO_COMPARE_OPTION = {\n label: 'No comparison',\n value: NO_PERIOD_VALUE,\n};\n\nexport const DEFAULT_COMPARE_OPTIONS = [\n { label: 'Day before', value: '24h' },\n { label: 'Week before', value: '1w' },\n { label: 'Month before', value: '1M' },\n];\n\nexport class SceneTimeRangeCompare\n extends SceneObjectBase<SceneTimeRangeCompareState>\n implements ExtraQueryProvider<SceneTimeRangeCompareState>\n{\n static Component = SceneTimeRangeCompareRenderer;\n protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['compareWith'] });\n\n public constructor(state: Partial<SceneTimeRangeCompareState>) {\n super({ compareOptions: DEFAULT_COMPARE_OPTIONS, ...state });\n this.addActivationHandler(this._onActivate);\n }\n\n private _onActivate = () => {\n const sceneTimeRange = sceneGraph.getTimeRange(this);\n this.setState({ compareOptions: this.getCompareOptions(sceneTimeRange.state.value) });\n\n this._subs.add(\n sceneTimeRange.subscribeToState((timeRange) => {\n const compareOptions = this.getCompareOptions(timeRange.value);\n const stateUpdate: Partial<SceneTimeRangeCompareState> = { compareOptions };\n\n // if current compareWith is not applicable to the new time range, set it to previous period comparison\n if (Boolean(this.state.compareWith) && !compareOptions.find(({ value }) => value === this.state.compareWith)) {\n stateUpdate.compareWith = PREVIOUS_PERIOD_VALUE;\n }\n\n this.setState(stateUpdate);\n })\n );\n };\n\n public getCompareOptions = (timeRange: TimeRange) => {\n const diffDays = Math.ceil(timeRange.to.diff(timeRange.from));\n\n const matchIndex = DEFAULT_COMPARE_OPTIONS.findIndex(({ value }) => {\n const intervalInMs = rangeUtil.intervalToMs(value);\n return intervalInMs >= diffDays;\n });\n\n return [\n NO_COMPARE_OPTION,\n PREVIOUS_PERIOD_COMPARE_OPTION,\n ...DEFAULT_COMPARE_OPTIONS.slice(matchIndex).map(({ label, value }) => ({ label, value })),\n ];\n };\n\n public onCompareWithChanged = (compareWith: string) => {\n if (compareWith === NO_PERIOD_VALUE) {\n this.onClearCompare();\n } else {\n this.setState({ compareWith });\n }\n };\n\n public onClearCompare = () => {\n this.setState({ compareWith: undefined });\n };\n\n // Get a time shifted request to compare with the primary request.\n public getExtraQueries(request: DataQueryRequest): ExtraQueryDescriptor[] {\n const extraQueries: ExtraQueryDescriptor[] = [];\n const compareRange = this.getCompareTimeRange(request.range);\n if (!compareRange) {\n return extraQueries;\n }\n\n const targets = request.targets.filter((query: DataQueryExtended) => query.timeRangeCompare !== false);\n if (targets.length) {\n extraQueries.push({\n req: {\n ...request,\n targets,\n range: compareRange,\n },\n processor: timeShiftAlignmentProcessor,\n });\n }\n return extraQueries;\n }\n\n // The query runner should rerun the comparison query if the compareWith value has changed and there are queries that haven't opted out of TWC\n public shouldRerun(\n prev: SceneTimeRangeCompareState,\n next: SceneTimeRangeCompareState,\n queries: SceneDataQuery[]\n ): boolean {\n return (\n prev.compareWith !== next.compareWith && queries.find((query) => query.timeRangeCompare !== false) !== undefined\n );\n }\n\n public getCompareTimeRange(timeRange: TimeRange): TimeRange | undefined {\n let compareFrom: DateTime;\n let compareTo: DateTime;\n\n if (this.state.compareWith) {\n if (this.state.compareWith === PREVIOUS_PERIOD_VALUE) {\n const diffMs = timeRange.to.diff(timeRange.from);\n compareFrom = dateTime(timeRange.from!).subtract(diffMs);\n compareTo = dateTime(timeRange.to!).subtract(diffMs);\n } else {\n compareFrom = dateTime(timeRange.from!).subtract(rangeUtil.intervalToMs(this.state.compareWith));\n compareTo = dateTime(timeRange.to!).subtract(rangeUtil.intervalToMs(this.state.compareWith));\n }\n return {\n from: compareFrom,\n to: compareTo,\n raw: {\n from: compareFrom,\n to: compareTo,\n },\n };\n }\n\n return undefined;\n }\n\n public getUrlState(): SceneObjectUrlValues {\n return {\n compareWith: this.state.compareWith,\n };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues) {\n if (!values.compareWith) {\n return;\n }\n\n const compareWith = parseUrlParam(values.compareWith);\n\n if (compareWith) {\n const compareOptions = this.getCompareOptions(sceneGraph.getTimeRange(this).state.value);\n\n if (compareOptions.find(({ value }) => value === compareWith)) {\n this.setState({\n compareWith,\n });\n } else {\n this.setState({\n compareWith: '__previousPeriod',\n });\n }\n }\n }\n}\n\n// Processor function for use with time shifted comparison series.\n// This aligns the secondary series with the primary and adds custom\n// metadata and config to the secondary series' fields so that it is\n// rendered appropriately.\nconst timeShiftAlignmentProcessor: ExtraQueryDataProcessor = (primary, secondary) => {\n const diff = secondary.timeRange.from.diff(primary.timeRange.from);\n secondary.series.forEach((series) => {\n series.refId = getCompareSeriesRefId(series.refId || '');\n series.meta = {\n ...series.meta,\n // @ts-ignore Remove when https://github.com/grafana/grafana/pull/71129 is released\n timeCompare: {\n diffMs: diff,\n isTimeShiftQuery: true,\n },\n };\n series.fields.forEach((field) => {\n // Align compare series time stamps with reference series\n if (field.type === FieldType.time) {\n field.values = field.values.map((v) => {\n return diff < 0 ? v - diff : v + diff;\n });\n }\n\n field.config = {\n ...field.config,\n color: {\n mode: 'fixed',\n fixedColor: config.theme.palette.gray60,\n },\n };\n return field;\n });\n });\n return of(secondary);\n};\n\nfunction SceneTimeRangeCompareRenderer({ model }: SceneComponentProps<SceneTimeRangeCompare>) {\n const styles = useStyles2(getStyles);\n const { compareWith, compareOptions } = model.useState();\n\n const [previousCompare, setPreviousCompare] = React.useState(compareWith);\n const previousValue = compareOptions.find(({ value }) => value === previousCompare) ?? PREVIOUS_PERIOD_COMPARE_OPTION;\n\n const value = compareOptions.find(({ value }) => value === compareWith);\n const enabled = Boolean(value);\n\n const onClick = () => {\n if (enabled) {\n setPreviousCompare(compareWith);\n model.onClearCompare();\n } else if (!enabled) {\n model.onCompareWithChanged(previousValue.value);\n }\n };\n\n return (\n <ButtonGroup>\n <ToolbarButton\n variant=\"canvas\"\n tooltip=\"Enable time frame comparison\"\n onClick={(e) => {\n e.stopPropagation();\n e.preventDefault();\n onClick();\n }}\n >\n <Checkbox label=\" \" value={enabled} onClick={onClick} />\n Comparison\n </ToolbarButton>\n\n {enabled ? (\n <ButtonSelect\n variant=\"canvas\"\n value={value}\n options={compareOptions}\n onChange={(v) => {\n model.onCompareWithChanged(v.value!);\n }}\n />\n ) : (\n <ToolbarButton className={styles.previewButton} disabled variant=\"canvas\" isOpen={false}>\n {previousValue.label}\n </ToolbarButton>\n )}\n </ButtonGroup>\n );\n}\n\nfunction getStyles(theme: GrafanaTheme2) {\n return {\n previewButton: css({\n '&:disabled': {\n border: `1px solid ${theme.colors.secondary.border}`,\n color: theme.colors.text.disabled,\n opacity: 1,\n },\n }),\n };\n}\n"],"names":["value"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,qBAAwB,GAAA,kBAAA,CAAA;AAC9B,MAAM,eAAkB,GAAA,YAAA,CAAA;AAEjB,MAAM,8BAAiC,GAAA;AAAA,EAC5C,KAAO,EAAA,iBAAA;AAAA,EACP,KAAO,EAAA,qBAAA;AACT,EAAA;AAEO,MAAM,iBAAoB,GAAA;AAAA,EAC/B,KAAO,EAAA,eAAA;AAAA,EACP,KAAO,EAAA,eAAA;AACT,EAAA;AAEO,MAAM,uBAA0B,GAAA;AAAA,EACrC,EAAE,KAAA,EAAO,YAAc,EAAA,KAAA,EAAO,KAAM,EAAA;AAAA,EACpC,EAAE,KAAA,EAAO,aAAe,EAAA,KAAA,EAAO,IAAK,EAAA;AAAA,EACpC,EAAE,KAAA,EAAO,cAAgB,EAAA,KAAA,EAAO,IAAK,EAAA;AACvC,EAAA;AAEO,MAAM,8BACH,eAEV,CAAA;AAAA,EAIS,YAAY,KAA4C,EAAA;AAC7D,IAAM,KAAA,CAAA,cAAA,CAAA,EAAE,cAAgB,EAAA,uBAAA,EAAA,EAA4B,KAAO,CAAA,C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AAA,aAAA,CAAA,QAAA,EAAA;AAAA,IAAS,KAAM,EAAA,GAAA;AAAA,IAAI,KAAO,EAAA,OAAA;AAAA,IAAS,OAAA;AAAA,GAAkB,CAAE,EAAA,YAE1D,CAEC,EAAA,OAAA,mBACE,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA;AAAA,IACC,OAAQ,EAAA,QAAA;AAAA,IACR,KAAA;AAAA,IACA,OAAS,EAAA,cAAA;AAAA,IACT,QAAA,EAAU,CAAC,CAAM,KAAA;AACf,MAAM,KAAA,CAAA,oBAAA,CAAqB,EAAE,KAAM,CAAA,CAAA;AAAA,KACrC;AAAA,GACF,oBAEC,KAAA,CAAA,aAAA,CAAA,aAAA,EAAA;AAAA,IAAc,WAAW,MAAO,CAAA,aAAA;AAAA,IAAe,QAAQ,EAAA,IAAA;AAAA,IAAC,OAAQ,EAAA,QAAA;AAAA,IAAS,MAAQ,EAAA,KAAA;AAAA,GAC/E,EAAA,aAAA,CAAc,KACjB,CAEJ,CAAA,CAAA;AAEJ,CAAA;AAEA,SAAS,UAAU,KAAsB,EAAA;AACvC,EAAO,OAAA;AAAA,IACL,eAAe,GAAI,CAAA;AAAA,MACjB,YAAc,EAAA;AAAA,QACZ,MAAQ,EAAA,CAAA,UAAA,EAAa,KAAM,CAAA,MAAA,CAAO,SAAU,CAAA,MAAA,CAAA,CAAA;AAAA,QAC5C,KAAA,EAAO,KAAM,CAAA,MAAA,CAAO,IAAK,CAAA,QAAA;AAAA,QACzB,OAAS,EAAA,CAAA;AAAA,OACX;AAAA,KACD,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExtraQueryProvider.js","sources":["../../../src/querying/ExtraQueryProvider.ts"],"sourcesContent":["import { DataQueryRequest, PanelData } from \"@grafana/data\";\nimport { Observable } from \"rxjs\";\n\nimport { SceneObjectBase } from \"../core/SceneObjectBase\";\nimport { SceneObjectState } from \"../core/types\";\n\n// A processor function called by the query runner with responses\n// to any extra requests.\n//\n// A processor function should accept two arguments: the data returned by the\n// _primary_ query, and the data returned by the `ExtraQueryProvider`'s\n// _secondary_ query. It should return a new `PanelData` representing the processed output.\n// It should _not_ modify the primary PanelData.\n//\n// Examples of valid processing include alignment of data between primary and secondary\n// (see the `timeShiftAlignmentProcessor` returned by `SceneTimeRangeCompare`), or doing\n// some more advanced processing such as fitting a time series model on the secondary data.\n//\n// See the docs for `extraQueryProcessingOperator` for more information.\nexport type ExtraQueryDataProcessor = (primary: PanelData, secondary: PanelData) => Observable<PanelData>;\n\n// An extra request that should be run by a query runner, and an optional\n// processor that should be called with the response data.\nexport interface ExtraQueryDescriptor {\n // The extra request to add.\n req: DataQueryRequest;\n // An optional function used to process the data before passing it\n // to any transformations or visualizations.\n processor?: ExtraQueryDataProcessor;\n}\n\n// Indicates that this type wants to add extra requests, along with\n// optional processing functions, to a query runner.\nexport interface ExtraQueryProvider<T extends SceneObjectState> extends SceneObjectBase<T> {\n // Get any extra requests and their required processors.\n getExtraQueries(request: DataQueryRequest): ExtraQueryDescriptor[];\n // Determine whether a query should be rerun.\n //\n // When the provider's state changes this function will be passed both the previous and the\n // next state. The implementation can use this to determine whether the change should trigger\n // a rerun of the query or not.\n shouldRerun(prev: T, next: T): boolean;\n}\n\nexport function isExtraQueryProvider(obj: any): obj is ExtraQueryProvider<any> {\n return typeof obj === 'object' && 'getExtraQueries' in obj;\n}\n"],"names":[],"mappings":"AA4CO,SAAS,qBAAqB,GAA0C,EAAA;AAC7E,EAAO,OAAA,OAAO,GAAQ,KAAA,QAAA,IAAY,iBAAqB,IAAA,GAAA,CAAA;AACzD;;;;"}
1
+ {"version":3,"file":"ExtraQueryProvider.js","sources":["../../../src/querying/ExtraQueryProvider.ts"],"sourcesContent":["import { DataQueryRequest, PanelData } from '@grafana/data';\nimport { Observable } from 'rxjs';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { SceneDataQuery, SceneObjectState } from '../core/types';\n\n// A processor function called by the query runner with responses\n// to any extra requests.\n//\n// A processor function should accept two arguments: the data returned by the\n// _primary_ query, and the data returned by the `ExtraQueryProvider`'s\n// _secondary_ query. It should return a new `PanelData` representing the processed output.\n// It should _not_ modify the primary PanelData.\n//\n// Examples of valid processing include alignment of data between primary and secondary\n// (see the `timeShiftAlignmentProcessor` returned by `SceneTimeRangeCompare`), or doing\n// some more advanced processing such as fitting a time series model on the secondary data.\n//\n// See the docs for `extraQueryProcessingOperator` for more information.\nexport type ExtraQueryDataProcessor = (primary: PanelData, secondary: PanelData) => Observable<PanelData>;\n\n// An extra request that should be run by a query runner, and an optional\n// processor that should be called with the response data.\nexport interface ExtraQueryDescriptor {\n // The extra request to add.\n req: DataQueryRequest;\n // An optional function used to process the data before passing it\n // to any transformations or visualizations.\n processor?: ExtraQueryDataProcessor;\n}\n\n// Indicates that this type wants to add extra requests, along with\n// optional processing functions, to a query runner.\nexport interface ExtraQueryProvider<T extends SceneObjectState> extends SceneObjectBase<T> {\n // Get any extra requests and their required processors.\n getExtraQueries(request: DataQueryRequest): ExtraQueryDescriptor[];\n // Determine whether a query should be rerun.\n //\n // When the provider's state changes this function will be passed both the previous and the\n // next state. The implementation can use this to determine whether the change should trigger\n // a rerun of the query or not.\n shouldRerun(prev: T, next: T, queries: SceneDataQuery[]): boolean;\n}\n\nexport function isExtraQueryProvider(obj: any): obj is ExtraQueryProvider<any> {\n return typeof obj === 'object' && 'getExtraQueries' in obj;\n}\n"],"names":[],"mappings":"AA4CO,SAAS,qBAAqB,GAA0C,EAAA;AAC7E,EAAO,OAAA,OAAO,GAAQ,KAAA,QAAA,IAAY,iBAAqB,IAAA,GAAA,CAAA;AACzD;;;;"}
@@ -79,7 +79,7 @@ class SceneQueryRunner extends SceneObjectBase {
79
79
  for (const provider of providers) {
80
80
  this._subs.add(
81
81
  provider.subscribeToState((n, p) => {
82
- if (provider.shouldRerun(p, n)) {
82
+ if (provider.shouldRerun(p, n, this.state.queries)) {
83
83
  this.runQueries();
84
84
  }
85
85
  })
@@ -1 +1 @@
1
- {"version":3,"file":"SceneQueryRunner.js","sources":["../../../src/querying/SceneQueryRunner.ts"],"sourcesContent":["import { cloneDeep, isEqual } from 'lodash';\nimport { forkJoin, ReplaySubject, Unsubscribable } from 'rxjs';\n\nimport { DataQuery, DataSourceRef, LoadingState } from '@grafana/schema';\n\nimport {\n AlertStateInfo,\n DataFrame,\n DataFrameView,\n DataQueryRequest,\n DataSourceApi,\n DataTopic,\n PanelData,\n preProcessPanelData,\n rangeUtil,\n} from '@grafana/data';\n\n// TODO: Remove this ignore annotation when the grafana runtime dependency has been updated\n// @ts-ignore\nimport { getRunRequest, toDataQueryError, isExpressionReference } from '@grafana/runtime';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport {\n DataLayerFilter,\n SceneDataProvider,\n SceneDataProviderResult,\n SceneDataQuery,\n SceneObjectState,\n SceneTimeRangeLike,\n} from '../core/types';\nimport { getDataSource } from '../utils/getDataSource';\nimport { VariableDependencyConfig } from '../variables/VariableDependencyConfig';\nimport { writeSceneLog } from '../utils/writeSceneLog';\nimport { VariableValueRecorder } from '../variables/VariableValueRecorder';\nimport { emptyPanelData } from '../core/SceneDataNode';\nimport { getClosest } from '../core/sceneGraph/utils';\nimport { isExtraQueryProvider, ExtraQueryDataProcessor, ExtraQueryProvider } from './ExtraQueryProvider';\nimport { passthroughProcessor, extraQueryProcessingOperator } from './extraQueryProcessingOperator';\nimport { filterAnnotations } from './layers/annotations/filterAnnotations';\nimport { getEnrichedDataRequest } from './getEnrichedDataRequest';\nimport { findActiveAdHocFilterVariableByUid } from '../variables/adhoc/patchGetAdhocFilters';\nimport { registerQueryWithController } from './registerQueryWithController';\nimport { findActiveGroupByVariablesByUid } from '../variables/groupby/findActiveGroupByVariablesByUid';\nimport { GroupByVariable } from '../variables/groupby/GroupByVariable';\nimport { AdHocFiltersVariable, isFilterComplete } from '../variables/adhoc/AdHocFiltersVariable';\nimport { SceneVariable } from '../variables/types';\nimport { DataLayersMerger } from './DataLayersMerger';\n\nlet counter = 100;\n\nexport function getNextRequestId() {\n return 'SQR' + counter++;\n}\n\nexport interface QueryRunnerState extends SceneObjectState {\n data?: PanelData;\n queries: SceneDataQuery[];\n datasource?: DataSourceRef;\n minInterval?: string;\n maxDataPoints?: number;\n liveStreaming?: boolean;\n maxDataPointsFromWidth?: boolean;\n cacheTimeout?: DataQueryRequest['cacheTimeout'];\n queryCachingTTL?: DataQueryRequest['queryCachingTTL'];\n // Filters to be applied to data layer results before combining them with SQR results\n dataLayerFilter?: DataLayerFilter;\n // Private runtime state\n _hasFetchedData?: boolean;\n}\n\nexport interface DataQueryExtended extends DataQuery {\n [key: string]: any;\n\n // Opt this query out of time window comparison\n timeRangeCompare?: boolean;\n}\n\n// The requests that will be run by the query runner.\n//\n// Generally the query runner will run a single primary request.\n// If the scene graph contains implementations of\n// `ExtraQueryProvider`, the requests created by these\n// implementations will be added to the list of secondary requests,\n// and these will be executed at the same time as the primary request.\n//\n// The results of each secondary request will be passed to an associated\n// processor function (along with the results of the primary request),\n// which can transform the results as desired.\ninterface PreparedRequests {\n // The primary request to run.\n primary: DataQueryRequest;\n // A possibly empty list of secondary requests to run alongside\n // the primary request.\n secondaries: DataQueryRequest[];\n // A map from `requestId` of secondary requests to processors\n // for those requests. Provided by the `ExtraQueryProvider`.\n processors: Map<string, ExtraQueryDataProcessor>;\n}\n\nexport class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implements SceneDataProvider {\n private _querySub?: Unsubscribable;\n private _dataLayersSub?: Unsubscribable;\n private _dataLayersMerger = new DataLayersMerger();\n private _timeSub?: Unsubscribable;\n private _timeSubRange?: SceneTimeRangeLike;\n private _containerWidth?: number;\n private _variableValueRecorder = new VariableValueRecorder();\n private _results = new ReplaySubject<SceneDataProviderResult>(1);\n private _scopedVars = { __sceneObject: { value: this, text: '__sceneObject' } };\n private _layerAnnotations?: DataFrame[];\n private _resultAnnotations?: DataFrame[];\n\n private _adhocFiltersVar?: AdHocFiltersVariable;\n private _groupByVar?: GroupByVariable;\n\n public getResultsStream() {\n return this._results;\n }\n\n protected _variableDependency: VariableDependencyConfig<QueryRunnerState> = new VariableDependencyConfig(this, {\n statePaths: ['queries', 'datasource'],\n onVariableUpdateCompleted: this.onVariableUpdatesCompleted.bind(this),\n onAnyVariableChanged: this.onAnyVariableChanged.bind(this),\n });\n\n public constructor(initialState: QueryRunnerState) {\n super(initialState);\n\n this.addActivationHandler(() => this._onActivate());\n }\n\n private _onActivate() {\n const timeRange = sceneGraph.getTimeRange(this);\n\n // Add subscriptions to any extra providers so that they rerun queries\n // when their state changes and they should rerun.\n const providers = this.getClosestExtraQueryProviders();\n for (const provider of providers) {\n this._subs.add(\n provider.subscribeToState((n, p) => {\n if (provider.shouldRerun(p, n)) {\n this.runQueries();\n }\n })\n );\n }\n\n this.subscribeToTimeRangeChanges(timeRange);\n\n if (this.shouldRunQueriesOnActivate()) {\n this.runQueries();\n }\n\n if (!this._dataLayersSub) {\n this._handleDataLayers();\n }\n\n return () => this._onDeactivate();\n }\n\n // This method subscribes to all SceneDataLayers up until the root, and combines the results into data provided from SceneQueryRunner\n private _handleDataLayers() {\n const dataLayers = sceneGraph.getDataLayers(this);\n\n if (dataLayers.length === 0) {\n return;\n }\n\n this._dataLayersSub = this._dataLayersMerger\n .getMergedStream(dataLayers)\n .subscribe(this._onLayersReceived.bind(this));\n }\n\n private _onLayersReceived(results: Iterable<SceneDataProviderResult>) {\n const timeRange = sceneGraph.getTimeRange(this);\n const { dataLayerFilter } = this.state;\n\n let annotations: DataFrame[] = [];\n let alertStates: DataFrame[] = [];\n let alertState: AlertStateInfo | undefined;\n\n for (const result of results) {\n for (let frame of result.data.series) {\n if (frame.meta?.dataTopic === DataTopic.Annotations) {\n annotations = annotations.concat(frame);\n }\n if (frame.meta?.dataTopic === DataTopic.AlertStates) {\n alertStates = alertStates.concat(frame);\n }\n }\n }\n\n if (dataLayerFilter?.panelId) {\n if (annotations.length > 0) {\n annotations = filterAnnotations(annotations, dataLayerFilter);\n }\n\n if (alertStates.length > 0) {\n for (const frame of alertStates) {\n const frameView = new DataFrameView<AlertStateInfo>(frame);\n\n for (const row of frameView) {\n if (row.panelId === dataLayerFilter.panelId) {\n alertState = row;\n break;\n }\n }\n }\n }\n }\n\n // Skip unnessary state updates\n if (\n allFramesEmpty(annotations) &&\n allFramesEmpty(this._layerAnnotations) &&\n isEqual(alertState, this.state.data?.alertState)\n ) {\n return;\n }\n\n this._layerAnnotations = annotations;\n\n const baseStateUpdate = this.state.data ? this.state.data : { ...emptyPanelData, timeRange: timeRange.state.value };\n\n this.setState({\n data: {\n ...baseStateUpdate,\n annotations: [...(this._resultAnnotations ?? []), ...annotations],\n alertState: alertState ?? this.state.data?.alertState,\n },\n });\n }\n\n /**\n * This tries to start a new query whenever a variable completes or is changed.\n *\n * We care about variable update completions even when the variable has not changed and even when it is not a direct dependency.\n * Example: Variables A and B (B depends on A). A update depends on time range. So when time change query runner will\n * find that variable A is loading which is a dependency on of variable B so will set _isWaitingForVariables to true and\n * not issue any query.\n *\n * When A completes it's loading (with no value change, so B never updates) it will cause a call of this function letting\n * the query runner know that A has completed, and in case _isWaitingForVariables we try to run the query. The query will\n * only run if all variables are in a non loading state so in other scenarios where a query depends on many variables this will\n * be called many times until all dependencies are in a non loading state. *\n */\n private onVariableUpdatesCompleted() {\n this.runQueries();\n }\n\n /**\n * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query\n */\n private onAnyVariableChanged(variable: SceneVariable) {\n // If this variable has already been detected this variable as a dependency onVariableUpdatesCompleted above will handle value changes\n if (this._adhocFiltersVar === variable || this._groupByVar === variable) {\n return;\n }\n\n if (variable instanceof AdHocFiltersVariable && this._isRelevantAutoVariable(variable)) {\n this.runQueries();\n }\n\n if (variable instanceof GroupByVariable && this._isRelevantAutoVariable(variable)) {\n this.runQueries();\n }\n }\n\n private _isRelevantAutoVariable(variable: AdHocFiltersVariable | GroupByVariable) {\n const datasource = this.state.datasource ?? findFirstDatasource(this.state.queries);\n return variable.state.applyMode === 'auto' && datasource?.uid === variable.state.datasource?.uid;\n }\n\n private shouldRunQueriesOnActivate() {\n if (this._variableValueRecorder.hasDependenciesChanged(this)) {\n writeSceneLog(\n 'SceneQueryRunner',\n 'Variable dependency changed while inactive, shouldRunQueriesOnActivate returns true'\n );\n return true;\n }\n\n // If we don't have any data we should run queries\n if (!this.state.data) {\n return true;\n }\n\n // If time range is stale / different we should run queries\n if (this._isDataTimeRangeStale(this.state.data)) {\n return true;\n }\n\n return false;\n }\n\n private _isDataTimeRangeStale(data: PanelData) {\n const timeRange = sceneGraph.getTimeRange(this);\n\n const stateTimeRange = timeRange.state.value;\n const dataTimeRange = data.timeRange;\n\n if (\n stateTimeRange.from.unix() === dataTimeRange.from.unix() &&\n stateTimeRange.to.unix() === dataTimeRange.to.unix()\n ) {\n return false;\n }\n writeSceneLog('SceneQueryRunner', 'Data time range is stale');\n return true;\n }\n\n private _onDeactivate(): void {\n if (this._querySub) {\n this._querySub.unsubscribe();\n this._querySub = undefined;\n }\n\n if (this._dataLayersSub) {\n this._dataLayersSub.unsubscribe();\n this._dataLayersSub = undefined;\n }\n\n this._timeSub?.unsubscribe();\n this._timeSub = undefined;\n this._timeSubRange = undefined;\n this._adhocFiltersVar = undefined;\n this._groupByVar = undefined;\n this._variableValueRecorder.recordCurrentDependencyValuesForSceneObject(this);\n }\n\n public setContainerWidth(width: number) {\n // If we don't have a width we should run queries\n if (!this._containerWidth && width > 0) {\n this._containerWidth = width;\n\n // If we don't have maxDataPoints specifically set and maxDataPointsFromWidth is true\n if (this.state.maxDataPointsFromWidth && !this.state.maxDataPoints) {\n // As this is called from render path we need to wait for next tick before running queries\n setTimeout(() => {\n if (this.isActive && !this.state._hasFetchedData) {\n this.runQueries();\n }\n }, 0);\n }\n } else {\n // if the updated container width is bigger than 0 let's remember the width until next query issue\n if (width > 0) {\n this._containerWidth = width;\n }\n }\n }\n\n public isDataReadyToDisplay() {\n return Boolean(this.state._hasFetchedData);\n }\n\n private subscribeToTimeRangeChanges(timeRange: SceneTimeRangeLike) {\n if (this._timeSubRange === timeRange) {\n // Nothing to do, already subscribed\n return;\n }\n\n if (this._timeSub) {\n this._timeSub.unsubscribe();\n }\n\n this._timeSubRange = timeRange;\n this._timeSub = timeRange.subscribeToState(() => {\n this.runWithTimeRange(timeRange);\n });\n }\n\n public runQueries() {\n const timeRange = sceneGraph.getTimeRange(this);\n this.subscribeToTimeRangeChanges(timeRange);\n this.runWithTimeRange(timeRange);\n }\n\n private getMaxDataPoints() {\n if (this.state.maxDataPoints) {\n return this.state.maxDataPoints;\n }\n\n return this.state.maxDataPointsFromWidth ? this._containerWidth ?? 500 : 500;\n }\n\n public cancelQuery() {\n this._querySub?.unsubscribe();\n\n if (this._dataLayersSub) {\n this._dataLayersSub.unsubscribe();\n this._dataLayersSub = undefined;\n }\n\n this.setState({\n data: { ...this.state.data!, state: LoadingState.Done },\n });\n }\n\n private async runWithTimeRange(timeRange: SceneTimeRangeLike) {\n // If no maxDataPoints specified we might need to wait for container width to be set from the outside\n if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {\n return;\n }\n\n // If data layers subscription doesn't exist, create one\n if (!this._dataLayersSub) {\n this._handleDataLayers();\n }\n\n // Cancel any running queries\n this._querySub?.unsubscribe();\n\n // Skip executing queries if variable dependency is in loading state\n if (this._variableDependency.hasDependencyInLoadingState()) {\n writeSceneLog('SceneQueryRunner', 'Variable dependency is in loading state, skipping query execution');\n this.setState({ data: { ...(this.state.data ?? emptyPanelData), state: LoadingState.Loading } });\n return;\n }\n\n const { queries } = this.state;\n\n // Simple path when no queries exist\n if (!queries?.length) {\n this._setNoDataState();\n return;\n }\n\n try {\n const datasource = this.state.datasource ?? findFirstDatasource(queries);\n const ds = await getDataSource(datasource, this._scopedVars);\n\n this.findAndSubscribeToAdHocFilters(datasource?.uid);\n\n const runRequest = getRunRequest();\n const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);\n\n writeSceneLog('SceneQueryRunner', 'Starting runRequest', this.state.key);\n\n let stream = runRequest(ds, primary);\n\n if (secondaries.length > 0) {\n // Submit all secondary requests in parallel.\n const secondaryStreams = secondaries.map((r) => runRequest(ds, r));\n // Create the rxjs operator which will combine the primary and secondary responses\n // by calling the correct processor functions provided by the\n // extra request providers.\n const op = extraQueryProcessingOperator(processors);\n // Combine the primary and secondary streams into a single stream, and apply the operator.\n stream = forkJoin([stream, ...secondaryStreams]).pipe(op);\n }\n\n stream = stream.pipe(\n registerQueryWithController({\n type: 'data',\n request: primary,\n origin: this,\n cancel: () => this.cancelQuery(),\n })\n );\n\n this._querySub = stream.subscribe(this.onDataReceived);\n } catch (err) {\n console.error('PanelQueryRunner Error', err);\n\n this.onDataReceived({\n ...emptyPanelData,\n ...this.state.data,\n state: LoadingState.Error,\n errors: [toDataQueryError(err)],\n });\n }\n }\n\n public clone(withState?: Partial<QueryRunnerState>) {\n const clone = super.clone(withState);\n\n if (this._resultAnnotations) {\n clone['_resultAnnotations'] = this._resultAnnotations.map((frame) => ({ ...frame }));\n }\n\n if (this._layerAnnotations) {\n clone['_layerAnnotations'] = this._layerAnnotations.map((frame) => ({ ...frame }));\n }\n\n clone['_variableValueRecorder'] = this._variableValueRecorder.cloneAndRecordCurrentValuesForSceneObject(this);\n clone['_containerWidth'] = this._containerWidth;\n clone['_results'].next({ origin: this, data: this.state.data ?? emptyPanelData });\n\n return clone;\n }\n\n private prepareRequests(timeRange: SceneTimeRangeLike, ds: DataSourceApi): PreparedRequests {\n const { minInterval, queries } = this.state;\n\n let request: DataQueryRequest<DataQueryExtended> = {\n app: 'scenes',\n requestId: getNextRequestId(),\n timezone: timeRange.getTimeZone(),\n range: timeRange.state.value,\n interval: '1s',\n intervalMs: 1000,\n targets: cloneDeep(queries),\n maxDataPoints: this.getMaxDataPoints(),\n scopedVars: this._scopedVars,\n startTime: Date.now(),\n liveStreaming: this.state.liveStreaming,\n rangeRaw: {\n from: timeRange.state.from,\n to: timeRange.state.to,\n },\n cacheTimeout: this.state.cacheTimeout,\n queryCachingTTL: this.state.queryCachingTTL,\n // This asks the scene root to provide context properties like app, panel and dashboardUID\n ...getEnrichedDataRequest(this),\n };\n\n if (this._adhocFiltersVar) {\n // only pass filters that have both key and value\n // @ts-ignore (Temporary ignore until we update @grafana/data)\n request.filters = this._adhocFiltersVar.state.filters.filter(isFilterComplete);\n }\n\n if (this._groupByVar) {\n // @ts-ignore (Temporary ignore until we update @grafana/data)\n request.groupByKeys = this._groupByVar.state.value;\n }\n\n request.targets = request.targets.map((query) => {\n if (\n !query.datasource ||\n (query.datasource.uid !== ds.uid &&\n !ds.meta?.mixed &&\n isExpressionReference /* TODO: Remove this check when isExpressionReference is properly exported from grafan runtime */ &&\n !isExpressionReference(query.datasource))\n ) {\n query.datasource = ds.getRef();\n }\n return query;\n });\n\n // TODO interpolate minInterval\n const lowerIntervalLimit = minInterval ? minInterval : ds.interval;\n const norm = rangeUtil.calculateInterval(timeRange.state.value, request.maxDataPoints!, lowerIntervalLimit);\n\n // make shallow copy of scoped vars,\n // and add built in variables interval and interval_ms\n request.scopedVars = Object.assign({}, request.scopedVars, {\n __interval: { text: norm.interval, value: norm.interval },\n __interval_ms: { text: norm.intervalMs.toString(), value: norm.intervalMs },\n });\n\n request.interval = norm.interval;\n request.intervalMs = norm.intervalMs;\n\n // If there are any extra request providers, we need to add a new request for each\n // and map the request's ID to the processor function given by the provider, to ensure that\n // the processor is called with the correct response data.\n const primaryTimeRange = timeRange.state.value;\n let secondaryRequests: DataQueryRequest[] = [];\n let secondaryProcessors = new Map();\n for (const provider of this.getClosestExtraQueryProviders() ?? []) {\n for (const { req, processor } of provider.getExtraQueries(request)) {\n const requestId = getNextRequestId();\n secondaryRequests.push({ ...req, requestId });\n secondaryProcessors.set(requestId, processor ?? passthroughProcessor);\n }\n }\n request.range = primaryTimeRange;\n return { primary: request, secondaries: secondaryRequests, processors: secondaryProcessors };\n }\n\n private onDataReceived = (data: PanelData) => {\n // Will combine annotations from SQR queries (frames with meta.dataTopic === DataTopic.Annotations)\n const preProcessedData = preProcessPanelData(data, this.state.data);\n\n // Save query annotations\n this._resultAnnotations = data.annotations;\n\n // Will combine annotations & alert state from data layer providers\n const dataWithLayersApplied = this._combineDataLayers(preProcessedData);\n\n let hasFetchedData = this.state._hasFetchedData;\n\n if (!hasFetchedData && preProcessedData.state !== LoadingState.Loading) {\n hasFetchedData = true;\n }\n\n this.setState({ data: dataWithLayersApplied, _hasFetchedData: hasFetchedData });\n this._results.next({ origin: this, data: dataWithLayersApplied });\n };\n\n private _combineDataLayers(data: PanelData) {\n if (this._layerAnnotations && this._layerAnnotations.length > 0) {\n data.annotations = (data.annotations || []).concat(this._layerAnnotations);\n }\n\n if (this.state.data && this.state.data.alertState) {\n data.alertState = this.state.data.alertState;\n }\n\n return data;\n }\n\n private _setNoDataState() {\n if (this.state.data !== emptyPanelData) {\n this.setState({ data: emptyPanelData });\n }\n }\n\n /**\n * Walk up the scene graph and find any ExtraQueryProviders.\n *\n * This will return an array of the closest provider of each type.\n */\n private getClosestExtraQueryProviders(): Array<ExtraQueryProvider<any>> {\n // Maintain a map from provider constructor to provider object. The constructor\n // is used as a unique key for each class, to ensure we have no more than one\n // type of each type of provider.\n const found = new Map();\n if (!this.parent) {\n return [];\n }\n getClosest(this.parent, (s) => {\n if (isExtraQueryProvider(s) && !found.has(s.constructor)) {\n found.set(s.constructor, s);\n }\n s.forEachChild((child) => {\n if (isExtraQueryProvider(child) && !found.has(child.constructor)) {\n found.set(child.constructor, child);\n }\n });\n // Always return null so that the search continues to the top of\n // the scene graph.\n return null;\n });\n return Array.from(found.values());\n }\n\n /**\n * Walk up scene graph and find the closest filterset with matching data source\n */\n private findAndSubscribeToAdHocFilters(uid: string | undefined) {\n const filtersVar = findActiveAdHocFilterVariableByUid(uid);\n\n if (this._adhocFiltersVar !== filtersVar) {\n this._adhocFiltersVar = filtersVar;\n this._updateExplicitVariableDependencies();\n }\n\n const groupByVar = findActiveGroupByVariablesByUid(uid);\n if (this._groupByVar !== groupByVar) {\n this._groupByVar = groupByVar;\n this._updateExplicitVariableDependencies();\n }\n }\n\n private _updateExplicitVariableDependencies() {\n const explicitDependencies: string[] = [];\n\n if (this._adhocFiltersVar) {\n explicitDependencies.push(this._adhocFiltersVar.state.name);\n }\n\n if (this._groupByVar) {\n explicitDependencies.push(this._groupByVar.state.name);\n }\n\n this._variableDependency.setVariableNames(explicitDependencies);\n }\n}\n\nexport function findFirstDatasource(targets: DataQuery[]): DataSourceRef | undefined {\n return targets.find((t) => t.datasource !== null)?.datasource ?? undefined;\n}\n\nfunction allFramesEmpty(frames?: DataFrame[]) {\n if (!frames) {\n return true;\n }\n\n for (let i = 0; i < frames.length; i++) {\n if (frames[i].length > 0) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAI,OAAU,GAAA,GAAA,CAAA;AAEP,SAAS,gBAAmB,GAAA;AACjC,EAAA,OAAO,KAAQ,GAAA,OAAA,EAAA,CAAA;AACjB,CAAA;AA+CO,MAAM,yBAAyB,eAA+D,CAAA;AAAA,EA0B5F,YAAY,YAAgC,EAAA;AACjD,IAAA,KAAA,CAAM,YAAY,CAAA,CAAA;AAxBpB,IAAQ,IAAA,CAAA,iBAAA,GAAoB,IAAI,gBAAiB,EAAA,CAAA;AAIjD,IAAQ,IAAA,CAAA,sBAAA,GAAyB,IAAI,qBAAsB,EAAA,CAAA;AAC3D,IAAQ,IAAA,CAAA,QAAA,GAAW,IAAI,aAAA,CAAuC,CAAC,CAAA,CAAA;AAC/D,IAAQ,IAAA,CAAA,WAAA,GAAc,EAAE,aAAe,EAAA,EAAE,OAAO,IAAM,EAAA,IAAA,EAAM,iBAAkB,EAAA,CAAA;AAW9E,IAAU,IAAA,CAAA,mBAAA,GAAkE,IAAI,wBAAA,CAAyB,IAAM,EAAA;AAAA,MAC7G,UAAA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AAA,IAAI,KAAK,WAAa,EAAA;AACpB,MAAA,oBAAA,CAAqB,IAAK,CAAA,IAAA,CAAK,WAAY,CAAA,KAAA,CAAM,IAAI,CAAA,CAAA;AAAA,KACvD;AAEA,IAAK,IAAA,CAAA,mBAAA,CAAoB,iBAAiB,oBAAoB,CAAA,CAAA;AAAA,GAChE;AACF,CAAA;AAEO,SAAS,oBAAoB,OAAiD,EAAA;AAjqBrF,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAkqBE,EAAO,OAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,OAAA,CAAQ,IAAK,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,eAAe,IAAI,CAAA,KAAzC,IAA4C,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,UAAA,KAA5C,IAA0D,GAAA,EAAA,GAAA,KAAA,CAAA,CAAA;AACnE,CAAA;AAEA,SAAS,eAAe,MAAsB,EAAA;AAC5C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,MAAA,CAAO,QAAQ,CAAK,EAAA,EAAA;AACtC,IAAI,IAAA,MAAA,CAAO,CAAG,CAAA,CAAA,MAAA,GAAS,CAAG,EAAA;AACxB,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACF;AAEA,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"SceneQueryRunner.js","sources":["../../../src/querying/SceneQueryRunner.ts"],"sourcesContent":["import { cloneDeep, isEqual } from 'lodash';\nimport { forkJoin, ReplaySubject, Unsubscribable } from 'rxjs';\n\nimport { DataQuery, DataSourceRef, LoadingState } from '@grafana/schema';\n\nimport {\n AlertStateInfo,\n DataFrame,\n DataFrameView,\n DataQueryRequest,\n DataSourceApi,\n DataTopic,\n PanelData,\n preProcessPanelData,\n rangeUtil,\n} from '@grafana/data';\n\n// TODO: Remove this ignore annotation when the grafana runtime dependency has been updated\n// @ts-ignore\nimport { getRunRequest, toDataQueryError, isExpressionReference } from '@grafana/runtime';\n\nimport { SceneObjectBase } from '../core/SceneObjectBase';\nimport { sceneGraph } from '../core/sceneGraph';\nimport {\n DataLayerFilter,\n SceneDataProvider,\n SceneDataProviderResult,\n SceneDataQuery,\n SceneObjectState,\n SceneTimeRangeLike,\n} from '../core/types';\nimport { getDataSource } from '../utils/getDataSource';\nimport { VariableDependencyConfig } from '../variables/VariableDependencyConfig';\nimport { writeSceneLog } from '../utils/writeSceneLog';\nimport { VariableValueRecorder } from '../variables/VariableValueRecorder';\nimport { emptyPanelData } from '../core/SceneDataNode';\nimport { getClosest } from '../core/sceneGraph/utils';\nimport { isExtraQueryProvider, ExtraQueryDataProcessor, ExtraQueryProvider } from './ExtraQueryProvider';\nimport { passthroughProcessor, extraQueryProcessingOperator } from './extraQueryProcessingOperator';\nimport { filterAnnotations } from './layers/annotations/filterAnnotations';\nimport { getEnrichedDataRequest } from './getEnrichedDataRequest';\nimport { findActiveAdHocFilterVariableByUid } from '../variables/adhoc/patchGetAdhocFilters';\nimport { registerQueryWithController } from './registerQueryWithController';\nimport { findActiveGroupByVariablesByUid } from '../variables/groupby/findActiveGroupByVariablesByUid';\nimport { GroupByVariable } from '../variables/groupby/GroupByVariable';\nimport { AdHocFiltersVariable, isFilterComplete } from '../variables/adhoc/AdHocFiltersVariable';\nimport { SceneVariable } from '../variables/types';\nimport { DataLayersMerger } from './DataLayersMerger';\n\nlet counter = 100;\n\nexport function getNextRequestId() {\n return 'SQR' + counter++;\n}\n\nexport interface QueryRunnerState extends SceneObjectState {\n data?: PanelData;\n queries: SceneDataQuery[];\n datasource?: DataSourceRef;\n minInterval?: string;\n maxDataPoints?: number;\n liveStreaming?: boolean;\n maxDataPointsFromWidth?: boolean;\n cacheTimeout?: DataQueryRequest['cacheTimeout'];\n queryCachingTTL?: DataQueryRequest['queryCachingTTL'];\n // Filters to be applied to data layer results before combining them with SQR results\n dataLayerFilter?: DataLayerFilter;\n // Private runtime state\n _hasFetchedData?: boolean;\n}\n\nexport interface DataQueryExtended extends DataQuery {\n [key: string]: any;\n\n // Opt this query out of time window comparison\n timeRangeCompare?: boolean;\n}\n\n// The requests that will be run by the query runner.\n//\n// Generally the query runner will run a single primary request.\n// If the scene graph contains implementations of\n// `ExtraQueryProvider`, the requests created by these\n// implementations will be added to the list of secondary requests,\n// and these will be executed at the same time as the primary request.\n//\n// The results of each secondary request will be passed to an associated\n// processor function (along with the results of the primary request),\n// which can transform the results as desired.\ninterface PreparedRequests {\n // The primary request to run.\n primary: DataQueryRequest;\n // A possibly empty list of secondary requests to run alongside\n // the primary request.\n secondaries: DataQueryRequest[];\n // A map from `requestId` of secondary requests to processors\n // for those requests. Provided by the `ExtraQueryProvider`.\n processors: Map<string, ExtraQueryDataProcessor>;\n}\n\nexport class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implements SceneDataProvider {\n private _querySub?: Unsubscribable;\n private _dataLayersSub?: Unsubscribable;\n private _dataLayersMerger = new DataLayersMerger();\n private _timeSub?: Unsubscribable;\n private _timeSubRange?: SceneTimeRangeLike;\n private _containerWidth?: number;\n private _variableValueRecorder = new VariableValueRecorder();\n private _results = new ReplaySubject<SceneDataProviderResult>(1);\n private _scopedVars = { __sceneObject: { value: this, text: '__sceneObject' } };\n private _layerAnnotations?: DataFrame[];\n private _resultAnnotations?: DataFrame[];\n\n private _adhocFiltersVar?: AdHocFiltersVariable;\n private _groupByVar?: GroupByVariable;\n\n public getResultsStream() {\n return this._results;\n }\n\n protected _variableDependency: VariableDependencyConfig<QueryRunnerState> = new VariableDependencyConfig(this, {\n statePaths: ['queries', 'datasource'],\n onVariableUpdateCompleted: this.onVariableUpdatesCompleted.bind(this),\n onAnyVariableChanged: this.onAnyVariableChanged.bind(this),\n });\n\n public constructor(initialState: QueryRunnerState) {\n super(initialState);\n\n this.addActivationHandler(() => this._onActivate());\n }\n\n private _onActivate() {\n const timeRange = sceneGraph.getTimeRange(this);\n\n // Add subscriptions to any extra providers so that they rerun queries\n // when their state changes and they should rerun.\n const providers = this.getClosestExtraQueryProviders();\n for (const provider of providers) {\n this._subs.add(\n provider.subscribeToState((n, p) => {\n if (provider.shouldRerun(p, n, this.state.queries)) {\n this.runQueries();\n }\n })\n );\n }\n\n this.subscribeToTimeRangeChanges(timeRange);\n\n if (this.shouldRunQueriesOnActivate()) {\n this.runQueries();\n }\n\n if (!this._dataLayersSub) {\n this._handleDataLayers();\n }\n\n return () => this._onDeactivate();\n }\n\n // This method subscribes to all SceneDataLayers up until the root, and combines the results into data provided from SceneQueryRunner\n private _handleDataLayers() {\n const dataLayers = sceneGraph.getDataLayers(this);\n\n if (dataLayers.length === 0) {\n return;\n }\n\n this._dataLayersSub = this._dataLayersMerger\n .getMergedStream(dataLayers)\n .subscribe(this._onLayersReceived.bind(this));\n }\n\n private _onLayersReceived(results: Iterable<SceneDataProviderResult>) {\n const timeRange = sceneGraph.getTimeRange(this);\n const { dataLayerFilter } = this.state;\n\n let annotations: DataFrame[] = [];\n let alertStates: DataFrame[] = [];\n let alertState: AlertStateInfo | undefined;\n\n for (const result of results) {\n for (let frame of result.data.series) {\n if (frame.meta?.dataTopic === DataTopic.Annotations) {\n annotations = annotations.concat(frame);\n }\n if (frame.meta?.dataTopic === DataTopic.AlertStates) {\n alertStates = alertStates.concat(frame);\n }\n }\n }\n\n if (dataLayerFilter?.panelId) {\n if (annotations.length > 0) {\n annotations = filterAnnotations(annotations, dataLayerFilter);\n }\n\n if (alertStates.length > 0) {\n for (const frame of alertStates) {\n const frameView = new DataFrameView<AlertStateInfo>(frame);\n\n for (const row of frameView) {\n if (row.panelId === dataLayerFilter.panelId) {\n alertState = row;\n break;\n }\n }\n }\n }\n }\n\n // Skip unnessary state updates\n if (\n allFramesEmpty(annotations) &&\n allFramesEmpty(this._layerAnnotations) &&\n isEqual(alertState, this.state.data?.alertState)\n ) {\n return;\n }\n\n this._layerAnnotations = annotations;\n\n const baseStateUpdate = this.state.data ? this.state.data : { ...emptyPanelData, timeRange: timeRange.state.value };\n\n this.setState({\n data: {\n ...baseStateUpdate,\n annotations: [...(this._resultAnnotations ?? []), ...annotations],\n alertState: alertState ?? this.state.data?.alertState,\n },\n });\n }\n\n /**\n * This tries to start a new query whenever a variable completes or is changed.\n *\n * We care about variable update completions even when the variable has not changed and even when it is not a direct dependency.\n * Example: Variables A and B (B depends on A). A update depends on time range. So when time change query runner will\n * find that variable A is loading which is a dependency on of variable B so will set _isWaitingForVariables to true and\n * not issue any query.\n *\n * When A completes it's loading (with no value change, so B never updates) it will cause a call of this function letting\n * the query runner know that A has completed, and in case _isWaitingForVariables we try to run the query. The query will\n * only run if all variables are in a non loading state so in other scenarios where a query depends on many variables this will\n * be called many times until all dependencies are in a non loading state. *\n */\n private onVariableUpdatesCompleted() {\n this.runQueries();\n }\n\n /**\n * Check if value changed is a adhoc filter o group by variable that did not exist when we issued the last query\n */\n private onAnyVariableChanged(variable: SceneVariable) {\n // If this variable has already been detected this variable as a dependency onVariableUpdatesCompleted above will handle value changes\n if (this._adhocFiltersVar === variable || this._groupByVar === variable) {\n return;\n }\n\n if (variable instanceof AdHocFiltersVariable && this._isRelevantAutoVariable(variable)) {\n this.runQueries();\n }\n\n if (variable instanceof GroupByVariable && this._isRelevantAutoVariable(variable)) {\n this.runQueries();\n }\n }\n\n private _isRelevantAutoVariable(variable: AdHocFiltersVariable | GroupByVariable) {\n const datasource = this.state.datasource ?? findFirstDatasource(this.state.queries);\n return variable.state.applyMode === 'auto' && datasource?.uid === variable.state.datasource?.uid;\n }\n\n private shouldRunQueriesOnActivate() {\n if (this._variableValueRecorder.hasDependenciesChanged(this)) {\n writeSceneLog(\n 'SceneQueryRunner',\n 'Variable dependency changed while inactive, shouldRunQueriesOnActivate returns true'\n );\n return true;\n }\n\n // If we don't have any data we should run queries\n if (!this.state.data) {\n return true;\n }\n\n // If time range is stale / different we should run queries\n if (this._isDataTimeRangeStale(this.state.data)) {\n return true;\n }\n\n return false;\n }\n\n private _isDataTimeRangeStale(data: PanelData) {\n const timeRange = sceneGraph.getTimeRange(this);\n\n const stateTimeRange = timeRange.state.value;\n const dataTimeRange = data.timeRange;\n\n if (\n stateTimeRange.from.unix() === dataTimeRange.from.unix() &&\n stateTimeRange.to.unix() === dataTimeRange.to.unix()\n ) {\n return false;\n }\n writeSceneLog('SceneQueryRunner', 'Data time range is stale');\n return true;\n }\n\n private _onDeactivate(): void {\n if (this._querySub) {\n this._querySub.unsubscribe();\n this._querySub = undefined;\n }\n\n if (this._dataLayersSub) {\n this._dataLayersSub.unsubscribe();\n this._dataLayersSub = undefined;\n }\n\n this._timeSub?.unsubscribe();\n this._timeSub = undefined;\n this._timeSubRange = undefined;\n this._adhocFiltersVar = undefined;\n this._groupByVar = undefined;\n this._variableValueRecorder.recordCurrentDependencyValuesForSceneObject(this);\n }\n\n public setContainerWidth(width: number) {\n // If we don't have a width we should run queries\n if (!this._containerWidth && width > 0) {\n this._containerWidth = width;\n\n // If we don't have maxDataPoints specifically set and maxDataPointsFromWidth is true\n if (this.state.maxDataPointsFromWidth && !this.state.maxDataPoints) {\n // As this is called from render path we need to wait for next tick before running queries\n setTimeout(() => {\n if (this.isActive && !this.state._hasFetchedData) {\n this.runQueries();\n }\n }, 0);\n }\n } else {\n // if the updated container width is bigger than 0 let's remember the width until next query issue\n if (width > 0) {\n this._containerWidth = width;\n }\n }\n }\n\n public isDataReadyToDisplay() {\n return Boolean(this.state._hasFetchedData);\n }\n\n private subscribeToTimeRangeChanges(timeRange: SceneTimeRangeLike) {\n if (this._timeSubRange === timeRange) {\n // Nothing to do, already subscribed\n return;\n }\n\n if (this._timeSub) {\n this._timeSub.unsubscribe();\n }\n\n this._timeSubRange = timeRange;\n this._timeSub = timeRange.subscribeToState(() => {\n this.runWithTimeRange(timeRange);\n });\n }\n\n public runQueries() {\n const timeRange = sceneGraph.getTimeRange(this);\n this.subscribeToTimeRangeChanges(timeRange);\n this.runWithTimeRange(timeRange);\n }\n\n private getMaxDataPoints() {\n if (this.state.maxDataPoints) {\n return this.state.maxDataPoints;\n }\n\n return this.state.maxDataPointsFromWidth ? this._containerWidth ?? 500 : 500;\n }\n\n public cancelQuery() {\n this._querySub?.unsubscribe();\n\n if (this._dataLayersSub) {\n this._dataLayersSub.unsubscribe();\n this._dataLayersSub = undefined;\n }\n\n this.setState({\n data: { ...this.state.data!, state: LoadingState.Done },\n });\n }\n\n private async runWithTimeRange(timeRange: SceneTimeRangeLike) {\n // If no maxDataPoints specified we might need to wait for container width to be set from the outside\n if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {\n return;\n }\n\n // If data layers subscription doesn't exist, create one\n if (!this._dataLayersSub) {\n this._handleDataLayers();\n }\n\n // Cancel any running queries\n this._querySub?.unsubscribe();\n\n // Skip executing queries if variable dependency is in loading state\n if (this._variableDependency.hasDependencyInLoadingState()) {\n writeSceneLog('SceneQueryRunner', 'Variable dependency is in loading state, skipping query execution');\n this.setState({ data: { ...(this.state.data ?? emptyPanelData), state: LoadingState.Loading } });\n return;\n }\n\n const { queries } = this.state;\n\n // Simple path when no queries exist\n if (!queries?.length) {\n this._setNoDataState();\n return;\n }\n\n try {\n const datasource = this.state.datasource ?? findFirstDatasource(queries);\n const ds = await getDataSource(datasource, this._scopedVars);\n\n this.findAndSubscribeToAdHocFilters(datasource?.uid);\n\n const runRequest = getRunRequest();\n const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);\n\n writeSceneLog('SceneQueryRunner', 'Starting runRequest', this.state.key);\n\n let stream = runRequest(ds, primary);\n\n if (secondaries.length > 0) {\n // Submit all secondary requests in parallel.\n const secondaryStreams = secondaries.map((r) => runRequest(ds, r));\n // Create the rxjs operator which will combine the primary and secondary responses\n // by calling the correct processor functions provided by the\n // extra request providers.\n const op = extraQueryProcessingOperator(processors);\n // Combine the primary and secondary streams into a single stream, and apply the operator.\n stream = forkJoin([stream, ...secondaryStreams]).pipe(op);\n }\n\n stream = stream.pipe(\n registerQueryWithController({\n type: 'data',\n request: primary,\n origin: this,\n cancel: () => this.cancelQuery(),\n })\n );\n\n this._querySub = stream.subscribe(this.onDataReceived);\n } catch (err) {\n console.error('PanelQueryRunner Error', err);\n\n this.onDataReceived({\n ...emptyPanelData,\n ...this.state.data,\n state: LoadingState.Error,\n errors: [toDataQueryError(err)],\n });\n }\n }\n\n public clone(withState?: Partial<QueryRunnerState>) {\n const clone = super.clone(withState);\n\n if (this._resultAnnotations) {\n clone['_resultAnnotations'] = this._resultAnnotations.map((frame) => ({ ...frame }));\n }\n\n if (this._layerAnnotations) {\n clone['_layerAnnotations'] = this._layerAnnotations.map((frame) => ({ ...frame }));\n }\n\n clone['_variableValueRecorder'] = this._variableValueRecorder.cloneAndRecordCurrentValuesForSceneObject(this);\n clone['_containerWidth'] = this._containerWidth;\n clone['_results'].next({ origin: this, data: this.state.data ?? emptyPanelData });\n\n return clone;\n }\n\n private prepareRequests(timeRange: SceneTimeRangeLike, ds: DataSourceApi): PreparedRequests {\n const { minInterval, queries } = this.state;\n\n let request: DataQueryRequest<DataQueryExtended> = {\n app: 'scenes',\n requestId: getNextRequestId(),\n timezone: timeRange.getTimeZone(),\n range: timeRange.state.value,\n interval: '1s',\n intervalMs: 1000,\n targets: cloneDeep(queries),\n maxDataPoints: this.getMaxDataPoints(),\n scopedVars: this._scopedVars,\n startTime: Date.now(),\n liveStreaming: this.state.liveStreaming,\n rangeRaw: {\n from: timeRange.state.from,\n to: timeRange.state.to,\n },\n cacheTimeout: this.state.cacheTimeout,\n queryCachingTTL: this.state.queryCachingTTL,\n // This asks the scene root to provide context properties like app, panel and dashboardUID\n ...getEnrichedDataRequest(this),\n };\n\n if (this._adhocFiltersVar) {\n // only pass filters that have both key and value\n // @ts-ignore (Temporary ignore until we update @grafana/data)\n request.filters = this._adhocFiltersVar.state.filters.filter(isFilterComplete);\n }\n\n if (this._groupByVar) {\n // @ts-ignore (Temporary ignore until we update @grafana/data)\n request.groupByKeys = this._groupByVar.state.value;\n }\n\n request.targets = request.targets.map((query) => {\n if (\n !query.datasource ||\n (query.datasource.uid !== ds.uid &&\n !ds.meta?.mixed &&\n isExpressionReference /* TODO: Remove this check when isExpressionReference is properly exported from grafan runtime */ &&\n !isExpressionReference(query.datasource))\n ) {\n query.datasource = ds.getRef();\n }\n return query;\n });\n\n // TODO interpolate minInterval\n const lowerIntervalLimit = minInterval ? minInterval : ds.interval;\n const norm = rangeUtil.calculateInterval(timeRange.state.value, request.maxDataPoints!, lowerIntervalLimit);\n\n // make shallow copy of scoped vars,\n // and add built in variables interval and interval_ms\n request.scopedVars = Object.assign({}, request.scopedVars, {\n __interval: { text: norm.interval, value: norm.interval },\n __interval_ms: { text: norm.intervalMs.toString(), value: norm.intervalMs },\n });\n\n request.interval = norm.interval;\n request.intervalMs = norm.intervalMs;\n\n // If there are any extra request providers, we need to add a new request for each\n // and map the request's ID to the processor function given by the provider, to ensure that\n // the processor is called with the correct response data.\n const primaryTimeRange = timeRange.state.value;\n let secondaryRequests: DataQueryRequest[] = [];\n let secondaryProcessors = new Map();\n for (const provider of this.getClosestExtraQueryProviders() ?? []) {\n for (const { req, processor } of provider.getExtraQueries(request)) {\n const requestId = getNextRequestId();\n secondaryRequests.push({ ...req, requestId });\n secondaryProcessors.set(requestId, processor ?? passthroughProcessor);\n }\n }\n request.range = primaryTimeRange;\n return { primary: request, secondaries: secondaryRequests, processors: secondaryProcessors };\n }\n\n private onDataReceived = (data: PanelData) => {\n // Will combine annotations from SQR queries (frames with meta.dataTopic === DataTopic.Annotations)\n const preProcessedData = preProcessPanelData(data, this.state.data);\n\n // Save query annotations\n this._resultAnnotations = data.annotations;\n\n // Will combine annotations & alert state from data layer providers\n const dataWithLayersApplied = this._combineDataLayers(preProcessedData);\n\n let hasFetchedData = this.state._hasFetchedData;\n\n if (!hasFetchedData && preProcessedData.state !== LoadingState.Loading) {\n hasFetchedData = true;\n }\n\n this.setState({ data: dataWithLayersApplied, _hasFetchedData: hasFetchedData });\n this._results.next({ origin: this, data: dataWithLayersApplied });\n };\n\n private _combineDataLayers(data: PanelData) {\n if (this._layerAnnotations && this._layerAnnotations.length > 0) {\n data.annotations = (data.annotations || []).concat(this._layerAnnotations);\n }\n\n if (this.state.data && this.state.data.alertState) {\n data.alertState = this.state.data.alertState;\n }\n\n return data;\n }\n\n private _setNoDataState() {\n if (this.state.data !== emptyPanelData) {\n this.setState({ data: emptyPanelData });\n }\n }\n\n /**\n * Walk up the scene graph and find any ExtraQueryProviders.\n *\n * This will return an array of the closest provider of each type.\n */\n private getClosestExtraQueryProviders(): Array<ExtraQueryProvider<any>> {\n // Maintain a map from provider constructor to provider object. The constructor\n // is used as a unique key for each class, to ensure we have no more than one\n // type of each type of provider.\n const found = new Map();\n if (!this.parent) {\n return [];\n }\n getClosest(this.parent, (s) => {\n if (isExtraQueryProvider(s) && !found.has(s.constructor)) {\n found.set(s.constructor, s);\n }\n s.forEachChild((child) => {\n if (isExtraQueryProvider(child) && !found.has(child.constructor)) {\n found.set(child.constructor, child);\n }\n });\n // Always return null so that the search continues to the top of\n // the scene graph.\n return null;\n });\n return Array.from(found.values());\n }\n\n /**\n * Walk up scene graph and find the closest filterset with matching data source\n */\n private findAndSubscribeToAdHocFilters(uid: string | undefined) {\n const filtersVar = findActiveAdHocFilterVariableByUid(uid);\n\n if (this._adhocFiltersVar !== filtersVar) {\n this._adhocFiltersVar = filtersVar;\n this._updateExplicitVariableDependencies();\n }\n\n const groupByVar = findActiveGroupByVariablesByUid(uid);\n if (this._groupByVar !== groupByVar) {\n this._groupByVar = groupByVar;\n this._updateExplicitVariableDependencies();\n }\n }\n\n private _updateExplicitVariableDependencies() {\n const explicitDependencies: string[] = [];\n\n if (this._adhocFiltersVar) {\n explicitDependencies.push(this._adhocFiltersVar.state.name);\n }\n\n if (this._groupByVar) {\n explicitDependencies.push(this._groupByVar.state.name);\n }\n\n this._variableDependency.setVariableNames(explicitDependencies);\n }\n}\n\nexport function findFirstDatasource(targets: DataQuery[]): DataSourceRef | undefined {\n return targets.find((t) => t.datasource !== null)?.datasource ?? undefined;\n}\n\nfunction allFramesEmpty(frames?: DataFrame[]) {\n if (!frames) {\n return true;\n }\n\n for (let i = 0; i < frames.length; i++) {\n if (frames[i].length > 0) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,IAAI,OAAU,GAAA,GAAA,CAAA;AAEP,SAAS,gBAAmB,GAAA;AACjC,EAAA,OAAO,KAAQ,GAAA,OAAA,EAAA,CAAA;AACjB,CAAA;AA+CO,MAAM,yBAAyB,eAA+D,CAAA;AAAA,EA0B5F,YAAY,YAAgC,EAAA;AACjD,IAAA,KAAA,CAAM,YAAY,CAAA,CAAA;AAxBpB,IAAQ,IAAA,CAAA,iBAAA,GAAoB,IAAI,gBAAiB,EAAA,CAAA;AAIjD,IAAQ,IAAA,CAAA,sBAAA,GAAyB,IAAI,qBAAsB,EAAA,CAAA;AAC3D,IAAQ,IAAA,CAAA,QAAA,GAAW,IAAI,aAAA,CAAuC,CAAC,CAAA,CAAA;AAC/D,IAAQ,IAAA,CAAA,WAAA,GAAc,EAAE,aAAe,EAAA,EAAE,OAAO,IAAM,EAAA,IAAA,EAAM,iBAAkB,EAAA,CAAA;AAW9E,IAAU,IAAA,CAAA,mBAAA,GAAkE,IAAI,wBAAA,CAAyB,IAAM,EAAA;AAAA,MAC7G,UAAA,EAAY,CAAC,SAAA,EAAW,YAAY,CAAA;AAAA,MACpC,yBAA2B,EAAA,IAAA,CAAK,0BAA2B,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,MACpE,oBAAsB,EAAA,IAAA,CAAK,oBAAqB,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,KAC1D,CAAA,CAAA;AAicD,IAAQ,IAAA,CAAA,cAAA,GAAiB,CAAC,IAAoB,KAAA;AAE5C,MAAA,MAAM,gBAAmB,GAAA,mBA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A,EAAA,CAAA;AAkqBE,EAAO,OAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,OAAA,CAAQ,IAAK,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,eAAe,IAAI,CAAA,KAAzC,IAA4C,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,UAAA,KAA5C,IAA0D,GAAA,EAAA,GAAA,KAAA,CAAA,CAAA;AACnE,CAAA;AAEA,SAAS,eAAe,MAAsB,EAAA;AAC5C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,MAAA,CAAO,QAAQ,CAAK,EAAA,EAAA;AACtC,IAAI,IAAA,MAAA,CAAO,CAAG,CAAA,CAAA,MAAA,GAAS,CAAG,EAAA;AACxB,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAAA,GACF;AAEA,EAAO,OAAA,IAAA,CAAA;AACT;;;;"}
package/dist/index.d.ts CHANGED
@@ -1329,7 +1329,7 @@ interface ExtraQueryDescriptor {
1329
1329
  }
1330
1330
  interface ExtraQueryProvider<T extends SceneObjectState> extends SceneObjectBase<T> {
1331
1331
  getExtraQueries(request: DataQueryRequest): ExtraQueryDescriptor[];
1332
- shouldRerun(prev: T, next: T): boolean;
1332
+ shouldRerun(prev: T, next: T, queries: SceneDataQuery[]): boolean;
1333
1333
  }
1334
1334
 
1335
1335
  declare abstract class SceneDataLayerSetBase<T extends SceneDataLayerProviderState> extends SceneObjectBase<T> implements SceneDataLayerProvider {
@@ -1833,7 +1833,7 @@ declare class SceneTimeRangeCompare extends SceneObjectBase<SceneTimeRangeCompar
1833
1833
  onCompareWithChanged: (compareWith: string) => void;
1834
1834
  onClearCompare: () => void;
1835
1835
  getExtraQueries(request: DataQueryRequest): ExtraQueryDescriptor[];
1836
- shouldRerun(prev: SceneTimeRangeCompareState, next: SceneTimeRangeCompareState): boolean;
1836
+ shouldRerun(prev: SceneTimeRangeCompareState, next: SceneTimeRangeCompareState, queries: SceneDataQuery[]): boolean;
1837
1837
  getCompareTimeRange(timeRange: TimeRange): TimeRange | undefined;
1838
1838
  getUrlState(): SceneObjectUrlValues;
1839
1839
  updateFromUrl(values: SceneObjectUrlValues): void;
package/dist/index.js CHANGED
@@ -4020,7 +4020,7 @@ class SceneQueryRunner extends SceneObjectBase {
4020
4020
  for (const provider of providers) {
4021
4021
  this._subs.add(
4022
4022
  provider.subscribeToState((n, p) => {
4023
- if (provider.shouldRerun(p, n)) {
4023
+ if (provider.shouldRerun(p, n, this.state.queries)) {
4024
4024
  this.runQueries();
4025
4025
  }
4026
4026
  })
@@ -9305,8 +9305,8 @@ class SceneTimeRangeCompare extends SceneObjectBase {
9305
9305
  }
9306
9306
  return extraQueries;
9307
9307
  }
9308
- shouldRerun(prev, next) {
9309
- return prev.compareWith !== next.compareWith;
9308
+ shouldRerun(prev, next, queries) {
9309
+ return prev.compareWith !== next.compareWith && queries.find((query) => query.timeRangeCompare !== false) !== void 0;
9310
9310
  }
9311
9311
  getCompareTimeRange(timeRange) {
9312
9312
  let compareFrom;