variable_srv.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. import '../all';
  2. import { VariableSrv } from '../variable_srv';
  3. import { DashboardModel } from '../../dashboard/state/DashboardModel';
  4. import $q from 'q';
  5. import { dateTime } from '@grafana/ui/src/utils/moment_wrapper';
  6. import { CustomVariable } from '../custom_variable';
  7. describe('VariableSrv', function(this: any) {
  8. const ctx = {
  9. datasourceSrv: {},
  10. timeSrv: {
  11. timeRange: () => {
  12. return { from: '2018-01-29', to: '2019-01-29' };
  13. },
  14. },
  15. $rootScope: {
  16. $on: () => {},
  17. },
  18. $injector: {
  19. instantiate: (ctr, obj) => new ctr(obj.model),
  20. },
  21. templateSrv: {
  22. setGrafanaVariable: jest.fn(),
  23. init: vars => {
  24. this.variables = vars;
  25. },
  26. updateIndex: () => {},
  27. replace: str =>
  28. str.replace(this.regex, match => {
  29. return match;
  30. }),
  31. },
  32. $location: {
  33. search: () => {},
  34. },
  35. } as any;
  36. function describeUpdateVariable(desc, fn) {
  37. describe(desc, () => {
  38. const scenario: any = {};
  39. scenario.setup = setupFn => {
  40. scenario.setupFn = setupFn;
  41. };
  42. beforeEach(async () => {
  43. scenario.setupFn();
  44. const ds: any = {};
  45. ds.metricFindQuery = () => Promise.resolve(scenario.queryResult);
  46. ctx.variableSrv = new VariableSrv($q, ctx.$location, ctx.$injector, ctx.templateSrv, ctx.timeSrv);
  47. ctx.variableSrv.timeSrv = ctx.timeSrv;
  48. ctx.datasourceSrv = {
  49. get: () => Promise.resolve(ds),
  50. getMetricSources: () => scenario.metricSources,
  51. };
  52. ctx.$injector.instantiate = (ctr, model) => {
  53. return getVarMockConstructor(ctr, model, ctx);
  54. };
  55. ctx.variableSrv.init(
  56. new DashboardModel({
  57. templating: { list: [] },
  58. updateSubmenuVisibility: () => {},
  59. })
  60. );
  61. scenario.variable = ctx.variableSrv.createVariableFromModel(scenario.variableModel);
  62. ctx.variableSrv.addVariable(scenario.variable);
  63. await ctx.variableSrv.updateOptions(scenario.variable);
  64. });
  65. fn(scenario);
  66. });
  67. }
  68. describeUpdateVariable('interval variable without auto', scenario => {
  69. scenario.setup(() => {
  70. scenario.variableModel = {
  71. type: 'interval',
  72. query: '1s,2h,5h,1d',
  73. name: 'test',
  74. };
  75. });
  76. it('should update options array', () => {
  77. expect(scenario.variable.options.length).toBe(4);
  78. expect(scenario.variable.options[0].text).toBe('1s');
  79. expect(scenario.variable.options[0].value).toBe('1s');
  80. });
  81. });
  82. //
  83. // Interval variable update
  84. //
  85. describeUpdateVariable('interval variable with auto', scenario => {
  86. scenario.setup(() => {
  87. scenario.variableModel = {
  88. type: 'interval',
  89. query: '1s,2h,5h,1d',
  90. name: 'test',
  91. auto: true,
  92. auto_count: 10,
  93. };
  94. const range = {
  95. from: dateTime(new Date())
  96. .subtract(7, 'days')
  97. .toDate(),
  98. to: new Date(),
  99. };
  100. ctx.timeSrv.timeRange = () => range;
  101. // ctx.templateSrv.setGrafanaVariable = jest.fn();
  102. });
  103. it('should update options array', () => {
  104. expect(scenario.variable.options.length).toBe(5);
  105. expect(scenario.variable.options[0].text).toBe('auto');
  106. expect(scenario.variable.options[0].value).toBe('$__auto_interval_test');
  107. });
  108. it('should set $__auto_interval_test', () => {
  109. const call = ctx.templateSrv.setGrafanaVariable.mock.calls[0];
  110. expect(call[0]).toBe('$__auto_interval_test');
  111. expect(call[1]).toBe('12h');
  112. });
  113. // updateAutoValue() gets called twice: once directly once via VariableSrv.validateVariableSelectionState()
  114. // So use lastCall instead of a specific call number
  115. it('should set $__auto_interval', () => {
  116. const call = ctx.templateSrv.setGrafanaVariable.mock.calls.pop();
  117. expect(call[0]).toBe('$__auto_interval');
  118. expect(call[1]).toBe('12h');
  119. });
  120. });
  121. //
  122. // Query variable update
  123. //
  124. describeUpdateVariable('query variable with empty current object and refresh', scenario => {
  125. scenario.setup(() => {
  126. scenario.variableModel = {
  127. type: 'query',
  128. query: '',
  129. name: 'test',
  130. current: {},
  131. };
  132. scenario.queryResult = [{ text: 'backend1' }, { text: 'backend2' }];
  133. });
  134. it('should set current value to first option', () => {
  135. expect(scenario.variable.options.length).toBe(2);
  136. expect(scenario.variable.current.value).toBe('backend1');
  137. });
  138. });
  139. describeUpdateVariable(
  140. 'query variable with multi select and new options does not contain some selected values',
  141. scenario => {
  142. scenario.setup(() => {
  143. scenario.variableModel = {
  144. type: 'query',
  145. query: '',
  146. name: 'test',
  147. current: {
  148. value: ['val1', 'val2', 'val3'],
  149. text: 'val1 + val2 + val3',
  150. },
  151. };
  152. scenario.queryResult = [{ text: 'val2' }, { text: 'val3' }];
  153. });
  154. it('should update current value', () => {
  155. expect(scenario.variable.current.value).toEqual(['val2', 'val3']);
  156. expect(scenario.variable.current.text).toEqual('val2 + val3');
  157. });
  158. }
  159. );
  160. describeUpdateVariable(
  161. 'query variable with multi select and new options does not contain any selected values',
  162. scenario => {
  163. scenario.setup(() => {
  164. scenario.variableModel = {
  165. type: 'query',
  166. query: '',
  167. name: 'test',
  168. current: {
  169. value: ['val1', 'val2', 'val3'],
  170. text: 'val1 + val2 + val3',
  171. },
  172. };
  173. scenario.queryResult = [{ text: 'val5' }, { text: 'val6' }];
  174. });
  175. it('should update current value with first one', () => {
  176. expect(scenario.variable.current.value).toEqual('val5');
  177. expect(scenario.variable.current.text).toEqual('val5');
  178. });
  179. }
  180. );
  181. describeUpdateVariable('query variable with multi select and $__all selected', scenario => {
  182. scenario.setup(() => {
  183. scenario.variableModel = {
  184. type: 'query',
  185. query: '',
  186. name: 'test',
  187. includeAll: true,
  188. current: {
  189. value: ['$__all'],
  190. text: 'All',
  191. },
  192. };
  193. scenario.queryResult = [{ text: 'val5' }, { text: 'val6' }];
  194. });
  195. it('should keep current All value', () => {
  196. expect(scenario.variable.current.value).toEqual(['$__all']);
  197. expect(scenario.variable.current.text).toEqual('All');
  198. });
  199. });
  200. describeUpdateVariable('query variable with numeric results', scenario => {
  201. scenario.setup(() => {
  202. scenario.variableModel = {
  203. type: 'query',
  204. query: '',
  205. name: 'test',
  206. current: {},
  207. };
  208. scenario.queryResult = [{ text: 12, value: 12 }];
  209. });
  210. it('should set current value to first option', () => {
  211. expect(scenario.variable.current.value).toBe('12');
  212. expect(scenario.variable.options[0].value).toBe('12');
  213. expect(scenario.variable.options[0].text).toBe('12');
  214. });
  215. });
  216. describeUpdateVariable('basic query variable', scenario => {
  217. scenario.setup(() => {
  218. scenario.variableModel = { type: 'query', query: 'apps.*', name: 'test' };
  219. scenario.queryResult = [{ text: 'backend1' }, { text: 'backend2' }];
  220. });
  221. it('should update options array', () => {
  222. expect(scenario.variable.options.length).toBe(2);
  223. expect(scenario.variable.options[0].text).toBe('backend1');
  224. expect(scenario.variable.options[0].value).toBe('backend1');
  225. expect(scenario.variable.options[1].value).toBe('backend2');
  226. });
  227. it('should select first option as value', () => {
  228. expect(scenario.variable.current.value).toBe('backend1');
  229. });
  230. });
  231. describeUpdateVariable('and existing value still exists in options', scenario => {
  232. scenario.setup(() => {
  233. scenario.variableModel = { type: 'query', query: 'apps.*', name: 'test' };
  234. scenario.variableModel.current = { value: 'backend2', text: 'backend2' };
  235. scenario.queryResult = [{ text: 'backend1' }, { text: 'backend2' }];
  236. });
  237. it('should keep variable value', () => {
  238. expect(scenario.variable.current.text).toBe('backend2');
  239. });
  240. });
  241. describeUpdateVariable('and regex pattern exists', scenario => {
  242. scenario.setup(() => {
  243. scenario.variableModel = { type: 'query', query: 'apps.*', name: 'test' };
  244. scenario.variableModel.regex = '/apps.*(backend_[0-9]+)/';
  245. scenario.queryResult = [
  246. { text: 'apps.backend.backend_01.counters.req' },
  247. { text: 'apps.backend.backend_02.counters.req' },
  248. ];
  249. });
  250. it('should extract and use match group', () => {
  251. expect(scenario.variable.options[0].value).toBe('backend_01');
  252. });
  253. });
  254. describeUpdateVariable('and regex pattern exists and no match', scenario => {
  255. scenario.setup(() => {
  256. scenario.variableModel = { type: 'query', query: 'apps.*', name: 'test' };
  257. scenario.variableModel.regex = '/apps.*(backendasd[0-9]+)/';
  258. scenario.queryResult = [
  259. { text: 'apps.backend.backend_01.counters.req' },
  260. { text: 'apps.backend.backend_02.counters.req' },
  261. ];
  262. });
  263. it('should not add non matching items, None option should be added instead', () => {
  264. expect(scenario.variable.options.length).toBe(1);
  265. expect(scenario.variable.options[0].isNone).toBe(true);
  266. });
  267. });
  268. describeUpdateVariable('regex pattern without slashes', scenario => {
  269. scenario.setup(() => {
  270. scenario.variableModel = { type: 'query', query: 'apps.*', name: 'test' };
  271. scenario.variableModel.regex = 'backend_01';
  272. scenario.queryResult = [
  273. { text: 'apps.backend.backend_01.counters.req' },
  274. { text: 'apps.backend.backend_02.counters.req' },
  275. ];
  276. });
  277. it('should return matches options', () => {
  278. expect(scenario.variable.options.length).toBe(1);
  279. });
  280. });
  281. describeUpdateVariable('regex pattern remove duplicates', scenario => {
  282. scenario.setup(() => {
  283. scenario.variableModel = { type: 'query', query: 'apps.*', name: 'test' };
  284. scenario.variableModel.regex = '/backend_01/';
  285. scenario.queryResult = [
  286. { text: 'apps.backend.backend_01.counters.req' },
  287. { text: 'apps.backend.backend_01.counters.req' },
  288. ];
  289. });
  290. it('should return matches options', () => {
  291. expect(scenario.variable.options.length).toBe(1);
  292. });
  293. });
  294. describeUpdateVariable('with include All', scenario => {
  295. scenario.setup(() => {
  296. scenario.variableModel = {
  297. type: 'query',
  298. query: 'apps.*',
  299. name: 'test',
  300. includeAll: true,
  301. };
  302. scenario.queryResult = [{ text: 'backend1' }, { text: 'backend2' }, { text: 'backend3' }];
  303. });
  304. it('should add All option', () => {
  305. expect(scenario.variable.options[0].text).toBe('All');
  306. expect(scenario.variable.options[0].value).toBe('$__all');
  307. });
  308. });
  309. describeUpdateVariable('with include all and custom value', scenario => {
  310. scenario.setup(() => {
  311. scenario.variableModel = {
  312. type: 'query',
  313. query: 'apps.*',
  314. name: 'test',
  315. includeAll: true,
  316. allValue: '*',
  317. };
  318. scenario.queryResult = [{ text: 'backend1' }, { text: 'backend2' }, { text: 'backend3' }];
  319. });
  320. it('should add All option with custom value', () => {
  321. expect(scenario.variable.options[0].value).toBe('$__all');
  322. });
  323. });
  324. describeUpdateVariable('without sort', scenario => {
  325. scenario.setup(() => {
  326. scenario.variableModel = {
  327. type: 'query',
  328. query: 'apps.*',
  329. name: 'test',
  330. sort: 0,
  331. };
  332. scenario.queryResult = [{ text: 'bbb2' }, { text: 'aaa10' }, { text: 'ccc3' }];
  333. });
  334. it('should return options without sort', () => {
  335. expect(scenario.variable.options[0].text).toBe('bbb2');
  336. expect(scenario.variable.options[1].text).toBe('aaa10');
  337. expect(scenario.variable.options[2].text).toBe('ccc3');
  338. });
  339. });
  340. describeUpdateVariable('with alphabetical sort (asc)', scenario => {
  341. scenario.setup(() => {
  342. scenario.variableModel = {
  343. type: 'query',
  344. query: 'apps.*',
  345. name: 'test',
  346. sort: 1,
  347. };
  348. scenario.queryResult = [{ text: 'bbb2' }, { text: 'aaa10' }, { text: 'ccc3' }];
  349. });
  350. it('should return options with alphabetical sort', () => {
  351. expect(scenario.variable.options[0].text).toBe('aaa10');
  352. expect(scenario.variable.options[1].text).toBe('bbb2');
  353. expect(scenario.variable.options[2].text).toBe('ccc3');
  354. });
  355. });
  356. describeUpdateVariable('with alphabetical sort (desc)', scenario => {
  357. scenario.setup(() => {
  358. scenario.variableModel = {
  359. type: 'query',
  360. query: 'apps.*',
  361. name: 'test',
  362. sort: 2,
  363. };
  364. scenario.queryResult = [{ text: 'bbb2' }, { text: 'aaa10' }, { text: 'ccc3' }];
  365. });
  366. it('should return options with alphabetical sort', () => {
  367. expect(scenario.variable.options[0].text).toBe('ccc3');
  368. expect(scenario.variable.options[1].text).toBe('bbb2');
  369. expect(scenario.variable.options[2].text).toBe('aaa10');
  370. });
  371. });
  372. describeUpdateVariable('with numerical sort (asc)', scenario => {
  373. scenario.setup(() => {
  374. scenario.variableModel = {
  375. type: 'query',
  376. query: 'apps.*',
  377. name: 'test',
  378. sort: 3,
  379. };
  380. scenario.queryResult = [{ text: 'bbb2' }, { text: 'aaa10' }, { text: 'ccc3' }];
  381. });
  382. it('should return options with numerical sort', () => {
  383. expect(scenario.variable.options[0].text).toBe('bbb2');
  384. expect(scenario.variable.options[1].text).toBe('ccc3');
  385. expect(scenario.variable.options[2].text).toBe('aaa10');
  386. });
  387. });
  388. describeUpdateVariable('with numerical sort (desc)', scenario => {
  389. scenario.setup(() => {
  390. scenario.variableModel = {
  391. type: 'query',
  392. query: 'apps.*',
  393. name: 'test',
  394. sort: 4,
  395. };
  396. scenario.queryResult = [{ text: 'bbb2' }, { text: 'aaa10' }, { text: 'ccc3' }];
  397. });
  398. it('should return options with numerical sort', () => {
  399. expect(scenario.variable.options[0].text).toBe('aaa10');
  400. expect(scenario.variable.options[1].text).toBe('ccc3');
  401. expect(scenario.variable.options[2].text).toBe('bbb2');
  402. });
  403. });
  404. //
  405. // datasource variable update
  406. //
  407. describeUpdateVariable('datasource variable with regex filter', scenario => {
  408. scenario.setup(() => {
  409. scenario.variableModel = {
  410. type: 'datasource',
  411. query: 'graphite',
  412. name: 'test',
  413. current: { value: 'backend4_pee', text: 'backend4_pee' },
  414. regex: '/pee$/',
  415. };
  416. scenario.metricSources = [
  417. { name: 'backend1', meta: { id: 'influx' } },
  418. { name: 'backend2_pee', meta: { id: 'graphite' } },
  419. { name: 'backend3', meta: { id: 'graphite' } },
  420. { name: 'backend4_pee', meta: { id: 'graphite' } },
  421. ];
  422. });
  423. it('should set only contain graphite ds and filtered using regex', () => {
  424. expect(scenario.variable.options.length).toBe(2);
  425. expect(scenario.variable.options[0].value).toBe('backend2_pee');
  426. expect(scenario.variable.options[1].value).toBe('backend4_pee');
  427. });
  428. it('should keep current value if available', () => {
  429. expect(scenario.variable.current.value).toBe('backend4_pee');
  430. });
  431. });
  432. //
  433. // Custom variable update
  434. //
  435. describeUpdateVariable('update custom variable', scenario => {
  436. scenario.setup(() => {
  437. scenario.variableModel = {
  438. type: 'custom',
  439. query: 'hej, hop, asd, escaped\\,var',
  440. name: 'test',
  441. };
  442. });
  443. it('should update options array', () => {
  444. expect(scenario.variable.options.length).toBe(4);
  445. expect(scenario.variable.options[0].text).toBe('hej');
  446. expect(scenario.variable.options[1].value).toBe('hop');
  447. expect(scenario.variable.options[2].value).toBe('asd');
  448. expect(scenario.variable.options[3].value).toBe('escaped,var');
  449. });
  450. });
  451. describe('multiple interval variables with auto', () => {
  452. let variable1, variable2;
  453. beforeEach(() => {
  454. const range = {
  455. from: dateTime(new Date())
  456. .subtract(7, 'days')
  457. .toDate(),
  458. to: new Date(),
  459. };
  460. ctx.timeSrv.timeRange = () => range;
  461. ctx.templateSrv.setGrafanaVariable = jest.fn();
  462. const variableModel1 = {
  463. type: 'interval',
  464. query: '1s,2h,5h,1d',
  465. name: 'variable1',
  466. auto: true,
  467. auto_count: 10,
  468. };
  469. variable1 = ctx.variableSrv.createVariableFromModel(variableModel1);
  470. ctx.variableSrv.addVariable(variable1);
  471. const variableModel2 = {
  472. type: 'interval',
  473. query: '1s,2h,5h',
  474. name: 'variable2',
  475. auto: true,
  476. auto_count: 1000,
  477. };
  478. variable2 = ctx.variableSrv.createVariableFromModel(variableModel2);
  479. ctx.variableSrv.addVariable(variable2);
  480. ctx.variableSrv.updateOptions(variable1);
  481. ctx.variableSrv.updateOptions(variable2);
  482. // ctx.$rootScope.$digest();
  483. });
  484. it('should update options array', () => {
  485. expect(variable1.options.length).toBe(5);
  486. expect(variable1.options[0].text).toBe('auto');
  487. expect(variable1.options[0].value).toBe('$__auto_interval_variable1');
  488. expect(variable2.options.length).toBe(4);
  489. expect(variable2.options[0].text).toBe('auto');
  490. expect(variable2.options[0].value).toBe('$__auto_interval_variable2');
  491. });
  492. it('should correctly set $__auto_interval_variableX', () => {
  493. let variable1Set,
  494. variable2Set,
  495. legacySet,
  496. unknownSet = false;
  497. // updateAutoValue() gets called repeatedly: once directly once via VariableSrv.validateVariableSelectionState()
  498. // So check that all calls are valid rather than expect a specific number and/or ordering of calls
  499. for (let i = 0; i < ctx.templateSrv.setGrafanaVariable.mock.calls.length; i++) {
  500. const call = ctx.templateSrv.setGrafanaVariable.mock.calls[i];
  501. switch (call[0]) {
  502. case '$__auto_interval_variable1':
  503. expect(call[1]).toBe('12h');
  504. variable1Set = true;
  505. break;
  506. case '$__auto_interval_variable2':
  507. expect(call[1]).toBe('10m');
  508. variable2Set = true;
  509. break;
  510. case '$__auto_interval':
  511. expect(call[1]).toEqual(expect.stringMatching(/^(12h|10m)$/));
  512. legacySet = true;
  513. break;
  514. default:
  515. unknownSet = true;
  516. break;
  517. }
  518. }
  519. expect(variable1Set).toEqual(true);
  520. expect(variable2Set).toEqual(true);
  521. expect(legacySet).toEqual(true);
  522. expect(unknownSet).toEqual(false);
  523. });
  524. });
  525. describe('setOptionFromUrl', () => {
  526. it('sets single value as string if not multi choice', async () => {
  527. const [setValueMock, setFromUrl] = setupSetFromUrlTest(ctx);
  528. await setFromUrl('one');
  529. expect(setValueMock).toHaveBeenCalledWith({ text: 'one', value: 'one' });
  530. });
  531. it('sets single value as array if multi choice', async () => {
  532. const [setValueMock, setFromUrl] = setupSetFromUrlTest(ctx, { multi: true });
  533. await setFromUrl('one');
  534. expect(setValueMock).toHaveBeenCalledWith({ text: 'one', value: ['one'] });
  535. });
  536. it('sets both text and value as array if multiple values in url', async () => {
  537. const [setValueMock, setFromUrl] = setupSetFromUrlTest(ctx, { multi: true });
  538. await setFromUrl(['one', 'two']);
  539. expect(setValueMock).toHaveBeenCalledWith({ text: ['one', 'two'], value: ['one', 'two'] });
  540. });
  541. it('sets text and value even if it does not match any option', async () => {
  542. const [setValueMock, setFromUrl] = setupSetFromUrlTest(ctx);
  543. await setFromUrl('none');
  544. expect(setValueMock).toHaveBeenCalledWith({ text: 'none', value: 'none' });
  545. });
  546. it('sets text and value even if it does not match any option and it is array', async () => {
  547. const [setValueMock, setFromUrl] = setupSetFromUrlTest(ctx);
  548. await setFromUrl(['none', 'none2']);
  549. expect(setValueMock).toHaveBeenCalledWith({ text: ['none', 'none2'], value: ['none', 'none2'] });
  550. });
  551. });
  552. });
  553. function setupSetFromUrlTest(ctx, model = {}) {
  554. const variableSrv = new VariableSrv($q, ctx.$location, ctx.$injector, ctx.templateSrv, ctx.timeSrv);
  555. const finalModel = {
  556. type: 'custom',
  557. options: ['one', 'two', 'three'].map(v => ({ text: v, value: v })),
  558. name: 'test',
  559. ...model,
  560. };
  561. const variable = new CustomVariable(finalModel, variableSrv);
  562. // We are mocking the setValue here instead of just checking the final variable.current value because there is lots
  563. // of stuff going when the setValue is called that is hard to mock out.
  564. variable.setValue = jest.fn();
  565. return [variable.setValue, val => variableSrv.setOptionFromUrl(variable, val)];
  566. }
  567. function getVarMockConstructor(variable, model, ctx) {
  568. switch (model.model.type) {
  569. case 'datasource':
  570. return new variable(model.model, ctx.datasourceSrv, ctx.variableSrv, ctx.templateSrv);
  571. case 'query':
  572. return new variable(model.model, ctx.datasourceSrv, ctx.templateSrv, ctx.variableSrv);
  573. case 'interval':
  574. return new variable(model.model, ctx.timeSrv, ctx.templateSrv, ctx.variableSrv);
  575. case 'custom':
  576. return new variable(model.model, ctx.variableSrv);
  577. default:
  578. return new variable(model.model);
  579. }
  580. }