query_ctrl.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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. console.log('postgres query data received', dataList);
  262. const anySeriesFromQuery: any = _.find(dataList, { refId: this.target.refId });
  263. if (anySeriesFromQuery) {
  264. this.lastQueryMeta = anySeriesFromQuery.meta;
  265. }
  266. }
  267. onDataError(err: any) {
  268. if (err.data && err.data.results) {
  269. const queryRes = err.data.results[this.target.refId];
  270. if (queryRes) {
  271. this.lastQueryMeta = queryRes.meta;
  272. this.lastQueryError = queryRes.error;
  273. }
  274. }
  275. }
  276. transformToSegments(config: { addNone?: any; addTemplateVars?: any; templateQuoter?: any }) {
  277. return (results: any) => {
  278. const segments = _.map(results, segment => {
  279. return this.uiSegmentSrv.newSegment({
  280. value: segment.text,
  281. expandable: segment.expandable,
  282. });
  283. });
  284. if (config.addTemplateVars) {
  285. for (const variable of this.templateSrv.variables) {
  286. let value;
  287. value = '$' + variable.name;
  288. if (config.templateQuoter && variable.multi === false) {
  289. value = config.templateQuoter(value);
  290. }
  291. segments.unshift(
  292. this.uiSegmentSrv.newSegment({
  293. type: 'template',
  294. value: value,
  295. expandable: true,
  296. })
  297. );
  298. }
  299. }
  300. if (config.addNone) {
  301. segments.unshift(this.uiSegmentSrv.newSegment({ type: 'template', value: 'none', expandable: true }));
  302. }
  303. return segments;
  304. };
  305. }
  306. findAggregateIndex(selectParts: any) {
  307. return _.findIndex(selectParts, (p: any) => p.def.type === 'aggregate' || p.def.type === 'percentile');
  308. }
  309. findWindowIndex(selectParts: any) {
  310. return _.findIndex(selectParts, (p: any) => p.def.type === 'window' || p.def.type === 'moving_window');
  311. }
  312. addSelectPart(selectParts: any[], item: { value: any }, subItem: { type: any; value: any }) {
  313. let partType = item.value;
  314. if (subItem && subItem.type) {
  315. partType = subItem.type;
  316. }
  317. let partModel = sqlPart.create({ type: partType });
  318. if (subItem) {
  319. partModel.params[0] = subItem.value;
  320. }
  321. let addAlias = false;
  322. switch (partType) {
  323. case 'column':
  324. const parts = _.map(selectParts, (part: any) => {
  325. return sqlPart.create({ type: part.def.type, params: _.clone(part.params) });
  326. });
  327. this.selectParts.push(parts);
  328. break;
  329. case 'percentile':
  330. case 'aggregate':
  331. // add group by if no group by yet
  332. if (this.target.group.length === 0) {
  333. this.addGroup('time', '$__interval');
  334. }
  335. const aggIndex = this.findAggregateIndex(selectParts);
  336. if (aggIndex !== -1) {
  337. // replace current aggregation
  338. selectParts[aggIndex] = partModel;
  339. } else {
  340. selectParts.splice(1, 0, partModel);
  341. }
  342. if (!_.find(selectParts, (p: any) => p.def.type === 'alias')) {
  343. addAlias = true;
  344. }
  345. break;
  346. case 'moving_window':
  347. case 'window':
  348. const windowIndex = this.findWindowIndex(selectParts);
  349. if (windowIndex !== -1) {
  350. // replace current window function
  351. selectParts[windowIndex] = partModel;
  352. } else {
  353. const aggIndex = this.findAggregateIndex(selectParts);
  354. if (aggIndex !== -1) {
  355. selectParts.splice(aggIndex + 1, 0, partModel);
  356. } else {
  357. selectParts.splice(1, 0, partModel);
  358. }
  359. }
  360. if (!_.find(selectParts, (p: any) => p.def.type === 'alias')) {
  361. addAlias = true;
  362. }
  363. break;
  364. case 'alias':
  365. addAlias = true;
  366. break;
  367. }
  368. if (addAlias) {
  369. // set initial alias name to column name
  370. partModel = sqlPart.create({ type: 'alias', params: [selectParts[0].params[0].replace(/"/g, '')] });
  371. if (selectParts[selectParts.length - 1].def.type === 'alias') {
  372. selectParts[selectParts.length - 1] = partModel;
  373. } else {
  374. selectParts.push(partModel);
  375. }
  376. }
  377. this.updatePersistedParts();
  378. this.panelCtrl.refresh();
  379. }
  380. removeSelectPart(selectParts: any, part: { def: { type: string } }) {
  381. if (part.def.type === 'column') {
  382. // remove all parts of column unless its last column
  383. if (this.selectParts.length > 1) {
  384. const modelsIndex = _.indexOf(this.selectParts, selectParts);
  385. this.selectParts.splice(modelsIndex, 1);
  386. }
  387. } else {
  388. const partIndex = _.indexOf(selectParts, part);
  389. selectParts.splice(partIndex, 1);
  390. }
  391. this.updatePersistedParts();
  392. }
  393. handleSelectPartEvent(selectParts: any, part: { def: any }, evt: { name: any }) {
  394. switch (evt.name) {
  395. case 'get-param-options': {
  396. switch (part.def.type) {
  397. case 'aggregate':
  398. return this.datasource
  399. .metricFindQuery(this.metaBuilder.buildAggregateQuery())
  400. .then(this.transformToSegments({}))
  401. .catch(this.handleQueryError.bind(this));
  402. case 'column':
  403. return this.datasource
  404. .metricFindQuery(this.metaBuilder.buildColumnQuery('value'))
  405. .then(this.transformToSegments({}))
  406. .catch(this.handleQueryError.bind(this));
  407. }
  408. }
  409. case 'part-param-changed': {
  410. this.updatePersistedParts();
  411. this.panelCtrl.refresh();
  412. break;
  413. }
  414. case 'action': {
  415. this.removeSelectPart(selectParts, part);
  416. this.panelCtrl.refresh();
  417. break;
  418. }
  419. case 'get-part-actions': {
  420. return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
  421. }
  422. }
  423. }
  424. handleGroupPartEvent(part: any, index: any, evt: { name: any }) {
  425. switch (evt.name) {
  426. case 'get-param-options': {
  427. return this.datasource
  428. .metricFindQuery(this.metaBuilder.buildColumnQuery())
  429. .then(this.transformToSegments({}))
  430. .catch(this.handleQueryError.bind(this));
  431. }
  432. case 'part-param-changed': {
  433. this.updatePersistedParts();
  434. this.panelCtrl.refresh();
  435. break;
  436. }
  437. case 'action': {
  438. this.removeGroup(part, index);
  439. this.panelCtrl.refresh();
  440. break;
  441. }
  442. case 'get-part-actions': {
  443. return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
  444. }
  445. }
  446. }
  447. addGroup(partType: string, value: string) {
  448. let params = [value];
  449. if (partType === 'time') {
  450. params = ['$__interval', 'none'];
  451. }
  452. const partModel = sqlPart.create({ type: partType, params: params });
  453. if (partType === 'time') {
  454. // put timeGroup at start
  455. this.groupParts.splice(0, 0, partModel);
  456. } else {
  457. this.groupParts.push(partModel);
  458. }
  459. // add aggregates when adding group by
  460. for (const selectParts of this.selectParts) {
  461. if (!selectParts.some(part => part.def.type === 'aggregate')) {
  462. const aggregate = sqlPart.create({ type: 'aggregate', params: ['avg'] });
  463. selectParts.splice(1, 0, aggregate);
  464. if (!selectParts.some(part => part.def.type === 'alias')) {
  465. const alias = sqlPart.create({ type: 'alias', params: [selectParts[0].part.params[0]] });
  466. selectParts.push(alias);
  467. }
  468. }
  469. }
  470. this.updatePersistedParts();
  471. }
  472. removeGroup(part: { def: { type: string } }, index: number) {
  473. if (part.def.type === 'time') {
  474. // remove aggregations
  475. this.selectParts = _.map(this.selectParts, (s: any) => {
  476. return _.filter(s, (part: any) => {
  477. if (part.def.type === 'aggregate' || part.def.type === 'percentile') {
  478. return false;
  479. }
  480. return true;
  481. });
  482. });
  483. }
  484. this.groupParts.splice(index, 1);
  485. this.updatePersistedParts();
  486. }
  487. handleWherePartEvent(whereParts: any, part: any, evt: any, index: any) {
  488. switch (evt.name) {
  489. case 'get-param-options': {
  490. switch (evt.param.name) {
  491. case 'left':
  492. return this.datasource
  493. .metricFindQuery(this.metaBuilder.buildColumnQuery())
  494. .then(this.transformToSegments({}))
  495. .catch(this.handleQueryError.bind(this));
  496. case 'right':
  497. if (['int4', 'int8', 'float4', 'float8', 'timestamp', 'timestamptz'].indexOf(part.datatype) > -1) {
  498. // don't do value lookups for numerical fields
  499. return this.$q.when([]);
  500. } else {
  501. return this.datasource
  502. .metricFindQuery(this.metaBuilder.buildValueQuery(part.params[0]))
  503. .then(
  504. this.transformToSegments({
  505. addTemplateVars: true,
  506. templateQuoter: (v: string) => {
  507. return this.queryModel.quoteLiteral(v);
  508. },
  509. })
  510. )
  511. .catch(this.handleQueryError.bind(this));
  512. }
  513. case 'op':
  514. return this.$q.when(this.uiSegmentSrv.newOperators(this.metaBuilder.getOperators(part.datatype)));
  515. default:
  516. return this.$q.when([]);
  517. }
  518. }
  519. case 'part-param-changed': {
  520. this.updatePersistedParts();
  521. this.datasource.metricFindQuery(this.metaBuilder.buildDatatypeQuery(part.params[0])).then((d: any) => {
  522. if (d.length === 1) {
  523. part.datatype = d[0].text;
  524. }
  525. });
  526. this.panelCtrl.refresh();
  527. break;
  528. }
  529. case 'action': {
  530. // remove element
  531. whereParts.splice(index, 1);
  532. this.updatePersistedParts();
  533. this.panelCtrl.refresh();
  534. break;
  535. }
  536. case 'get-part-actions': {
  537. return this.$q.when([{ text: 'Remove', value: 'remove-part' }]);
  538. }
  539. }
  540. }
  541. getWhereOptions() {
  542. const options = [];
  543. if (this.queryModel.hasUnixEpochTimecolumn()) {
  544. options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__unixEpochFilter' }));
  545. } else {
  546. options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__timeFilter' }));
  547. }
  548. options.push(this.uiSegmentSrv.newSegment({ type: 'expression', value: 'Expression' }));
  549. return this.$q.when(options);
  550. }
  551. addWhereAction(part: any, index: any) {
  552. switch (this.whereAdd.type) {
  553. case 'macro': {
  554. const partModel = sqlPart.create({ type: 'macro', name: this.whereAdd.value, params: [] });
  555. if (this.whereParts.length >= 1 && this.whereParts[0].def.type === 'macro') {
  556. // replace current macro
  557. this.whereParts[0] = partModel;
  558. } else {
  559. this.whereParts.splice(0, 0, partModel);
  560. }
  561. break;
  562. }
  563. default: {
  564. this.whereParts.push(sqlPart.create({ type: 'expression', params: ['value', '=', 'value'] }));
  565. }
  566. }
  567. this.updatePersistedParts();
  568. this.resetPlusButton(this.whereAdd);
  569. this.panelCtrl.refresh();
  570. }
  571. getGroupOptions() {
  572. return this.datasource
  573. .metricFindQuery(this.metaBuilder.buildColumnQuery('group'))
  574. .then((tags: any) => {
  575. const options = [];
  576. if (!this.queryModel.hasTimeGroup()) {
  577. options.push(this.uiSegmentSrv.newSegment({ type: 'time', value: 'time($__interval,none)' }));
  578. }
  579. for (const tag of tags) {
  580. options.push(this.uiSegmentSrv.newSegment({ type: 'column', value: tag.text }));
  581. }
  582. return options;
  583. })
  584. .catch(this.handleQueryError.bind(this));
  585. }
  586. addGroupAction() {
  587. switch (this.groupAdd.value) {
  588. default: {
  589. this.addGroup(this.groupAdd.type, this.groupAdd.value);
  590. }
  591. }
  592. this.resetPlusButton(this.groupAdd);
  593. this.panelCtrl.refresh();
  594. }
  595. handleQueryError(err: any): any[] {
  596. this.error = err.message || 'Failed to issue metric query';
  597. return [];
  598. }
  599. }