Move GLQL and analytics dashboards from js-yaml to yaml
What does this MR do and why?
This MR moves GLQL and the analytics dashboards from js-yaml 3 to yaml 2. It is one step in moving the frontend to one YAML library.
These call sites move:
- The GLQL parser reads the GLQL blocks that users write in Markdown and in dashboard panels.
- The GLQL dashboard data source adds a dimension to a panel block for
expandRowsBy. Only the GLQL parser in the frontend reads that block again. - The Analyze with Duo button adds the dashboard scope and date range to each panel block. It sends the blocks to the Data Analyst agent as context.
The three call sites are in one MR because the dashboard code writes GLQL blocks that the GLQL parser reads again.
Options, and what I ruled out
Parsing:
- The
yamldefaults.js-yamlwas called withoutjson: true, so it threw on duplicate keys. Theyamldefault (uniqueKeys: true) throws too. isPlainObjectin the parser. Like the GLQL API, the parser reads a block as a config only when it is a map. Anything else is the query.js-yamlreturnedundefinedfor an empty block, andyamlreturnsnull. A plaintypeofcheck would readnull, and a list such as- type = Issue, as a config with no query.- I ruled out
version: '1.1'for parsing. It readsy,n,onandyesas booleans, keys included, wherejs-yamlreads strings. merge: true, in the parser and in the Analyze with Duo button.js-yamland the GLQL API's Psych both merge a<<key with an inline map, such as<<: {display: table}, in a block or in the frontmatter. Without the option,yamlkeeps<<as a key, and the browser shows the default display where the API shows a table. In the Duo button, the option also keeps the context free of aliases, which the API refuses (YAML.safe_loadwithoutaliases: true).
Writing, in the data source:
- The
yamldefaults. Only the GLQL parser in the frontend reads the block, with the same library and the same schema.
Writing, in the Analyze with Duo button:
version: '1.1'andsingleQuote: true. The agent can send a panel block to the GLQL API with itsrun_glql_querytool, and the context tells it to reuse the panel filters verbatim.Analytics::Glql::ParserServicereads the block with Psych, which implements YAML 1.1. With the 1.2 default,yamlwritesyes,on,2026-01-01,1:30and1_000without quotes. Psych then reads a boolean, aDate(whichsafe_loadrefuses), or a number.singleQuote: truekeeps the quote style ofjs-yaml.lineWidth: 0. This is theyamlform oflineWidth: -1: it turns off folding, so a long query stays on one line.- I ruled out
aliasDuplicateObjects: false.js-yamlwas called withoutnoRefs. The block comes from a parse, so it has a shared object only when the input has an alias, and the GLQL API refuses aliases.
Behaviour changes
- Blocks that are not a map. For a block that holds only a comment,
~,nullor a list,js-yamlreturned something other than a map. The parser read it as a config with no query, and the compiler failed withCannot read properties of undefined (reading 'length'). Now the parser reads the text as the query, as the GLQL API does, and the compiler shows a syntax error. An empty block is unchanged. - YAML 1.1 scalars that a user types. For
title: 2026-01-01,limit: 1_000,limit: 010,limit: 0777ortitle: 1:30,js-yamlreturned aDate, 1000, 8, 511 or 90.yamlreturns the string2026-01-01, the string1_000, the numbers 10 and 777, and the string1:30. The GLQL API reads 1000, 8 and 511, asjs-yamldid, and refuses the date. Only the YAML 1.1 schema would match the API there, and it also readsyesandonas booleans. No GLQL block in the docs, the specs or the dashboards holds such a value. - Merge keys with an alias.
js-yamlmerged<<: *xinto the map, and so doesyamlwithmerge: true. The GLQL API refuses any alias and runs the whole block as the query, so such a block already differed from the API. - Unknown tags. For
title: !foo bar,js-yamlthrew.yamlkeepsbarand logs a warning. - Parse error messages. A YAML error in a GLQL block shows the
yamlmessage, such asMap keys must be unique, in place of thejs-yamlmessage, such asduplicated mapping key. Both point to the line and column. - A breakdown block with no
querykey.js-yamlthrew on theundefinedvalue, so the data source failed.yamlleaves the key out. The panel still shows an error, because the main query of the same block has no query to compile. - The text of the Duo context.
yamldoes not quote strings that hold a comma or{, and it writes emoji as they are. Psych reads the same values, except for comma numbers: the button writes1,000,1,000.5and1,2,3without quotes, and Psych reads1000,1000.5and123.js-yamlquoted them. #639127 tracks a shared writer that quotes them, for every place that writes YAML for Ruby.
Parse errors still reach the same handling. Every call site uses a bare catch, or no catch. No code reads YAMLException or .mark.
How I verified it
I ran a temporary comparison spec, which this MR does not commit, against the first commit of this MR. Its corpus:
- Every string and template literal in the source and spec files of GLQL and the analytics dashboards, CE and EE: 9454 distinct strings.
- Every GLQL block in
doc/, with the examples of the GLQL API: 104 blocks. - Every GLQL block in the dashboard YAML files in
ee/lib/gitlab/analytics/: 54 blocks. - 22 hand-written cases: empty and comment-only blocks, YAML 1.1 scalars, anchors and long queries.
Results:
- Parser. All doc and dashboard blocks give the same query and config. Of the spec strings, 185 throw with both libraries, and 229 give a different result. The 229 are not GLQL blocks: they are dates, colours, CSS classes and comments. Each one failed to compile before and fails now, 222 of them with the
Cannot read properties of undefinederror before. - Data source. I added a dimension to every block that parses the same, wrote it with both libraries and parsed it back with the matching parser. 9103 of 9212 give the same result. The other 109 have no query, and
js-yamlthrew on them. - Duo button. 190 blocks have a string query. I read both dumps with Psych, as
Analytics::Glql::ParserServicedoes and with the options ofGitlab::Config::Loader::Yaml. In all 190, Psych reads the same values, and they equal the object in JavaScript. With the 1.2 default, 5 of the hand-written cases change in Psych. - Dashboard files. All 60 YAML files in
ee/lib/gitlab/analytics/parse to the same value withjs-yamlloadandyamlparse. A spec of the dashboard preview reads two of them.
New specs pin the map check and merge: true in the parser, and the quotes and merged keys in the Duo context. The parser spec fails without isPlainObject or without merge: true. The Duo spec fails with the 1.2 default or without merge: true.
For each difference raised in review, I ran both runtimes: parseYAML from master and from this branch in Jest, and the real Analytics::Glql::ParserService with Psych 5.3.1. After the review changes, I ran parseYAML from master and from this branch over every GLQL block in doc/ and in the dashboard YAML files again. All give the same query and config.
The specs in these directories pass locally:
spec/frontend/glqlspec/frontend/explore/analytics_dashboardsee/spec/frontend/explore/analytics_dashboardsee/spec/frontend/glql
I ran a temporary feature spec in GDK, once at the merge-base and once at the MR head. The spec was not committed. It opens an issue whose description has five GLQL blocks:
- A valid block. It shows the same three issues in both runs.
- A block with a duplicate
titlekey. The error changes fromduplicated mapping keytoMap keys must be unique. Both point to line 2, column 1. - A block with only a comment. The error changes from
Cannot read properties of undefined (reading 'length')toUnexpected token near # Only a comment. - A block with an inline merge key,
<<: {display: table, title: Inline merge}. It shows a table in both runs, becausemerge: truekeeps thejs-yamlbehaviour. - A list block,
- type = Issue. The error changes fromCannot read properties of undefined (reading 'length')toUnexpected token near - type = Issue, because the parser now reads it as the query, as the GLQL API does.
Screenshots
Before (f5d5da4c) |
After (96fbb372) |
|---|---|
![]() |
![]() |
References
- Part of #638642 (closed)
- First MR of the series: !268430 (merged)
- Review points on merge keys, non-map blocks and YAML 1.1 scalars: !268469 (comment 4213330922) and !268469 (comment 4213332226)
- Shared Psych-compatible writer, including comma numbers: #639127
- Follow-up for panels that drop out of the Duo context: #639779 (closed)
- The migration came out of the review of !267423 (merged)

