diff --git a/dashboards-observability/common/query_manager/antlr/grammar/OpenSearchPPLLexer.g4 b/dashboards-observability/common/query_manager/antlr/grammar/OpenSearchPPLLexer.g4 index c30967a77..f51386796 100644 --- a/dashboards-observability/common/query_manager/antlr/grammar/OpenSearchPPLLexer.g4 +++ b/dashboards-observability/common/query_manager/antlr/grammar/OpenSearchPPLLexer.g4 @@ -11,6 +11,8 @@ channels { WHITESPACE, ERRORCHANNEL } // COMMAND KEYWORDS SEARCH: 'SEARCH'; +DESCRIBE: 'DESCRIBE'; +SHOW: 'SHOW'; FROM: 'FROM'; WHERE: 'WHERE'; FIELDS: 'FIELDS'; @@ -23,8 +25,16 @@ HEAD: 'HEAD'; TOP: 'TOP'; RARE: 'RARE'; PARSE: 'PARSE'; +METHOD: 'METHOD'; +REGEX: 'REGEX'; +PUNCT: 'PUNCT'; +GROK: 'GROK'; +PATTERN: 'PATTERN'; +PATTERNS: 'PATTERNS'; +NEW_FIELD: 'NEW_FIELD'; KMEANS: 'KMEANS'; AD: 'AD'; +ML: 'ML'; // COMMAND ASSIST KEYWORDS AS: 'AS'; @@ -33,6 +43,7 @@ SOURCE: 'SOURCE'; INDEX: 'INDEX'; D: 'D'; DESC: 'DESC'; +CATALOGS: 'CATALOGS'; // CLAUSE KEYWORDS SORTBY: 'SORTBY'; @@ -59,6 +70,7 @@ SAMPLE_SIZE: 'SAMPLE_SIZE'; OUTPUT_AFTER: 'OUTPUT_AFTER'; TIME_DECAY: 'TIME_DECAY'; ANOMALY_RATE: 'ANOMALY_RATE'; +CATEGORY_FIELD: 'CATEGORY_FIELD'; TIME_FIELD: 'TIME_FIELD'; TIME_ZONE: 'TIME_ZONE'; TRAINING_DATA_SIZE: 'TRAINING_DATA_SIZE'; @@ -101,6 +113,7 @@ DAY_SECOND: 'DAY_SECOND'; DAY_MINUTE: 'DAY_MINUTE'; DAY_HOUR: 'DAY_HOUR'; YEAR_MONTH: 'YEAR_MONTH'; +CONVERT_TZ: 'CONVERT_TZ'; // DATASET TYPES DATAMODEL: 'DATAMODEL'; @@ -168,6 +181,7 @@ VAR_POP: 'VAR_POP'; STDDEV_SAMP: 'STDDEV_SAMP'; STDDEV_POP: 'STDDEV_POP'; PERCENTILE: 'PERCENTILE'; +TAKE: 'TAKE'; FIRST: 'FIRST'; LAST: 'LAST'; LIST: 'LIST'; @@ -222,21 +236,39 @@ TAN: 'TAN'; // DATE AND TIME FUNCTIONS ADDDATE: 'ADDDATE'; +CURDATE: 'CURDATE'; +CURRENT_DATE: 'CURRENT_DATE'; +CURRENT_TIME: 'CURRENT_TIME'; +CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP'; +CURTIME: 'CURTIME'; DATE: 'DATE'; DATE_ADD: 'DATE_ADD'; +DATE_FORMAT: 'DATE_FORMAT'; DATE_SUB: 'DATE_SUB'; +DAYNAME: 'DAYNAME'; DAYOFMONTH: 'DAYOFMONTH'; DAYOFWEEK: 'DAYOFWEEK'; DAYOFYEAR: 'DAYOFYEAR'; -DAYNAME: 'DAYNAME'; FROM_DAYS: 'FROM_DAYS'; +LOCALTIME: 'LOCALTIME'; +LOCALTIMESTAMP: 'LOCALTIMESTAMP'; +FROM_UNIXTIME: 'FROM_UNIXTIME'; +MAKEDATE: 'MAKEDATE'; +MAKETIME: 'MAKETIME'; MONTHNAME: 'MONTHNAME'; +NOW: 'NOW'; +PERIOD_ADD: 'PERIOD_ADD'; +PERIOD_DIFF: 'PERIOD_DIFF'; SUBDATE: 'SUBDATE'; +SYSDATE: 'SYSDATE'; TIME: 'TIME'; TIME_TO_SEC: 'TIME_TO_SEC'; TIMESTAMP: 'TIMESTAMP'; -DATE_FORMAT: 'DATE_FORMAT'; TO_DAYS: 'TO_DAYS'; +UTC_DATE: 'UTC_DATE'; +UTC_TIME: 'UTC_TIME'; +UTC_TIMESTAMP: 'UTC_TIMESTAMP'; +UNIX_TIMESTAMP: 'UNIX_TIMESTAMP'; // TEXT FUNCTIONS SUBSTR: 'SUBSTR'; @@ -267,11 +299,16 @@ ISNOTNULL: 'ISNOTNULL'; IFNULL: 'IFNULL'; NULLIF: 'NULLIF'; IF: 'IF'; +TYPEOF: 'TYPEOF'; // RELEVANCE FUNCTIONS AND PARAMETERS MATCH: 'MATCH'; MATCH_PHRASE: 'MATCH_PHRASE'; +MATCH_PHRASE_PREFIX: 'MATCH_PHRASE_PREFIX'; +MATCH_BOOL_PREFIX: 'MATCH_BOOL_PREFIX'; SIMPLE_QUERY_STRING: 'SIMPLE_QUERY_STRING'; +MULTI_MATCH: 'MULTI_MATCH'; +QUERY_STRING: 'QUERY_STRING'; ALLOW_LEADING_WILDCARD: 'ALLOW_LEADING_WILDCARD'; ANALYZE_WILDCARD: 'ANALYZE_WILDCARD'; @@ -282,6 +319,7 @@ CUTOFF_FREQUENCY: 'CUTOFF_FREQUENCY'; DEFAULT_FIELD: 'DEFAULT_FIELD'; DEFAULT_OPERATOR: 'DEFAULT_OPERATOR'; ENABLE_POSITION_INCREMENTS: 'ENABLE_POSITION_INCREMENTS'; +ESCAPE: 'ESCAPE'; FLAGS: 'FLAGS'; FUZZY_MAX_EXPANSIONS: 'FUZZY_MAX_EXPANSIONS'; FUZZY_PREFIX_LENGTH: 'FUZZY_PREFIX_LENGTH'; diff --git a/dashboards-observability/common/query_manager/antlr/grammar/OpenSearchPPLParser.g4 b/dashboards-observability/common/query_manager/antlr/grammar/OpenSearchPPLParser.g4 index de96295f9..3909cef29 100644 --- a/dashboards-observability/common/query_manager/antlr/grammar/OpenSearchPPLParser.g4 +++ b/dashboards-observability/common/query_manager/antlr/grammar/OpenSearchPPLParser.g4 @@ -14,13 +14,19 @@ root /** statement */ pplStatement - : searchCommand (PIPE commands)* + : pplCommands (PIPE commands)* ; /** commands */ +pplCommands + : searchCommand + | describeCommand + | showCatalogsCommand + ; + commands : whereCommand | fieldsCommand | renameCommand | statsCommand | dedupCommand | sortCommand | evalCommand | headCommand - | topCommand | rareCommand | parseCommand | kmeansCommand | adCommand; + | topCommand | rareCommand | grokCommand | parseCommand | patternsCommand | kmeansCommand | adCommand | mlCommand; searchCommand : (SEARCH)? fromClause #searchFrom @@ -28,6 +34,14 @@ searchCommand | (SEARCH)? logicalExpression fromClause #searchFilterFrom ; +describeCommand + : DESCRIBE tableSourceClause + ; + +showCatalogsCommand + : SHOW CATALOGS + ; + whereCommand : WHERE logicalExpression ; @@ -85,10 +99,27 @@ rareCommand (byClause)? ; +grokCommand + : GROK (source_field=expression) (pattern=stringLiteral) + ; + parseCommand - : PARSE expression pattern + : PARSE (source_field=expression) (pattern=stringLiteral) ; - + +patternsCommand + : PATTERNS (patternsParameter)* (source_field=expression) + ; + +patternsParameter + : (NEW_FIELD EQUAL new_field=stringLiteral) + | (PATTERN EQUAL pattern=stringLiteral) + ; + +patternsMethod + : PUNCT | REGEX + ; + kmeansCommand : KMEANS (kmeansParameter)* ; @@ -110,6 +141,7 @@ adParameter | (OUTPUT_AFTER EQUAL output_after=integerLiteral) | (TIME_DECAY EQUAL time_decay=decimalLiteral) | (ANOMALY_RATE EQUAL anomaly_rate=decimalLiteral) + | (CATEGORY_FIELD EQUAL category_field=stringLiteral) | (TIME_FIELD EQUAL time_field=stringLiteral) | (DATE_FORMAT EQUAL date_format=stringLiteral) | (TIME_ZONE EQUAL time_zone=stringLiteral) @@ -117,10 +149,24 @@ adParameter | (ANOMALY_SCORE_THRESHOLD EQUAL anomaly_score_threshold=decimalLiteral) ; +mlCommand + : ML (mlArg)* + ; + +mlArg + : (argName=ident EQUAL argValue=literalValue) + ; + /** clauses */ fromClause - : SOURCE EQUAL tableSource (COMMA tableSource)* - | INDEX EQUAL tableSource (COMMA tableSource)* + : SOURCE EQUAL tableSourceClause + | INDEX EQUAL tableSourceClause + | SOURCE EQUAL tableFunction + | INDEX EQUAL tableFunction + ; + +tableSourceClause + : tableSource (COMMA tableSource)* ; renameClasue @@ -164,12 +210,17 @@ statsFunction | COUNT LT_PRTHS RT_PRTHS #countAllFunctionCall | (DISTINCT_COUNT | DC) LT_PRTHS valueExpression RT_PRTHS #distinctCountFunctionCall | percentileAggFunction #percentileAggFunctionCall + | takeAggFunction #takeAggFunctionCall ; statsFunctionName : AVG | COUNT | SUM | MIN | MAX | VAR_SAMP | VAR_POP | STDDEV_SAMP | STDDEV_POP ; +takeAggFunction + : TAKE LT_PRTHS fieldExpression (COMMA size=integerLiteral)? RT_PRTHS + ; + percentileAggFunction : PERCENTILE LESS value=integerLiteral GREATER LT_PRTHS aggField=fieldExpression RT_PRTHS ; @@ -208,6 +259,11 @@ primaryExpression | dataTypeFunctionCall | fieldExpression | literalValue + | constantFunction + ; + +constantFunction + : constantFunctionName LT_PRTHS functionArgs? RT_PRTHS ; booleanExpression @@ -238,6 +294,10 @@ tableSource | ID_DATE_SUFFIX ; +tableFunction + : qualifiedName LT_PRTHS functionArgs RT_PRTHS + ; + /** fields */ fieldList : fieldExpression (COMMA fieldExpression)* @@ -300,6 +360,7 @@ evalFunctionName | dateAndTimeFunctionBase | textFunctionBase | conditionFunctionBase + | systemFunctionBase ; functionArgs @@ -307,7 +368,7 @@ functionArgs ; functionArg - : valueExpression + : (ident EQUAL)? valueExpression ; relevanceArg @@ -317,8 +378,8 @@ relevanceArg relevanceArgName : ALLOW_LEADING_WILDCARD | ANALYZER | ANALYZE_WILDCARD | AUTO_GENERATE_SYNONYMS_PHRASE_QUERY | BOOST | CUTOFF_FREQUENCY | DEFAULT_FIELD | DEFAULT_OPERATOR | ENABLE_POSITION_INCREMENTS - | FIELDS | FLAGS | FUZZINESS | FUZZY_MAX_EXPANSIONS | FUZZY_PREFIX_LENGTH | FUZZY_REWRITE - | FUZZY_TRANSPOSITIONS | LENIENT | LOW_FREQ_OPERATOR | MAX_DETERMINIZED_STATES + | ESCAPE | FIELDS | FLAGS | FUZZINESS | FUZZY_MAX_EXPANSIONS | FUZZY_PREFIX_LENGTH + | FUZZY_REWRITE | FUZZY_TRANSPOSITIONS | LENIENT | LOW_FREQ_OPERATOR | MAX_DETERMINIZED_STATES | MAX_EXPANSIONS | MINIMUM_SHOULD_MATCH | OPERATOR | PHRASE_SLOP | PREFIX_LENGTH | QUOTE_ANALYZER | QUOTE_FIELD_SUFFIX | REWRITE | SLOP | TIE_BREAKER | TIME_ZONE | TYPE | ZERO_TERMS_QUERY @@ -360,9 +421,17 @@ trigonometricFunctionName ; dateAndTimeFunctionBase - : ADDDATE | DATE | DATE_ADD | DATE_SUB | DAY | DAYNAME | DAYOFMONTH | DAYOFWEEK | DAYOFYEAR | FROM_DAYS - | HOUR | MICROSECOND | MINUTE | MONTH | MONTHNAME | QUARTER | SECOND | SUBDATE | TIME | TIME_TO_SEC - | TIMESTAMP | TO_DAYS | YEAR | WEEK | DATE_FORMAT + : ADDDATE | CONVERT_TZ | DATE | DATE_ADD | DATE_FORMAT | DATE_SUB + | DATETIME | DAY | DAYNAME | DAYOFMONTH | DAYOFWEEK | DAYOFYEAR | FROM_DAYS | FROM_UNIXTIME + | HOUR | MAKEDATE | MAKETIME | MICROSECOND | MINUTE | MONTH | MONTHNAME | PERIOD_ADD + | PERIOD_DIFF | QUARTER | SECOND | SUBDATE | SYSDATE | TIME | TIME_TO_SEC + | TIMESTAMP | TO_DAYS | UNIX_TIMESTAMP | WEEK | YEAR + ; + +// Functions which value could be cached in scope of a single query +constantFunctionName + : CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP | LOCALTIME | LOCALTIMESTAMP | UTC_TIMESTAMP | UTC_DATE | UTC_TIME + | CURDATE | CURTIME | NOW ; /** condition function return boolean value */ @@ -371,6 +440,10 @@ conditionFunctionBase | IF | ISNULL | ISNOTNULL | IFNULL | NULLIF ; +systemFunctionBase + : TYPEOF + ; + textFunctionBase : SUBSTR | SUBSTRING | TRIM | LTRIM | RTRIM | LOWER | UPPER | CONCAT | CONCAT_WS | LENGTH | STRCMP | RIGHT | LEFT | ASCII | LOCATE | REPLACE @@ -389,10 +462,14 @@ binaryOperator singleFieldRelevanceFunctionName : MATCH | MATCH_PHRASE + | MATCH_BOOL_PREFIX + | MATCH_PHRASE_PREFIX ; multiFieldRelevanceFunctionName : SIMPLE_QUERY_STRING + | MULTI_MATCH + | QUERY_STRING ; /** literals and values*/ @@ -402,6 +479,7 @@ literalValue | integerLiteral | decimalLiteral | booleanLiteral + | datetimeLiteral //#datetime ; intervalLiteral @@ -424,8 +502,23 @@ booleanLiteral : TRUE | FALSE ; -pattern - : stringLiteral +// Date and Time Literal, follow ANSI 92 +datetimeLiteral + : dateLiteral + | timeLiteral + | timestampLiteral + ; + +dateLiteral + : DATE date=stringLiteral + ; + +timeLiteral + : TIME time=stringLiteral + ; + +timestampLiteral + : TIMESTAMP timestamp=stringLiteral ; intervalUnit @@ -472,4 +565,8 @@ keywordsCanBeId | TIMESTAMP | DATE | TIME | FIRST | LAST | timespanUnit | SPAN + | constantFunctionName + | dateAndTimeFunctionBase + | textFunctionBase + | mathematicalFunctionBase ; \ No newline at end of file diff --git a/dashboards-observability/public/components/custom_panels/helpers/__tests__/__snapshots__/utils.test.tsx.snap b/dashboards-observability/public/components/custom_panels/helpers/__tests__/__snapshots__/utils.test.tsx.snap index 4668e70fc..1d6c90187 100644 --- a/dashboards-observability/public/components/custom_panels/helpers/__tests__/__snapshots__/utils.test.tsx.snap +++ b/dashboards-observability/public/components/custom_panels/helpers/__tests__/__snapshots__/utils.test.tsx.snap @@ -135,7 +135,26 @@ exports[`Utils helper functions renders displayVisualization function 1`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [ + Object { + "customLabel": "", + "label": "Carrier", + "name": "Carrier", + }, + ], + "series": Array [ + Object { + "aggregation": "sum", + "customLabel": "delays", + "label": "FlightDelayMin", + "name": "FlightDelayMin", + }, + ], + "span": undefined, + }, + }, }, "vis": Object { "barwidth": 0.97, @@ -398,12 +417,6 @@ exports[`Utils helper functions renders displayVisualization function 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, @@ -584,7 +597,26 @@ exports[`Utils helper functions renders displayVisualization function 1`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [ + Object { + "customLabel": "", + "label": "Carrier", + "name": "Carrier", + }, + ], + "series": Array [ + Object { + "aggregation": "sum", + "customLabel": "delays", + "label": "FlightDelayMin", + "name": "FlightDelayMin", + }, + ], + "span": undefined, + }, + }, }, "vis": Object { "barwidth": 0.97, @@ -847,12 +879,6 @@ exports[`Utils helper functions renders displayVisualization function 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, @@ -1040,7 +1066,26 @@ exports[`Utils helper functions renders displayVisualization function 1`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [ + Object { + "customLabel": "", + "label": "Carrier", + "name": "Carrier", + }, + ], + "series": Array [ + Object { + "aggregation": "sum", + "customLabel": "delays", + "label": "FlightDelayMin", + "name": "FlightDelayMin", + }, + ], + "span": undefined, + }, + }, }, "vis": Object { "barwidth": 0.97, @@ -1303,12 +1348,6 @@ exports[`Utils helper functions renders displayVisualization function 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, @@ -1363,7 +1402,35 @@ exports[`Utils helper functions renders displayVisualization function 1`] = ` "responsive": true, } } - data={Array []} + data={ + Array [ + Object { + "hoverinfo": "all", + "marker": Object { + "color": "rgba(60,161,199,0.35)", + "line": Object { + "color": "#3CA1C7", + "width": 2, + }, + }, + "name": "delays", + "orientation": "v", + "type": "bar", + "x": Array [ + ",BeatsWest", + ",Logstash Airways", + ",OpenSearch Dashboards Airlines", + ",OpenSearch-Air", + ], + "y": Array [ + undefined, + undefined, + undefined, + undefined, + ], + }, + ] + } layout={ Object { "bargap": 0.30000000000000004, @@ -1418,7 +1485,35 @@ exports[`Utils helper functions renders displayVisualization function 1`] = ` "responsive": true, } } - data={Array []} + data={ + Array [ + Object { + "hoverinfo": "all", + "marker": Object { + "color": "rgba(60,161,199,0.35)", + "line": Object { + "color": "#3CA1C7", + "width": 2, + }, + }, + "name": "delays", + "orientation": "v", + "type": "bar", + "x": Array [ + ",BeatsWest", + ",Logstash Airways", + ",OpenSearch Dashboards Airlines", + ",OpenSearch-Air", + ], + "y": Array [ + undefined, + undefined, + undefined, + undefined, + ], + }, + ] + } debug={false} divId="explorerPlotComponent" layout={ @@ -1631,7 +1726,36 @@ exports[`Utils helper functions renders displayVisualization function 2`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [], + "series": Array [ + Object { + "aggregation": "avg", + "customLabel": "", + "label": "machine.ram", + "name": "machine.ram", + }, + ], + "span": Object { + "interval": "1", + "time_field": Array [ + Object { + "label": "timestamp", + "name": "timestamp", + "type": "timestamp", + }, + ], + "unit": Array [ + Object { + "label": "Day", + "text": "Day", + "value": "d", + }, + ], + }, + }, + }, }, "vis": Object { "category": "Visualizations", @@ -1926,12 +2050,6 @@ exports[`Utils helper functions renders displayVisualization function 2`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fulllabel": "Time series", @@ -2138,7 +2256,36 @@ exports[`Utils helper functions renders displayVisualization function 2`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [], + "series": Array [ + Object { + "aggregation": "avg", + "customLabel": "", + "label": "machine.ram", + "name": "machine.ram", + }, + ], + "span": Object { + "interval": "1", + "time_field": Array [ + Object { + "label": "timestamp", + "name": "timestamp", + "type": "timestamp", + }, + ], + "unit": Array [ + Object { + "label": "Day", + "text": "Day", + "value": "d", + }, + ], + }, + }, + }, }, "vis": Object { "category": "Visualizations", @@ -2433,12 +2580,6 @@ exports[`Utils helper functions renders displayVisualization function 2`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fulllabel": "Time series", @@ -2659,7 +2800,36 @@ exports[`Utils helper functions renders displayVisualization function 2`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [], + "series": Array [ + Object { + "aggregation": "avg", + "customLabel": "", + "label": "machine.ram", + "name": "machine.ram", + }, + ], + "span": Object { + "interval": "1", + "time_field": Array [ + Object { + "label": "timestamp", + "name": "timestamp", + "type": "timestamp", + }, + ], + "unit": Array [ + Object { + "label": "Day", + "text": "Day", + "value": "d", + }, + ], + }, + }, + }, }, "vis": Object { "category": "Visualizations", @@ -2954,12 +3124,6 @@ exports[`Utils helper functions renders displayVisualization function 2`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fulllabel": "Time series", @@ -3247,7 +3411,26 @@ exports[`Utils helper functions renders displayVisualization function 3`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [ + Object { + "customLabel": "", + "label": "machine.os", + "name": "machine.os", + }, + ], + "series": Array [ + Object { + "aggregation": "avg", + "customLabel": "", + "label": "machine.ram", + "name": "machine.ram", + }, + ], + "span": undefined, + }, + }, }, "vis": Object { "barwidth": 0.97, @@ -3510,12 +3693,6 @@ exports[`Utils helper functions renders displayVisualization function 3`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, @@ -3696,7 +3873,26 @@ exports[`Utils helper functions renders displayVisualization function 3`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [ + Object { + "customLabel": "", + "label": "machine.os", + "name": "machine.os", + }, + ], + "series": Array [ + Object { + "aggregation": "avg", + "customLabel": "", + "label": "machine.ram", + "name": "machine.ram", + }, + ], + "span": undefined, + }, + }, }, "vis": Object { "barwidth": 0.97, @@ -3959,12 +4155,6 @@ exports[`Utils helper functions renders displayVisualization function 3`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, @@ -4152,7 +4342,26 @@ exports[`Utils helper functions renders displayVisualization function 3`] = ` "size": 4, "status": 200, }, - "userConfigs": Object {}, + "userConfigs": Object { + "dataConfig": Object { + "dimensions": Array [ + Object { + "customLabel": "", + "label": "machine.os", + "name": "machine.os", + }, + ], + "series": Array [ + Object { + "aggregation": "avg", + "customLabel": "", + "label": "machine.ram", + "name": "machine.ram", + }, + ], + "span": undefined, + }, + }, }, "vis": Object { "barwidth": 0.97, @@ -4415,12 +4624,6 @@ exports[`Utils helper functions renders displayVisualization function 3`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, @@ -4475,7 +4678,35 @@ exports[`Utils helper functions renders displayVisualization function 3`] = ` "responsive": true, } } - data={Array []} + data={ + Array [ + Object { + "hoverinfo": "all", + "marker": Object { + "color": "rgba(60,161,199,0.35)", + "line": Object { + "color": "#3CA1C7", + "width": 2, + }, + }, + "name": "avg(machine.ram)", + "orientation": "h", + "type": "bar", + "x": Array [ + undefined, + undefined, + undefined, + undefined, + ], + "y": Array [ + ",", + ",", + ",", + ",", + ], + }, + ] + } layout={ Object { "bargap": 0.30000000000000004, @@ -4530,7 +4761,35 @@ exports[`Utils helper functions renders displayVisualization function 3`] = ` "responsive": true, } } - data={Array []} + data={ + Array [ + Object { + "hoverinfo": "all", + "marker": Object { + "color": "rgba(60,161,199,0.35)", + "line": Object { + "color": "#3CA1C7", + "width": 2, + }, + }, + "name": "avg(machine.ram)", + "orientation": "h", + "type": "bar", + "x": Array [ + undefined, + undefined, + undefined, + undefined, + ], + "y": Array [ + ",", + ",", + ",", + ",", + ], + }, + ] + } debug={false} divId="explorerPlotComponent" layout={ diff --git a/dashboards-observability/public/components/custom_panels/helpers/utils.tsx b/dashboards-observability/public/components/custom_panels/helpers/utils.tsx index 483361dad..d70f7c455 100644 --- a/dashboards-observability/public/components/custom_panels/helpers/utils.tsx +++ b/dashboards-observability/public/components/custom_panels/helpers/utils.tsx @@ -18,6 +18,8 @@ import { CUSTOM_PANELS_API_PREFIX } from '../../../../common/constants/custom_pa import { VisualizationType, SavedVisualizationType } from '../../../../common/types/custom_panels'; import { Visualization } from '../../visualizations/visualization'; import { getVizContainerProps } from '../../../components/visualizations/charts/helpers'; +import { QueryManager } from '../../../../common/query_manager'; +import { getDefaultVisConfig } from '../../event_analytics/utils'; /* * "Utils" This file contains different reused functions in operational panels @@ -388,6 +390,17 @@ export const displayVisualization = (metaData: any, data: any, type: string) => if (metaData === undefined || _.isEmpty(metaData)) { return <>; } + const userVisConfig = + !_.isEmpty(metaData.user_configs) && !_.isEmpty(metaData.user_configs.series) + ? metaData.user_configs + : { + dataConfig: { + ...getDefaultVisConfig( + new QueryManager().queryParser().parse(metaData.query).getStats() + ), + }, + }; + return ( rawVizData: data, query: { rawQuery: metaData.query }, indexFields: {}, - userConfigs: metaData.user_configs, + userConfigs: userVisConfig, explorer: { explorerData: data, explorerFields: data.metadata.fields }, })} /> diff --git a/dashboards-observability/public/components/event_analytics/explorer/explorer.tsx b/dashboards-observability/public/components/event_analytics/explorer/explorer.tsx index 5e91850a9..4447457d0 100644 --- a/dashboards-observability/public/components/event_analytics/explorer/explorer.tsx +++ b/dashboards-observability/public/components/event_analytics/explorer/explorer.tsx @@ -69,6 +69,14 @@ import { VIS_CHART_TYPES, } from '../../../../common/constants/shared'; import { + getIndexPatternFromRawQuery, + preprocessQuery, + buildQuery, + composeFinalQuery, +} from '../../../../common/utils'; +import { formatError, getDefaultVisConfig } from '../utils'; +import { + statsChunk, GroupByChunk, GroupField, StatsAggregationChunk, @@ -80,11 +88,6 @@ import { IQueryTab, IVisualizationContainerProps, } from '../../../../common/types/explorer'; -import { - buildQuery, - composeFinalQuery, - getIndexPatternFromRawQuery, -} from '../../../../common/utils'; import { sleep } from '../../common/live_tail/live_tail_button'; import { onItemSelect, parseGetSuggestions } from '../../common/search/autocomplete_logic'; import { Search } from '../../common/search/search'; @@ -103,7 +106,6 @@ import { change as updateVizConfig, selectVisualizationConfig, } from '../redux/slices/viualization_config_slice'; -import { formatError } from '../utils'; import { DataGrid } from './events_views/data_grid'; import './explorer.scss'; import { HitsCounter } from './hits_counter/hits_counter'; @@ -316,11 +318,18 @@ export const Explorer = ({ ); // fill saved user configs if (objectData?.type) { + let visConfig = {}; + if (!isEmpty(objectData.user_configs) && !isEmpty(objectData.user_configs.series)) { + visConfig = JSON.parse(objectData.user_configs); + } else { + const statsTokens = queryManager.queryParser().parse(objectData.query).getStats(); + visConfig = { dataConfig: { ...getDefaultVisConfig(statsTokens) } }; + } await dispatch( updateVizConfig({ tabId, vizId: objectData?.type, - data: JSON.parse(objectData.user_configs), + data: visConfig, }) ); } @@ -1111,98 +1120,6 @@ export const Explorer = ({ : undefined; }; - const getUpdatedDataConfig = (statsToken: statsChunk) => { - if (statsToken === null) { - return { - [GROUPBY]: [], - [AGGREGATIONS]: [], - }; - } - - const groupByToken = statsToken.groupby; - const seriesToken = statsToken.aggregations && statsToken.aggregations[0]; - const span = getSpanValue(groupByToken); - switch (curVisId) { - case VIS_CHART_TYPES.TreeMap: - return { - [GROUPBY]: [ - { - childField: { - ...(groupByToken?.group_fields - ? { - label: groupByToken?.group_fields[0].name ?? '', - name: groupByToken?.group_fields[0].name ?? '', - } - : { label: '', name: '' }), - }, - parentFields: [], - }, - ], - [AGGREGATIONS]: [ - { - valueField: { - ...(seriesToken - ? { - label: `${seriesToken.function?.name}(${seriesToken.function?.value_expression})`, - name: `${seriesToken.function?.name}(${seriesToken.function?.value_expression})`, - } - : { label: '', name: '' }), - }, - }, - ], - }; - case VIS_CHART_TYPES.Histogram: - return { - [GROUPBY]: [{ bucketSize: '', bucketOffset: '' }], - [AGGREGATIONS]: [], - }; - case VIS_CHART_TYPES.LogsView: { - const dimensions = statsToken.aggregations - .map((agg) => { - const logViewField = `${agg.function.name}(${agg.function.value_expression})` ?? ''; - return { - label: logViewField, - name: logViewField, - }; - }) - .concat( - groupByToken.group_fields?.map((agg) => ({ - label: agg.name ?? '', - name: agg.name ?? '', - })) - ); - if (span !== undefined) { - const { time_field, interval, unit } = span; - const timespanField = `span(${time_field[0].name},${interval}${unit[0].value})`; - dimensions.push({ - label: timespanField, - name: timespanField, - }); - } - return { - [AGGREGATIONS]: [], - [GROUPBY]: dimensions, - }; - } - - default: - return { - [AGGREGATIONS]: statsToken.aggregations.map((agg) => ({ - label: agg.function?.value_expression, - name: agg.function?.value_expression, - aggregation: agg.function?.name, - [CUSTOM_LABEL]: agg[CUSTOM_LABEL as keyof StatsAggregationChunk], - })), - [GROUPBY]: groupByToken?.group_fields?.map((agg) => ({ - label: agg.name ?? '', - name: agg.name ?? '', - [CUSTOM_LABEL]: agg[CUSTOM_LABEL as keyof GroupField] ?? '', - })), - span, - }; - } - }; - const handleQuerySearch = useCallback( async (availability?: boolean) => { // clear previous selected timestamp when index pattern changes @@ -1222,7 +1139,7 @@ export const Explorer = ({ if (selectedContentTabId === TAB_CHART_ID) { // parse stats section on every search const statsTokens = queryManager.queryParser().parse(tempQuery).getStats(); - const updatedDataConfig = getUpdatedDataConfig(statsTokens); + const updatedDataConfig = getDefaultVisConfig(statsTokens); await dispatch( changeVizConfig({ tabId, @@ -1232,7 +1149,7 @@ export const Explorer = ({ ); } }, - [tempQuery, query, selectedContentTabId] + [tempQuery, query, selectedContentTabId, curVisId] ); const handleQueryChange = async (newQuery: string) => setTempQuery(newQuery); @@ -1538,11 +1455,13 @@ export const Explorer = ({ ); useEffect(() => { - const statsTokens = queryManager.queryParser().parse(tempQuery).getStats(); - const updatedDataConfig = getUpdatedDataConfig(statsTokens); - setSpanValue(!isEqual(typeof updatedDataConfig.span, 'undefined')); - }, [tempQuery, query, selectedContentTabId]); - + if (isEqual(selectedContentTabId, TAB_CHART_ID)) { + const statsTokens = queryManager.queryParser().parse(tempQuery).getStats(); + const updatedDataConfig = getDefaultVisConfig(statsTokens); + setSpanValue(!isEqual(typeof updatedDataConfig.span, 'undefined')); + } + }, [tempQuery, selectedContentTabId, curVisId]); + return ( , - "id": "data-panel", - "name": "Style", - }, - Object { - "content": , - "id": "availability-panel", - "name": "Availability", + "id": "data-panel", + "name": "Style", }, Object { "content": - - -
{ + if (statsToken === null) { + return { + [GROUPBY]: [], + [AGGREGATIONS]: [], + [BREAKDOWNS]: [] + }; + } + + const groupByToken = statsToken.groupby; + // const seriesToken = statsToken.aggregations && statsToken.aggregations[0]; + const span = getSpanValue(groupByToken); + return { + [AGGREGATIONS]: statsToken.aggregations.map((agg) => ({ + label: agg.function?.value_expression, + name: agg.function?.value_expression, + aggregation: agg.function?.name, + [CUSTOM_LABEL]: agg[CUSTOM_LABEL as keyof StatsAggregationChunk], + })), + [GROUPBY]: groupByToken?.group_fields?.map((agg) => ({ + label: agg.name ?? '', + name: agg.name ?? '', + [CUSTOM_LABEL]: agg[CUSTOM_LABEL as keyof GroupField] ?? '', + })), + span, + }; +}; + +const getSpanValue = (groupByToken: GroupByChunk) => { + const timeUnitValue = TIME_INTERVAL_OPTIONS.find( + (time_unit) => time_unit.value === groupByToken?.span?.span_expression.time_unit + )?.text; + return groupByToken?.span !== null + ? { + time_field: [ + { + name: groupByToken?.span.span_expression.field, + type: 'timestamp', + label: groupByToken?.span.span_expression.field, + }, + ], + unit: [ + { + text: timeUnitValue, + value: groupByToken?.span.span_expression.time_unit, + label: timeUnitValue, + }, + ], + interval: groupByToken?.span.span_expression.literal_value, + } + : undefined; +}; diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/bar.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/bar.test.tsx.snap index a1688524f..d8163e362 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/bar.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/bar.test.tsx.snap @@ -482,12 +482,6 @@ exports[`Veritcal Bar component Renders veritcal bar component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/heatmap.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/heatmap.test.tsx.snap index dbf0a9173..755b6a4da 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/heatmap.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/heatmap.test.tsx.snap @@ -482,12 +482,6 @@ exports[`Heatmap component Renders heatmap component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/histogram.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/histogram.test.tsx.snap index ac914b72e..419ff3c03 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/histogram.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/histogram.test.tsx.snap @@ -482,12 +482,6 @@ exports[`Histogram component Renders histogram component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/horizontal_bar.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/horizontal_bar.test.tsx.snap index 6856a232f..23b32e4c2 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/horizontal_bar.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/horizontal_bar.test.tsx.snap @@ -482,12 +482,6 @@ exports[`Horizontal bar component Renders horizontal bar component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/line.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/line.test.tsx.snap index 1dea3d499..c054c7fe5 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/line.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/line.test.tsx.snap @@ -482,12 +482,6 @@ exports[`Line component Renders line component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/logs_view.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/logs_view.test.tsx.snap index 64ebbd437..1a1281d6e 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/logs_view.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/logs_view.test.tsx.snap @@ -482,12 +482,6 @@ exports[`Logs View component Renders logs view component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/metrics.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/metrics.test.tsx.snap index 3b51e9fab..9a2ba7cce 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/metrics.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/metrics.test.tsx.snap @@ -444,12 +444,6 @@ exports[`Metrics component Renders Metrics component 1`] = ` "mapTo": "layoutConfig", "name": "Layout", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fulllabel": "Metrics", diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/pie.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/pie.test.tsx.snap index 8f71c11bf..6d12adee6 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/pie.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/pie.test.tsx.snap @@ -482,12 +482,6 @@ exports[`Pie component Renders pie component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/text.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/text.test.tsx.snap index 06516fd7d..762a46316 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/text.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/text.test.tsx.snap @@ -465,12 +465,6 @@ exports[`Text component Renders text component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/treemap.test.tsx.snap b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/treemap.test.tsx.snap index 052616ff4..23d4f693a 100644 --- a/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/treemap.test.tsx.snap +++ b/dashboards-observability/public/components/visualizations/charts/__tests__/__snapshots__/treemap.test.tsx.snap @@ -482,12 +482,6 @@ exports[`Treemap component Renders treemap component 1`] = ` "mapTo": "availabilityConfig", "name": "Availability", }, - Object { - "editor": [Function], - "id": "availability-panel", - "mapTo": "availabilityConfig", - "name": "Availability", - }, ], }, "fillopacity": 70, diff --git a/dashboards-observability/public/components/visualizations/charts/bar/bar_type.ts b/dashboards-observability/public/components/visualizations/charts/bar/bar_type.ts index bbb41ac33..f07555159 100644 --- a/dashboards-observability/public/components/visualizations/charts/bar/bar_type.ts +++ b/dashboards-observability/public/components/visualizations/charts/bar/bar_type.ts @@ -212,12 +212,6 @@ export const createBarTypeDefinition = (params: any) => ({ mapTo: 'availabilityConfig', editor: ConfigAvailability, }, - { - id: 'availability-panel', - name: 'Availability', - mapTo: 'availabilityConfig', - editor: ConfigAvailability, - }, ], }, visconfig: { diff --git a/dashboards-observability/public/components/visualizations/charts/data_table/data_table_type.ts b/dashboards-observability/public/components/visualizations/charts/data_table/data_table_type.ts index 2ca11ace0..effa7b716 100644 --- a/dashboards-observability/public/components/visualizations/charts/data_table/data_table_type.ts +++ b/dashboards-observability/public/components/visualizations/charts/data_table/data_table_type.ts @@ -104,12 +104,6 @@ export const createDatatableTypeDefinition = (params: any = {}) => ({ editor: ConfigEditor, content: [], }, - { - id: 'availability-panel', - name: 'Availability', - mapTo: 'availabilityConfig', - editor: ConfigAvailability, - }, ], }, visconfig: { diff --git a/dashboards-observability/public/components/visualizations/charts/lines/line_type.ts b/dashboards-observability/public/components/visualizations/charts/lines/line_type.ts index 30be5bb2d..d02558b66 100644 --- a/dashboards-observability/public/components/visualizations/charts/lines/line_type.ts +++ b/dashboards-observability/public/components/visualizations/charts/lines/line_type.ts @@ -227,12 +227,6 @@ export const createLineTypeDefinition = (params: any = {}) => ({ mapTo: 'availabilityConfig', editor: ConfigAvailability, }, - { - id: 'availability-panel', - name: 'Availability', - mapTo: 'availabilityConfig', - editor: ConfigAvailability, - }, ], }, visconfig: { diff --git a/dashboards-observability/public/components/visualizations/charts/metrics/metrics_type.ts b/dashboards-observability/public/components/visualizations/charts/metrics/metrics_type.ts index 11b835def..bc8f6b546 100644 --- a/dashboards-observability/public/components/visualizations/charts/metrics/metrics_type.ts +++ b/dashboards-observability/public/components/visualizations/charts/metrics/metrics_type.ts @@ -164,12 +164,6 @@ export const createMetricsTypeDefinition = (params: any = {}) => ({ editor: ConfigEditor, content: [], }, - { - id: 'availability-panel', - name: 'Availability', - mapTo: 'availabilityConfig', - editor: ConfigAvailability, - }, ], }, visconfig: {