query_ctrl.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. import _ from 'lodash';
  2. import appEvents from 'app/core/app_events';
  3. import { PostgresMetaQuery } from './meta_query';
  4. import { QueryCtrl } from 'app/plugins/sdk';
  5. import { SqlPart } from 'app/core/components/sql_part/sql_part';
  6. import PostgresQuery from './postgres_query';
  7. import sqlPart from './sql_part';
  8. import { auto, IQService } from 'angular';
  9. import { TemplateSrv } from 'app/features/templating/template_srv';
  10. export interface QueryMeta {
  11. sql: string;
  12. }
  13. const defaultQuery = `SELECT
  14. $__time(time_column),
  15. value1
  16. FROM
  17. metric_table
  18. WHERE
  19. $__timeFilter(time_column)
  20. `;
  21. export class PostgresQueryCtrl extends QueryCtrl {
  22. static templateUrl = 'partials/query.editor.html';
  23. showLastQuerySQL: boolean;
  24. formats: any[];
  25. queryModel: PostgresQuery;
  26. metaBuilder: PostgresMetaQuery;
  27. lastQueryMeta: QueryMeta;
  28. lastQueryError: string;
  29. showHelp: boolean;
  30. tableSegment: any;
  31. whereAdd: any;
  32. timeColumnSegment: any;
  33. metricColumnSegment: any;
  34. selectMenu: any[];
  35. selectParts: SqlPart[][];
  36. groupParts: SqlPart[];
  37. whereParts: SqlPart[];
  38. groupAdd: any;
  39. /** @ngInject */
  40. constructor(
  41. $scope: any,
  42. $injector: auto.IInjectorService,
  43. private templateSrv: TemplateSrv,
  44. private $q: IQService,
  45. private uiSegmentSrv: any
  46. ) {
  47. super($scope, $injector);
  48. this.target = this.target;
  49. this.queryModel = new PostgresQuery(this.target, templateSrv, this.panel.scopedVars);
  50. this.metaBuilder = new PostgresMetaQuery(this.target, this.queryModel);
  51. this.updateProjection();
  52. this.formats = [{ text: 'Time series', value: 'time_series' }, { text: 'Table', value: 'table' }];
  53. if (!this.target.rawSql) {
  54. // special handling when in table panel
  55. if (this.panelCtrl.panel.type === 'table') {
  56. this.target.format = 'table';
  57. this.target.rawSql = 'SELECT 1';
  58. this.target.rawQuery = true;
  59. } else {
  60. this.target.rawSql = defaultQuery;
  61. this.datasource.metricFindQuery(this.metaBuilder.findMetricTable()).then((result: any) => {
  62. if (result.length > 0) {
  63. this.target.table = result[0].text;
  64. let segment = this.uiSegmentSrv.newSegment(this.target.table);
  65. this.tableSegment.html = segment.html;
  66. this.tableSegment.value = segment.value;
  67. this.target.timeColumn = result[1].text;
  68. segment = this.uiSegmentSrv.newSegment(this.target.timeColumn);
  69. this.timeColumnSegment.html = segment.html;
  70. this.timeColumnSegment.value = segment.value;
  71. this.target.timeColumnType = 'timestamp';
  72. this.target.select = [[{ type: 'column', params: [result[2].text] }]];
  73. this.updateProjection();
  74. this.panelCtrl.refresh();
  75. }
  76. });
  77. }
  78. }
  79. if (!this.target.table) {
  80. this.tableSegment = uiSegmentSrv.newSegment({ value: 'select table', fake: true });
  81. } else {
  82. this.tableSegment = uiSegmentSrv.newSegment(this.target.table);
  83. }
  84. this.timeColumnSegment = uiSegmentSrv.newSegment(this.target.timeColumn);
  85. this.metricColumnSegment = uiSegmentSrv.newSegment(this.target.metricColumn);
  86. this.buildSelectMenu();
  87. this.whereAdd = this.uiSegmentSrv.newPlusButton();
  88. this.groupAdd = this.uiSegmentSrv.newPlusButton();
  89. this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
  90. this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
  91. }
  92. updateProjection() {
  93. this.selectParts = _.map(this.target.select, (parts: any) => {
  94. return _.map(parts, sqlPart.create).filter(n => n);
  95. });
  96. this.whereParts = _.map(this.target.where, sqlPart.create).filter(n => n);
  97. this.groupParts = _.map(this.target.group, sqlPart.create).filter(n => n);
  98. }
  99. updatePersistedParts() {
  100. this.target.select = _.map(this.selectParts, selectParts => {
  101. return _.map(selectParts, (part: any) => {
  102. return { type: part.def.type, datatype: part.datatype, params: part.params };
  103. });
  104. });
  105. this.target.where = _.map(this.whereParts, (part: any) => {
  106. return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params };
  107. });
  108. this.target.group = _.map(this.groupParts, (part: any) => {
  109. return { type: part.def.type, datatype: part.datatype, params: part.params };
  110. });
  111. }
  112. buildSelectMenu() {
  113. this.selectMenu = [];
  114. const aggregates = {
  115. text: 'Aggregate Functions',
  116. value: 'aggregate',
  117. submenu: [
  118. { text: 'Average', value: 'avg' },
  119. { text: 'Count', value: 'count' },
  120. { text: 'Maximum', value: 'max' },
  121. { text: 'Minimum', value: 'min' },
  122. { text: 'Sum', value: 'sum' },
  123. { text: 'Standard deviation', value: 'stddev' },
  124. { text: 'Variance', value: 'variance' },
  125. ],
  126. };
  127. // first and last aggregate are timescaledb specific
  128. if (this.datasource.jsonData.timescaledb === true) {
  129. aggregates.submenu.push({ text: 'First', value: 'first' });
  130. aggregates.submenu.push({ text: 'Last', value: 'last' });
  131. }
  132. this.selectMenu.push(aggregates);
  133. // ordered set aggregates require postgres 9.4+
  134. if (this.datasource.jsonData.postgresVersion >= 904) {
  135. const aggregates2 = {
  136. text: 'Ordered-Set Aggregate Functions',
  137. value: 'percentile',
  138. submenu: [
  139. { text: 'Percentile (continuous)', value: 'percentile_cont' },
  140. { text: 'Percentile (discrete)', value: 'percentile_disc' },
  141. ],
  142. };
  143. this.selectMenu.push(aggregates2);
  144. }
  145. const windows = {
  146. text: 'Window Functions',
  147. value: 'window',
  148. submenu: [
  149. { text: 'Delta', value: 'delta' },
  150. { text: 'Increase', value: 'increase' },
  151. { text: 'Rate', value: 'rate' },
  152. { text: 'Sum', value: 'sum' },
  153. { text: 'Moving Average', value: 'avg', type: 'moving_window' },
  154. ],
  155. };
  156. this.selectMenu.push(windows);
  157. this.selectMenu.push({ text: 'Alias', value: 'alias' });
  158. this.selectMenu.push({ text: 'Column', value: 'column' });
  159. }
  160. toggleEditorMode() {
  161. if (this.target.rawQuery) {
  162. appEvents.emit('confirm-modal', {
  163. title: 'Warning',
  164. text2: 'Switching to query builder may overwrite your raw SQL.',
  165. icon: 'fa-exclamation',
  166. yesText: 'Switch',
  167. onConfirm: () => {
  168. this.target.rawQuery = !this.target.rawQuery;
  169. },
  170. });
  171. } else {
  172. this.target.rawQuery = !this.target.rawQuery;
  173. }
  174. }
  175. resetPlusButton(button: { html: any; value: any }) {
  176. const plusButton = this.uiSegmentSrv.newPlusButton();
  177. button.html = plusButton.html;
  178. button.value = plusButton.value;
  179. }
  180. getTableSegments() {
  181. return this.datasource
  182. .metricFindQuery(this.metaBuilder.buildTableQuery())
  183. .then(this.transformToSegments({}))
  184. .catch(this.handleQueryError.bind(this));
  185. }
  186. tableChanged() {
  187. this.target.table = this.tableSegment.value;
  188. this.target.where = [];
  189. this.target.group = [];
  190. this.updateProjection();
  191. const segment = this.uiSegmentSrv.newSegment('none');
  192. this.metricColumnSegment.html = segment.html;
  193. this.metricColumnSegment.value = segment.value;
  194. this.target.metricColumn = 'none';
  195. const task1 = this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery('time')).then((result: any) => {
  196. // check if time column is still valid
  197. if (result.length > 0 && !_.find(result, (r: any) => r.text === this.target.timeColumn)) {
  198. const segment = this.uiSegmentSrv.newSegment(result[0].text);
  199. this.timeColumnSegment.html = segment.html;
  200. this.timeColumnSegment.value = segment.value;
  201. }
  202. return this.timeColumnChanged(false);
  203. });
  204. const task2 = this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery('value')).then((result: any) => {
  205. if (result.length > 0) {
  206. this.target.select = [[{ type: 'column', params: [result[0].text] }]];
  207. this.updateProjection();
  208. }
  209. });
  210. this.$q.all([task1, task2]).then(() => {
  211. this.panelCtrl.refresh();
  212. });
  213. }
  214. getTimeColumnSegments() {
  215. return this.datasource
  216. .metricFindQuery(this.metaBuilder.buildColumnQuery('time'))
  217. .then(this.transformToSegments({}))
  218. .catch(this.handleQueryError.bind(this));
  219. }
  220. timeColumnChanged(refresh?: boolean) {
  221. this.target.timeColumn = this.timeColumnSegment.value;
  222. return this.datasource
  223. .metricFindQuery(this.metaBuilder.buildDatatypeQuery(this.target.timeColumn))
  224. .then((result: any) => {
  225. if (result.length === 1) {
  226. if (this.target.timeColumnType !== result[0].text) {
  227. this.target.timeColumnType = result[0].text;
  228. }
  229. let partModel;
  230. if (this.queryModel.hasUnixEpochTimecolumn()) {
  231. partModel = sqlPart.create({ type: 'macro', name: '$__unixEpochFilter', params: [] });
  232. } else {
  233. partModel = sqlPart.create({ type: 'macro', name: '$__timeFilter', params: [] });
  234. }
  235. if (this.whereParts.length >= 1 && this.whereParts[0].def.type === 'macro') {
  236. // replace current macro
  237. this.whereParts[0] = partModel;
  238. } else {
  239. this.whereParts.splice(0, 0, partModel);
  240. }
  241. }
  242. this.updatePersistedParts();
  243. if (refresh !== false) {
  244. this.panelCtrl.refresh();
  245. }
  246. });
  247. }
  248. getMetricColumnSegments() {
  249. return this.datasource
  250. .metricFindQuery(this.metaBuilder.buildColumnQuery('metric'))
  251. .then(this.transformToSegments({ addNone: true }))
  252. .catch(this.handleQueryError.bind(this));
  253. }
  254. metricColumnChanged() {
  255. this.target.metricColumn = this.metricColumnSegment.value;
  256. this.panelCtrl.refresh();
  257. }
  258. onDataReceived(dataList: any) {
  259. this.lastQueryMeta = null;
  260. this.lastQueryError = null;
  261. const anySeriesFromQuery: any = _.find(dataList, { refId: this.target.refId });
  262. if (anySeriesFromQuery) {
  263. this.lastQueryMeta = anySeriesFromQuery.meta;
  264. }
  265. }
  266. onDataError(err: any) {
  267. if (err.data && err.data.results) {
  268. const queryRes = err.data.results[this.target.refId];
  269. if (queryRes) {
  270. this.lastQueryMeta = queryRes.meta;
  271. this.lastQueryError = queryRes.error;
  272. }
  273. }
  274. }
  275. transformToSegments(config: { addNone?: any; addTemplateVars?: any; templateQuoter?: any }) {
  276. return (results: any) => {
  277. const segments = _.map(results, segment => {
  278. return this.uiSegmentSrv.newSegment({
  279. value: segment.text,
  280. expandable: segment.expandable,
  281. });
  282. });
  283. if (config.addTemplateVars) {
  284. for (const variable of this.templateSrv.variables) {
  285. let value;
  286. value = '$' + variable.name;
  287. if (config.templateQuoter && variable.multi === false) {
  288. value = config.templateQuoter(value);
  289. }
  290. segments.unshift(
  291. this.uiSegmentSrv.newSegment({
  292. type: 'template',
  293. value: value,
  294. expandable: true,
  295. })
  296. );
  297. }
  298. }
  299. if (config.addNone) {
  300. segments.unshift(this.uiSegmentSrv.newSegment({ type: 'template', value: 'none', expandable: true }));
  301. }
  302. return segments;
  303. };
  304. }
  305. findAggregateIndex(selectParts: any) {
  306. return _.findIndex(selectParts, (p: any) => p.def.type === 'aggregate' || p.def.type === 'percentile');
  307. }
  308. findWindowIndex(selectParts: any) {
  309. return _.findIndex(selectParts, (p: any) => p.def.type === 'window' || p.def.type === 'moving_window');
  310. }
  311. addSelectPart(selectParts: any[], item: { value: any }, subItem: { type: any; value: any }) {
  312. let partType = item.value;
  313. if (subItem && subItem.type) {
  314. partType = subItem.type;
  315. }
  316. let partModel = sqlPart.create({ type: partType });
  317. if (subItem) {
  318. partModel.params[0] = subItem.value;
  319. }
  320. let addAlias = false;
  321. switch (partType) {
  322. case 'column':
  323. const parts = _.map(selectParts, (part: any) => {
  324. return sqlPart.create({ type: part.def.type, params: _.clone(part.params) });
  325. });
  326. this.selectParts.push(parts);
  327. break;
  328. case 'percentile':
  329. case 'aggregate':
  330. // add group by if no group by yet
  331. if (this.target.group.length === 0) {
  332. this.addGroup('time', '$__interval');
  333. }
  334. const aggIndex = this.findAggregateIndex(selectParts);
  335. if (aggIndex !== -1) {
  336. // replace current aggregation
  337. selectParts[aggIndex] = partModel;
  338. } else {
  339. selectParts.splice(1, 0, partModel);
  340. }
  341. if (!_.find(selectParts, (p: any) => p.def.type === 'alias')) {
  342. addAlias = true;
  343. }
  344. break;
  345. case 'moving_window':
  346. case 'window':
  347. const windowIndex = this.findWindowIndex(selectParts);
  348. if (windowIndex !== -1) {
  349. // replace current window function
  350. selectParts[windowIndex] = partModel;
  351. } else {
  352. const aggIndex = this.findAggregateIndex(selectParts);
  353. if (aggIndex !== -1) {
  354. selectParts.splice(aggIndex + 1, 0, partModel);
  355. } else {
  356. selectParts.splice(1, 0, partModel);
  357. }
  358. }
  359. if (!_.find(selectParts, (p: any) => p.def.type === 'alias')) {
  360. addAlias = true;
  361. }
  362. break;
  363. case 'alias':
  364. addAlias = true;
  365. break;
  366. }
  367. if (addAlias) {
  368. // set initial alias name to column name
  369. partModel = sqlPart.create({ type: 'alias', params: [selectParts[0].params[0].replace(/"/g, '')] });
  370. if (selectParts[selectParts.length - 1].def.type === 'alias') {
  371. selectParts[selectParts.length - 1] = partModel;
  372. } else {
  373. selectParts.push(partModel);
  374. }
  375. }
  376. this.updatePersistedParts();
  377. this.panelCtrl.refresh();
  378. }
  379. removeSelectPart(selectParts: any, part: { def: { type: string } }) {
  380. if (part.def.type === 'column') {
  381. // remove all parts of column unless its last column
  382. if (this.selectParts.length > 1) {
  383. const modelsIndex = _.indexOf(this.selectParts, selectParts);
  384. this.selectParts.splice(modelsIndex, 1);
  385. }
  386. } else {
  387. const partIndex = _.indexOf(selectParts, part);
  388. selectParts.splice(partIndex, 1);
  389. }
  390. this.updatePersistedParts();
  391. }
  392. handleSelectPartEvent(selectParts: any, part: { def: any }, evt: { name: any }) {
  393. switch (evt.name) {
  394. case 'get-param-options': {
  395. switch (part.def.type) {
  396. case 'aggregate':
  397. return this.datasource
  398. .metricFindQuery(this.metaBuilder.buildAggregateQuery())
  399. .then(this.transformToSegments({}))
  400. .catch(this.handleQueryError.bind(this));
  401. case 'column':
  402. return this.datasource
  403. .metricFindQuery(this.metaBuilder.buildColumnQuery('value'))
  404. .then(this.transformToSegments({}))
  405. .catch(this.handleQueryError.bind(this));
  406. }
  407. }
  408. case 'part-param-changed': {
  409. this.updatePersistedParts();
  410. this.panelCtrl.refresh();
  411. break;
  412. }
  413. case 'action': {
  414. this.removeSelectPart(selectParts, part);
  415. this.panelCtrl.refresh();
  416. break;
  417. }
  418. case 'get-part-actions': {
  419. return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
  420. }
  421. }
  422. }
  423. handleGroupPartEvent(part: any, index: any, evt: { name: any }) {
  424. switch (evt.name) {
  425. case 'get-param-options': {
  426. return this.datasource
  427. .metricFindQuery(this.metaBuilder.buildColumnQuery())
  428. .then(this.transformToSegments({}))
  429. .catch(this.handleQueryError.bind(this));
  430. }
  431. case 'part-param-changed': {
  432. this.updatePersistedParts();
  433. this.panelCtrl.refresh();
  434. break;
  435. }
  436. case 'action': {
  437. this.removeGroup(part, index);
  438. this.panelCtrl.refresh();
  439. break;
  440. }
  441. case 'get-part-actions': {
  442. return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
  443. }
  444. }
  445. }
  446. addGroup(partType: string, value: string) {
  447. let params = [value];
  448. if (partType === 'time') {
  449. params = ['$__interval', 'none'];
  450. }
  451. const partModel = sqlPart.create({ type: partType, params: params });
  452. if (partType === 'time') {
  453. // put timeGroup at start
  454. this.groupParts.splice(0, 0, partModel);
  455. } else {
  456. this.groupParts.push(partModel);
  457. }
  458. // add aggregates when adding group by
  459. for (const selectParts of this.selectParts) {
  460. if (!selectParts.some(part => part.def.type === 'aggregate')) {
  461. const aggregate = sqlPart.create({ type: 'aggregate', params: ['avg'] });
  462. selectParts.splice(1, 0, aggregate);
  463. if (!selectParts.some(part => part.def.type === 'alias')) {
  464. const alias = sqlPart.create({ type: 'alias', params: [selectParts[0].part.params[0]] });
  465. selectParts.push(alias);
  466. }
  467. }
  468. }
  469. this.updatePersistedParts();
  470. }
  471. removeGroup(part: { def: { type: string } }, index: number) {
  472. if (part.def.type === 'time') {
  473. // remove aggregations
  474. this.selectParts = _.map(this.selectParts, (s: any) => {
  475. return _.filter(s, (part: any) => {
  476. if (part.def.type === 'aggregate' || part.def.type === 'percentile') {
  477. return false;
  478. }
  479. return true;
  480. });
  481. });
  482. }
  483. this.groupParts.splice(index, 1);
  484. this.updatePersistedParts();
  485. }
  486. handleWherePartEvent(whereParts: any, part: any, evt: any, index: any) {
  487. switch (evt.name) {
  488. case 'get-param-options': {
  489. switch (evt.param.name) {
  490. case 'left':
  491. return this.datasource
  492. .metricFindQuery(this.metaBuilder.buildColumnQuery())
  493. .then(this.transformToSegments({}))
  494. .catch(this.handleQueryError.bind(this));
  495. case 'right':
  496. if (['int4', 'int8', 'float4', 'float8', 'timestamp', 'timestamptz'].indexOf(part.datatype) > -1) {
  497. // don't do value lookups for numerical fields
  498. return this.$q.when([]);
  499. } else {
  500. return this.datasource
  501. .metricFindQuery(this.metaBuilder.buildValueQuery(part.params[0]))
  502. .then(
  503. this.transformToSegments({
  504. addTemplateVars: true,
  505. templateQuoter: (v: string) => {
  506. return this.queryModel.quoteLiteral(v);
  507. },
  508. })
  509. )
  510. .catch(this.handleQueryError.bind(this));
  511. }
  512. case 'op':
  513. return this.$q.when(this.uiSegmentSrv.newOperators(this.metaBuilder.getOperators(part.datatype)));
  514. default:
  515. return this.$q.when([]);
  516. }
  517. }
  518. case 'part-param-changed': {
  519. this.updatePersistedParts();
  520. this.datasource.metricFindQuery(this.metaBuilder.buildDatatypeQuery(part.params[0])).then((d: any) => {
  521. if (d.length === 1) {
  522. part.datatype = d[0].text;
  523. }
  524. });
  525. this.panelCtrl.refresh();
  526. break;
  527. }
  528. case 'action': {
  529. // remove element
  530. whereParts.splice(index, 1);
  531. this.updatePersistedParts();
  532. this.panelCtrl.refresh();
  533. break;
  534. }
  535. case 'get-part-actions': {
  536. return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
  537. }
  538. }
  539. }
  540. getWhereOptions() {
  541. const options = [];
  542. if (this.queryModel.hasUnixEpochTimecolumn()) {
  543. options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__unixEpochFilter' }));
  544. } else {
  545. options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__timeFilter' }));
  546. }
  547. options.push(this.uiSegmentSrv.newSegment({ type: 'expression', value: 'Expression' }));
  548. return this.$q.when(options);
  549. }
  550. addWhereAction(part: any, index: any) {
  551. switch (this.whereAdd.type) {
  552. case 'macro': {
  553. const partModel = sqlPart.create({ type: 'macro', name: this.whereAdd.value, params: [] });
  554. if (this.whereParts.length >= 1 && this.whereParts[0].def.type === 'macro') {
  555. // replace current macro
  556. this.whereParts[0] = partModel;
  557. } else {
  558. this.whereParts.splice(0, 0, partModel);
  559. }
  560. break;
  561. }
  562. default: {
  563. this.whereParts.push(sqlPart.create({ type: 'expression', params: ['value', '=', 'value'] }));
  564. }
  565. }
  566. this.updatePersistedParts();
  567. this.resetPlusButton(this.whereAdd);
  568. this.panelCtrl.refresh();
  569. }
  570. getGroupOptions() {
  571. return this.datasource
  572. .metricFindQuery(this.metaBuilder.buildColumnQuery('group'))
  573. .then((tags: any) => {
  574. const options = [];
  575. if (!this.queryModel.hasTimeGroup()) {
  576. options.push(this.uiSegmentSrv.newSegment({ type: 'time', value: 'time($__interval,none)' }));
  577. }
  578. for (const tag of tags) {
  579. options.push(this.uiSegmentSrv.newSegment({ type: 'column', value: tag.text }));
  580. }
  581. return options;
  582. })
  583. .catch(this.handleQueryError.bind(this));
  584. }
  585. addGroupAction() {
  586. switch (this.groupAdd.value) {
  587. default: {
  588. this.addGroup(this.groupAdd.type, this.groupAdd.value);
  589. }
  590. }
  591. this.resetPlusButton(this.groupAdd);
  592. this.panelCtrl.refresh();
  593. }
  594. handleQueryError(err: any): any[] {
  595. this.error = err.message || 'Failed to issue metric query';
  596. return [];
  597. }
  598. }