-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add reverse proxy checker (#21030)
* Add reverse proper checker * Create reverseProxyCheckerLogic.test.ts * Update reverseProxyCheckerLogic.test.ts * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (2) * Update UI snapshots for `chromium` (2) * Hook up reverseProxyCheckerLogic to the quick start menu task * Add a timestamp so it doesn't request too often --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
652b75d
commit fad9f5e
Showing
4 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
63 changes: 63 additions & 0 deletions
63
frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.test.ts
This file contains 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,63 @@ | ||
import { expectLogic } from 'kea-test-utils' | ||
|
||
import { useMocks } from '~/mocks/jest' | ||
import { initKeaTests } from '~/test/init' | ||
|
||
import { reverseProxyCheckerLogic } from './reverseProxyCheckerLogic' | ||
|
||
const hasReverseProxyValues = [['https://proxy.example.com'], [null]] | ||
const doesNotHaveReverseProxyValues = [[null], [null]] | ||
|
||
const useMockedValues = (results: (string | null)[][]): void => { | ||
useMocks({ | ||
post: { | ||
'/api/projects/:team/query': () => [ | ||
200, | ||
{ | ||
results, | ||
}, | ||
], | ||
}, | ||
}) | ||
} | ||
|
||
describe('reverseProxyCheckerLogic', () => { | ||
let logic: ReturnType<typeof reverseProxyCheckerLogic.build> | ||
|
||
beforeEach(() => { | ||
initKeaTests() | ||
localStorage.clear() | ||
logic = reverseProxyCheckerLogic() | ||
}) | ||
|
||
afterEach(() => { | ||
logic.unmount() | ||
}) | ||
|
||
it('should not have a reverse proxy set - when no data', async () => { | ||
useMockedValues([]) | ||
|
||
logic.mount() | ||
await expectLogic(logic).toFinishAllListeners().toMatchValues({ | ||
hasReverseProxy: false, | ||
}) | ||
}) | ||
|
||
it('should not have a reverse proxy set - when data with no lib_custom_api_host values', async () => { | ||
useMockedValues(doesNotHaveReverseProxyValues) | ||
|
||
logic.mount() | ||
await expectLogic(logic).toFinishAllListeners().toMatchValues({ | ||
hasReverseProxy: false, | ||
}) | ||
}) | ||
|
||
it('should have a reverse proxy set', async () => { | ||
useMockedValues(hasReverseProxyValues) | ||
|
||
logic.mount() | ||
await expectLogic(logic).toFinishAllListeners().toMatchValues({ | ||
hasReverseProxy: true, | ||
}) | ||
}) | ||
}) |
49 changes: 49 additions & 0 deletions
49
frontend/src/lib/components/ReverseProxyChecker/reverseProxyCheckerLogic.ts
This file contains 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,49 @@ | ||
import { afterMount, kea, path, reducers } from 'kea' | ||
import { loaders } from 'kea-loaders' | ||
import api from 'lib/api' | ||
|
||
import { HogQLQuery, NodeKind } from '~/queries/schema' | ||
import { hogql } from '~/queries/utils' | ||
|
||
import type { reverseProxyCheckerLogicType } from './reverseProxyCheckerLogicType' | ||
|
||
const CHECK_INTERVAL_MS = 1000 * 60 * 60 // 1 hour | ||
|
||
export const reverseProxyCheckerLogic = kea<reverseProxyCheckerLogicType>([ | ||
path(['components', 'ReverseProxyChecker', 'reverseProxyCheckerLogic']), | ||
loaders({ | ||
hasReverseProxy: [ | ||
false as boolean | null, | ||
{ | ||
loadHasReverseProxy: async () => { | ||
const query: HogQLQuery = { | ||
kind: NodeKind.HogQLQuery, | ||
query: hogql`SELECT properties.$lib_custom_api_host AS lib_custom_api_host | ||
FROM events | ||
WHERE timestamp >= now() - INTERVAL 1 DAY | ||
AND timestamp <= now() | ||
ORDER BY timestamp DESC | ||
limit 10`, | ||
} | ||
|
||
const res = await api.query(query) | ||
return !!res.results?.find((x) => !!x[0]) | ||
}, | ||
}, | ||
], | ||
}), | ||
reducers({ | ||
lastCheckedTimestamp: [ | ||
0, | ||
{ persist: true }, | ||
{ | ||
loadHasReverseProxySuccess: () => Date.now(), | ||
}, | ||
], | ||
}), | ||
afterMount(({ actions, values }) => { | ||
if (values.lastCheckedTimestamp < Date.now() - CHECK_INTERVAL_MS) { | ||
actions.loadHasReverseProxy() | ||
} | ||
}), | ||
]) |
This file contains 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
fad9f5e
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.
I believe due to this change every load of PH frontend causes an error message and toast:
Very cryptic error message and no recipe to fix it. Any advice?