Repository navigation
feat(team): add setting for default and allowed query languages - #3282
kunalbhatia2601 wants to merge 5 commits into
Conversation
🦋 Changeset detectedLatest commit: e109007 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@kunalbhatia2601 is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @kunalbhatia2601, thanks for the pull request! Before we review code from a first-time contributor we ask that a maintainer vouches for you, and you're not on our list yet. This PR stays open — it just isn't in the review queue until someone vouches. To get vouched, open an issue saying hello and what you're working on: https://github.com/hyperdxio/hyperdx/issues/new?template=introduce-yourself.md A maintainer will usually reply within a day or two, and then this PR gets picked up as normal. More detail in our contributing guide. |
PR Review
9 finding(s): 🔴 0 critical · 🟠 3 major · 🔵 6 minor 5 posted as inline comment(s) on the changed lines. 4 listed below. Findings outside the changed lines4 minor
Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
|
Deep Review✅ No critical issues found. No P0/P1 ship-blockers. Of the prior review's four P1s, three are resolved in the current diff: the concurrent-update TOCTOU is now closed by the atomic 🟡 P2 -- recommended
🔵 P3 nitpicks (6)
Reviewers (5): security, maintainability, testing, project-standards, learnings-researcher. Coverage note: the full fan-out (13 reviewers: the 5 above plus correctness, adversarial, api-contract, data-migrations, kieran-typescript, julik-frontend-races, previous-comments, agent-native) was dispatched, but 8 had not returned when synthesis was finalized. Their highest-stakes areas were covered by direct orchestrator analysis: the TOCTOU atomic-update filter, the Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (languageField.value && allowedLanguages.includes(languageField.value)) { |
There was a problem hiding this comment.
🟠 major — Team defaultQueryLanguage is never applied when both languages are allowed
Every page builds its initial language as searchedConfig.whereLanguage ?? getStoredLanguage() ?? 'lucene' (DBSearchPage.tsx:529/1143/1265, DBDashboardPage.tsx:383, SessionsPage.tsx:256, EditTimeChartForm.tsx:170, …). None of them pass the team, so the form value is already 'lucene'. This effect returns early because 'lucene' is allowed. Result: a team that sets the default to SQL and keeps both languages enabled still gets Lucene everywhere. Resolve defaults through the team, for example a useDefaultQueryLanguage() hook or passing me.team into getStoredLanguage, at the places where defaults are built. Then add a test that renders a page or form rather than only the pure helper.
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
| return; | ||
| } | ||
| const target = | ||
| getStoredLanguage(me?.team) ?? allowedLanguages[0] ?? 'lucene'; |
There was a problem hiding this comment.
🟠 major — Before /me loads, unset language fields are switched to SQL instead of Lucene
While me is loading, allowedLanguages is DEFAULT_QUERY_LANGUAGES, which is the zod enum order ['sql','lucene'] (common-utils/src/types.ts:153). getStoredLanguage(undefined) returns null when there is no stored preference. So any form whose language field is undefined gets allowedLanguages[0] = 'sql' written into it. That value is allowed, so it is never corrected after /me resolves, which overrides both the previous Lucene default and the team default. Skip reconciliation until me has loaded, and fall back to the team default or 'lucene' rather than allowedLanguages[0].
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
| } | ||
| const target = | ||
| getStoredLanguage(me?.team) ?? allowedLanguages[0] ?? 'lucene'; | ||
| handleLanguageChange(target, { isUserSelection: false }); |
There was a problem hiding this comment.
🟠 major — Language is switched on existing queries without touching the WHERE text
Suppose a saved search, dashboard tile, alert or URL holds where: 'level:error', whereLanguage: 'lucene' and the team later allows only SQL. This effect silently changes the language to 'sql' but keeps the Lucene text. That produces invalid SQL. For SessionsPage, onLanguageChange also writes it into appliedConfig (SessionsPage.tsx:420). Either keep showing and running the stored language for existing queries and restrict only new selections, or clear or flag the incompatible WHERE when the language is forced.
Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond
| }); | ||
|
|
||
| const language: 'sql' | 'lucene' = languageField.value ?? 'lucene'; | ||
| const language: QueryLanguage = allowedLanguages.includes(languageField.value) |
There was a problem hiding this comment.
🔵 minor — Display fallback duplicates getStoredLanguage(team) with a different precedence
The language ternary picks the team default first. The effect at line 240 uses getStoredLanguage(me?.team), which picks the stored preference first. When they disagree, the select briefly shows one language and then the effect writes the other. Compute both from one helper, for example const resolved = getStoredLanguage(me?.team), and use it for both the display and the reconciliation.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| defaultQueryLanguage: 'sql', | ||
| }); | ||
| expect(lang).toBe('sql'); | ||
| expect( |
There was a problem hiding this comment.
🔵 minor — The test that reconciliation does not persist to localStorage cannot fail
It calls only the pure getStoredLanguage, which never writes to localStorage. The behaviour it claims to cover is the isUserSelection guard in the component's useEffect. Render SearchWhereInput with a mocked useMe returning a SQL-only team and a form value of 'lucene'. Then assert that the field becomes 'sql' and that localStorage stays null.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| if (options?.isUserSelection) { | ||
| setStoredLanguage(lang); | ||
| } |
There was a problem hiding this comment.
Disabled language remains stored When a team disables a language the user previously selected, reconciliation changes the search form but leaves that language in localStorage. On a dashboard without an explicit language, the stored value can then control the URL and query while the editor displays the allowed language. The dashboard may run the query in a language the team disabled.
Knowledge Base Used: Identity, teams, and configuration
| it('updateTeamQueryLanguageSettings works in local app mode', async () => { | ||
| const origLocalMode = config.IS_LOCAL_APP_MODE; | ||
| try { | ||
| (config as { IS_LOCAL_APP_MODE: boolean }).IS_LOCAL_APP_MODE = true; |
There was a problem hiding this comment.
Test uses avoidable casts The local-mode test casts the imported configuration to change it here and casts it again to restore it. The repository’s TypeScript guide says to avoid
as casts when type inference or a typed alternative is possible. This repository requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
Some teams require using only Lucene or only SQL in their telemetry search workflows. This PR introduces team-level query language settings (
defaultQueryLanguageandallowedQueryLanguages) to allow teams to configure their preferred default query language and enable or disable specific languages across search inputs.defaultQueryLanguageandallowedQueryLanguagesfields to theTeammodel andTeamSchemavalidation schemas.PATCH /team/query-language-settingsAPI endpoint with validation to ensure at least one query language remains enabled and the default language is among the allowed set./team?tab=advanced).InputLanguageSwitchandSearchWhereInputcomponents to restrict dropdown choices and enforce the team's allowed query language settings.Steps:
/team?tab=advancedand locate the "Query Language Settings" section./searchand locate the search input language switch.References