-
Notifications
You must be signed in to change notification settings - Fork 3
web: fix topology device markers placed in the water #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
armcconnell
wants to merge
1
commit into
main
Choose a base branch
from
fix/topology-device-coordinates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { | ||
| computeDevicePositions, | ||
| FANOUT_RADIUS_DEG, | ||
| FACILITY_JITTER_DEG, | ||
| type PositionableDevice, | ||
| type PositionableMetro, | ||
| } from './devicePositions' | ||
|
|
||
| const metroMap = new Map<string, PositionableMetro>([ | ||
| ['metro-nyc', { latitude: 40.779, longitude: -74.072 }], | ||
| ]) | ||
|
|
||
| function dev(pk: string, over: Partial<PositionableDevice> = {}): PositionableDevice { | ||
| return { pk, metro_pk: 'metro-nyc', latitude: 0, longitude: 0, ...over } | ||
| } | ||
|
|
||
| function dist(a: [number, number], b: [number, number]): number { | ||
| return Math.hypot(a[0] - b[0], a[1] - b[1]) | ||
| } | ||
|
|
||
| describe('computeDevicePositions — fanout mode', () => { | ||
| it('places a lone device at the metro center', () => { | ||
| const pos = computeDevicePositions([dev('d1')], metroMap, 'fanout') | ||
| expect(pos.get('d1')).toEqual([-74.072, 40.779]) | ||
| }) | ||
|
|
||
| it('spreads co-metro devices within the (small) fanout radius and keeps them distinct', () => { | ||
| const devices = [dev('d1'), dev('d2'), dev('d3'), dev('d4')] | ||
| const pos = computeDevicePositions(devices, metroMap, 'fanout') | ||
| const center: [number, number] = [-74.072, 40.779] | ||
| const coords = devices.map(d => pos.get(d.pk)!) | ||
| // every marker stays close to the metro center (latitude offset bounded by the radius) | ||
| for (const c of coords) { | ||
| expect(Math.abs(c[1] - center[1])).toBeLessThanOrEqual(FANOUT_RADIUS_DEG + 1e-9) | ||
| expect(c).not.toEqual(center) | ||
| } | ||
| // markers are distinct from one another | ||
| const keys = new Set(coords.map(c => `${c[0]},${c[1]}`)) | ||
| expect(keys.size).toBe(4) | ||
| }) | ||
| }) | ||
|
|
||
| describe('computeDevicePositions — facility mode', () => { | ||
| it('anchors a lone device exactly at its facility coordinates', () => { | ||
| const pos = computeDevicePositions( | ||
| [dev('d1', { latitude: 40.7968, longitude: -74.03088 })], | ||
| metroMap, | ||
| 'facility', | ||
| ) | ||
| expect(pos.get('d1')).toEqual([-74.03088, 40.7968]) | ||
| }) | ||
|
|
||
| it('jitters co-located devices around the shared facility, within the jitter radius', () => { | ||
| const fac = { latitude: 40.7968, longitude: -74.03088 } | ||
| const devices = [ | ||
| dev('d1', fac), | ||
| dev('d2', fac), | ||
| dev('d3', fac), | ||
| ] | ||
| const pos = computeDevicePositions(devices, metroMap, 'facility') | ||
| const anchor: [number, number] = [fac.longitude, fac.latitude] | ||
| const coords = devices.map(d => pos.get(d.pk)!) | ||
| for (const c of coords) { | ||
| // stays within the small jitter radius of the real facility (not flung away) | ||
| expect(dist(c, anchor)).toBeLessThanOrEqual(FACILITY_JITTER_DEG / Math.cos(fac.latitude * Math.PI / 180) + 1e-6) | ||
| } | ||
| const keys = new Set(coords.map(c => `${c[0]},${c[1]}`)) | ||
| expect(keys.size).toBe(3) | ||
| }) | ||
|
|
||
| it('falls back to the metro fanout when a device has no facility coordinates', () => { | ||
| // facility coords 0/0 => missing; should NOT end up at [0,0] | ||
| const pos = computeDevicePositions([dev('d1')], metroMap, 'facility') | ||
| expect(pos.get('d1')).toEqual([-74.072, 40.779]) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
LEFT JOIN dz_facilities_current f ON d.location_pk = f.pkreferencesd.location_pk, which is not guaranteed present in every environment the API serves (e.g. remote proxy tables created before thelocation_pkmigration). Every sibling handler that touches this column guards against its absence:devices.go:204-217builds a fallback query stripping the identical join and retries onisUnknownIdentifierError(ClickHouse code 47);facilities.go:202/:290andmetros.go:246do the same.This query runs unguarded inside an
errgroupgoroutine, so on an environment lackinglocation_pkthe error failsFetchTopologyDatawholesale and/api/topologyreturns 500 — taking down map, globe, and the non-geo graph — while the devices/facilities pages on the same deployment keep working via their fallback.Fix: mirror the sibling pattern — on
isUnknownIdentifierError, retry with the join removed and0 as latitude, 0 as longitude(the frontend already treats 0/0 as "no facility coords" and falls back to the metro fanout, so it degrades cleanly).