GLQL frontend fails on blocks the GLQL API accepts: Duo drops panels, a map without query crashes
Problem
Analyze with Duo leaves a GLQL panel out of the agent's context when the panel is not a YAML block with a query key. The user gets no message, and only Sentry records the error.
withFilters in ee/app/assets/javascripts/explore/analytics_dashboards/components/analyze_with_duo_button.vue parses the panel text as one YAML document and needs a query key. The GLQL parser and the GLQL API accept two more forms, and both fail here:
| Panel form | GLQL parser (parseYAML) |
GLQL API (Analytics::Glql::ParserService) |
withFilters |
|---|---|---|---|
Block with query: |
runs | runs | adds the filters |
Frontmatter (---\ntitle: x\n---\ntype = Issue) |
runs | runs | throws: the text holds two YAML documents |
Bare query (type = Issue) |
runs | runs | throws GLQL panel has no query to filter |
When withFilters throws, the catch in resolvedPanels reports the error to Sentry and drops the panel. The dashboard still shows the panel, but the agent does not get it.
This does not affect the built-in dashboards today: all 57 GLQL panels in ee/lib/gitlab/analytics/ use the block form. It affects any panel written in the other two forms.
The behaviour is the same with js-yaml on master and with yaml in !268469 (merged), so that migration does not cause it.
Proposal
- Read the panel with
parseYAMLfrom~/glql/core/parser. It already returns{ query, config }for all three forms, andwithDimensionindata_sources/glql.jsuses it. - Write the result back as a block, with the filters added to
query. - Add spec cases for a frontmatter panel and a bare-query panel.
Things to check:
parseYAMLConfigsetsdisplayto the default when the panel has none. Decide whether the Duo context should get that default, or only the keys the panel sets.- Write the block with the Psych-compatible writer from #639127 if that lands first. The agent can send the block to the GLQL API, which reads it with Psych.
How I checked 🤖
- I ran
withFiltersfrommasterand from the branch of !268469 (merged) in Jest, with a frontmatter panel and a bare-query panel. Both versions throw for both panels. - I ran the same texts through the real
Analytics::Glql::ParserService(Psych 5.3.1). It returns{ config: { title: 'x' }, query: 'type = Issue' }for the frontmatter panel and{ config: {}, query: 'type = Issue' }for the bare query. - I loaded every dashboard YAML file in
ee/lib/gitlab/analytics/and sorted its GLQL panels by form. All 57 are blocks with aquerykey.
Also: a map without query crashes the GLQL parser
A block that is a map but has no query key, such as title: x, fails in the browser. The GLQL API runs the same text as the query.
| Block | GLQL parser (parse in app/assets/javascripts/glql/core/parser.js) |
GLQL API (Analytics::Glql::ParserService) |
|---|---|---|
title: x |
parseYAML returns a config with no query, and parseQuery throws TypeError: Cannot read properties of undefined (reading 'length') |
{ config: {}, query: 'title: x' } |
isValidYAMLaccepts any map, soparseYAMLtakes the map as the config and leavesqueryundefined.- The API reads the text as a config only when the map has a
querykey. Otherwise it runs the whole text as the query. - This happens on
masterwithjs-yamltoo, so !268469 (merged) does not cause it. That MR made the parser read anything that is not a map as the query, like the API, and left this case for here.
Proposal: in parseYAML, read the text as a config only when the map has a string query, as ParserService#get_standard_yaml does. Otherwise use the whole text as the query, so the compiler reports a syntax error instead of a TypeError. Add a spec case for title: x.
How I checked 🤖
- I called
parse('title: x\n')from~/glql/core/parserin Jest on the branch of !268469 (merged) (96fbb372). It throws theTypeErrorabove. parseYAML('title: x\n')frommasterand from that branch both return{ config: { title: 'x', display: 'list' } }, with noquery.- The real
Analytics::Glql::ParserServicewith Psych 5.3.1 returns{ config: {}, query: 'title: x' }.
References
- Raised in the review of !268469 (comment 4213332322)
- The map without
querywas raised in !268469 (comment 4213332226) - Related writer helper: #639127
- Part of the YAML library work in #638642 (closed)