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 yaml defaults. js-yaml was called without json: true, so it threw on duplicate keys. The yaml default (uniqueKeys: true) throws too.
  • isPlainObject in 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-yaml returned undefined for an empty block, and yaml returns null. A plain typeof check would read null, and a list such as - type = Issue, as a config with no query.
  • I ruled out version: '1.1' for parsing. It reads y, n, on and yes as booleans, keys included, where js-yaml reads strings.
  • merge: true, in the parser and in the Analyze with Duo button. js-yaml and 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, yaml keeps << 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_load without aliases: true).

Writing, in the data source:

  • The yaml defaults. 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' and singleQuote: true. The agent can send a panel block to the GLQL API with its run_glql_query tool, and the context tells it to reuse the panel filters verbatim. Analytics::Glql::ParserService reads the block with Psych, which implements YAML 1.1. With the 1.2 default, yaml writes yes, on, 2026-01-01, 1:30 and 1_000 without quotes. Psych then reads a boolean, a Date (which safe_load refuses), or a number. singleQuote: true keeps the quote style of js-yaml.
  • lineWidth: 0. This is the yaml form of lineWidth: -1: it turns off folding, so a long query stays on one line.
  • I ruled out aliasDuplicateObjects: false. js-yaml was called without noRefs. 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, ~, null or a list, js-yaml returned something other than a map. The parser read it as a config with no query, and the compiler failed with Cannot 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: 0777 or title: 1:30, js-yaml returned a Date, 1000, 8, 511 or 90. yaml returns the string 2026-01-01, the string 1_000, the numbers 10 and 777, and the string 1:30. The GLQL API reads 1000, 8 and 511, as js-yaml did, and refuses the date. Only the YAML 1.1 schema would match the API there, and it also reads yes and on as booleans. No GLQL block in the docs, the specs or the dashboards holds such a value.
  • Merge keys with an alias. js-yaml merged <<: *x into the map, and so does yaml with merge: 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-yaml threw. yaml keeps bar and logs a warning.
  • Parse error messages. A YAML error in a GLQL block shows the yaml message, such as Map keys must be unique, in place of the js-yaml message, such as duplicated mapping key. Both point to the line and column.
  • A breakdown block with no query key. js-yaml threw on the undefined value, so the data source failed. yaml leaves 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. yaml does 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 writes 1,000, 1,000.5 and 1,2,3 without quotes, and Psych reads 1000, 1000.5 and 123. js-yaml quoted 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 undefined error 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-yaml threw on them.
  • Duo button. 190 blocks have a string query. I read both dumps with Psych, as Analytics::Glql::ParserService does and with the options of Gitlab::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 with js-yaml load and yaml parse. 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/glql
  • spec/frontend/explore/analytics_dashboards
  • ee/spec/frontend/explore/analytics_dashboards
  • ee/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 title key. The error changes from duplicated mapping key to Map 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') to Unexpected token near # Only a comment.
  • A block with an inline merge key, <<: {display: table, title: Inline merge}. It shows a table in both runs, because merge: true keeps the js-yaml behaviour.
  • A list block, - type = Issue. The error changes from Cannot read properties of undefined (reading 'length') to Unexpected token near - type = Issue, because the parser now reads it as the query, as the GLQL API does.

Screenshots

Before (f5d5da4c) After (96fbb372)
before_light after_light

References

Edited by Miguel Rincon

Merge request reports

Loading
Loading