chore: replace getConfigValue with direct getConfig() property access#3589
chore: replace getConfigValue with direct getConfig() property access#3589yurishkuro merged 4 commits intomainfrom
getConfigValue with direct getConfig() property access#3589Conversation
getConfigValue with direct getConfig() property access
Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
…rvices Co-authored-by: yurishkuro <3523016+yurishkuro@users.noreply.github.com>
2478546 to
4480d93
Compare
| if (getConfig().storageCapabilities?.metricsStorage) { | ||
| NAV_LINKS.push({ |
There was a problem hiding this comment.
Critical Logic Change: This line changes the condition from monitor.menuEnabled to storageCapabilities?.metricsStorage, which is not a type-safe refactor but an actual behavior change.
Old code:
if (getConfigValue('monitor.menuEnabled')) {New code:
if (getConfig().storageCapabilities?.metricsStorage) {Impact: The Monitor menu item will now appear based on storage capabilities instead of the explicit monitor.menuEnabled config flag. This breaks the documented behavior in the comment above (lines 67-69 in old code) which states the Monitor page itself should handle storage capability checks while the menu is controlled by monitor.menuEnabled.
Fix: Change to getConfig().monitor?.menuEnabled to preserve the original logic.
| if (getConfig().storageCapabilities?.metricsStorage) { | |
| NAV_LINKS.push({ | |
| if (getConfig().monitor?.menuEnabled) { | |
| NAV_LINKS.push({ | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Pull request overview
This PR removes the unsafe getConfigValue(path: string): any helper and migrates callers to direct, type-checked getConfig() property access across jaeger-ui, updating tests accordingly.
Changes:
- Deleted
getConfigValuefromget-config.ts(and removed thelodash/getdependency). - Migrated config access at call sites to
getConfig().…with optional chaining / nullish coalescing where needed. - Updated Jest tests to mock / spy on the
getConfigdefault export instead ofgetConfigValue.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/jaeger-ui/src/utils/config/process-scripts.ts | Uses getConfig().scripts instead of string-path lookup. |
| packages/jaeger-ui/src/utils/config/process-scripts.test.js | Mocks getConfig default export to return structured config. |
| packages/jaeger-ui/src/utils/config/get-target.ts | Reads forbidNewPage via getConfig() property access. |
| packages/jaeger-ui/src/utils/config/get-target.test.js | Updates mocks to getConfig default export. |
| packages/jaeger-ui/src/utils/config/get-config.ts | Removes getConfigValue and lodash/get import. |
| packages/jaeger-ui/src/utils/config/get-config.test.js | Deletes getConfigValue tests and import. |
| packages/jaeger-ui/src/model/transform-trace-data.ts | Replaces getConfigValue('topTagPrefixes') with getConfig().topTagPrefixes and adjusts typing. |
| packages/jaeger-ui/src/model/link-patterns.ts | Switches to getConfig().linkPatterns and adds a type-predicate filter. |
| packages/jaeger-ui/src/components/common/TraceId.tsx | Reads traceIdDisplayLength via getConfig(). |
| packages/jaeger-ui/src/components/common/TraceId.test.js | Mocks getConfig default export. |
| packages/jaeger-ui/src/components/TraceDiff/TraceDiffGraph/TraceDiffGraph.tsx | Reads traceDiff.helpLink via getConfig().traceDiff?.helpLink. |
| packages/jaeger-ui/src/components/TraceDiff/TraceDiffGraph/TraceDiffGraph.test.js | Spies on getConfig default export and returns structured config. |
| packages/jaeger-ui/src/components/SearchTracePage/SearchResults/AltViewOptions.tsx | Uses getConfig().deepDependencies?.menuEnabled. |
| packages/jaeger-ui/src/components/SearchTracePage/SearchResults/AltViewOptions.test.js | Updates config mocking to getConfig default export. |
| packages/jaeger-ui/src/components/SearchTracePage/SearchForm.tsx | Uses getConfig().search?.maxLimit for max constraint. |
| packages/jaeger-ui/src/components/Monitor/index.tsx | Gates services vs empty state on getConfig().storageCapabilities?.metricsStorage. |
| packages/jaeger-ui/src/components/Monitor/index.test.js | Updates mock config object to include storageCapabilities.metricsStorage. |
| packages/jaeger-ui/src/components/Monitor/ServicesView/index.tsx | Reads monitor.docsLink via getConfig().monitor?.docsLink. |
| packages/jaeger-ui/src/components/Monitor/ServicesView/index.test.js | Updates mock config shape for monitor docs link. |
| packages/jaeger-ui/src/components/Monitor/EmptyState/index.tsx | Reads monitor.emptyState via getConfig().monitor?.emptyState ?? {}. |
| packages/jaeger-ui/src/components/Monitor/EmptyState/index.test.js | Updates mocks to return nested monitor.emptyState. |
| packages/jaeger-ui/src/components/DependencyGraph/index.tsx | Uses ?? fallback with getConfig().dependencies?.dagMaxNumServices. |
| packages/jaeger-ui/src/components/DeepDependencies/index.tsx | Reads search.maxLookback.value via getConfig().search?.maxLookback?.value. |
| packages/jaeger-ui/src/components/DeepDependencies/index.test.js | Updates config spy to return nested search.maxLookback.value. |
| packages/jaeger-ui/src/components/DeepDependencies/SidePanel/index.tsx | Uses getConfig().pathAgnosticDecorations for decorations. |
| packages/jaeger-ui/src/components/DeepDependencies/SidePanel/index.test.js | Updates config spy to return pathAgnosticDecorations. |
| packages/jaeger-ui/src/components/App/TopNav.tsx | Switches nav feature gates to getConfig() property reads (incl. monitor / quality metrics). |
| packages/jaeger-ui/src/components/App/TopNav.test.js | Updates mock config structure for nav gating and labels. |
| packages/jaeger-ui/src/components/App/ThemeStorage.ts | Uses getConfig().themes?.enabled instead of getConfigValue. |
| packages/jaeger-ui/src/components/App/ThemeStorage.test.ts | Mocks getConfig default export to enable/disable themes. |
| packages/jaeger-ui/src/components/App/ThemeProvider.test.tsx | Mocks getConfig default export to enable/disable themes. |
| packages/jaeger-ui/src/actions/path-agnostic-decorations.ts | Reads pathAgnosticDecorations via getConfig() directly. |
| packages/jaeger-ui/src/actions/path-agnostic-decorations.test.js | Updates spies/mocks to return structured getConfig() results. |
Comments suppressed due to low confidence (1)
packages/jaeger-ui/src/components/App/TopNav.tsx:73
- TopNav now gates the "Monitor" nav link solely on
storageCapabilities.metricsStorage. However,Configstill definesmonitor.menuEnabledand the default config sets it totrue, so configs that explicitly disable the monitor menu will no longer be honored, and the Monitor empty-state/setup page also becomes undiscoverable when metrics storage is disabled. Either (a) includegetConfig().monitor?.menuEnabledin this condition (optionally in addition tometricsStorage, depending on intended UX), or (b) remove/deprecatemonitor.menuEnabledfrom the config type + default config if it is no longer supported to avoid misleading configuration.
if (getConfig().storageCapabilities?.metricsStorage) {
NAV_LINKS.push({
to: monitorATMUrl.getUrl(),
matches: monitorATMUrl.matches,
text: 'Monitor',
});
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| it('getTargetEmptyOrBlank returns _blank because forbidNewPage is true', () => { | ||
| getConfigValueSpy.mockReturnValue(false); | ||
| getConfigSpy.mockReturnValue({ forbidNewPage: false }); |
There was a problem hiding this comment.
This test description says "forbidNewPage is true" but the mocked config sets forbidNewPage: false, so the wording is misleading when reading failures. Update the it(...) text to reflect the false case.
| it('getTargetBlankOrTop returns _blank because forbidNewPage is true', () => { | ||
| getConfigValueSpy.mockReturnValue(false); | ||
| getConfigSpy.mockReturnValue({ forbidNewPage: false }); |
There was a problem hiding this comment.
This test description says "forbidNewPage is true" but the mocked config sets forbidNewPage: false, so the wording is misleading when reading failures. Update the it(...) text to reflect the false case.
| if (getConfig().qualityMetrics?.menuEnabled) { | ||
| NAV_LINKS.push({ | ||
| to: qualityMetrics.getUrl(), | ||
| matches: qualityMetrics.matches, | ||
| text: getConfigValue('qualityMetrics.menuLabel'), | ||
| text: getConfig().qualityMetrics?.menuLabel ?? '', | ||
| }); |
There was a problem hiding this comment.
qualityMetrics.menuLabel is optional, but falling back to an empty string can produce a blank/invisible nav item when qualityMetrics.menuEnabled is true and the embedded config omits menuLabel (e.g., if it overwrites the whole qualityMetrics object). Prefer a meaningful fallback label (e.g., the default-config label) or skip adding the nav entry when the label is missing.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3589 +/- ##
==========================================
- Coverage 89.14% 89.12% -0.02%
==========================================
Files 304 304
Lines 9716 9713 -3
Branches 2592 2587 -5
==========================================
- Hits 8661 8657 -4
- Misses 1052 1053 +1
Partials 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
getConfigValue(path: string)accepted arbitrary string paths and returnedany, making typos silently returnundefinedat runtime and forcing callers to add unverified type annotations or casts.Changes
getConfigValuefromget-config.tsalong with the now-unusedlodash/getimportgetConfig()property access, removing manual type annotations and casts that only existed to compensate for theanyreturn type:Type fixes surfaced by the migration:
link-patterns.ts: replaced.filter(Boolean)with a type predicate to properly narrowProcessedLinkPattern[]transform-trace-data.ts: castreadonly string[]→string[]fororderTagsparameterTopNav.tsx: added?? ''fallback forqualityMetrics.menuLabel(string | undefined)DependencyGraph/index.tsx: replaced||with??fordagMaxNumServicesfallbackUpdated all test files that mocked
getConfigValueto mock thegetConfigdefault export instead, passing structured config objects rather than scalar valuesOriginal prompt
getConfigValueprovides no type safety for config access #3588💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.