Skip to content

Commit

Permalink
404 describe (#3104)
Browse files Browse the repository at this point in the history
* Detect Describe
* Only check if you can paginate if the lake has a describe endpoint
* isGroupBy only works if you have the describe endpoint
* Sync lake properly when current lake changes
* Distinguish between updating and adding lakes
* Don't run uid correlations if there is no poolName preset in the session
* Update the plugins when there is no describe endpoint
  • Loading branch information
jameskerr authored Jun 20, 2024
1 parent e73f73b commit 10d8974
Show file tree
Hide file tree
Showing 30 changed files with 168 additions and 84 deletions.
10 changes: 6 additions & 4 deletions apps/zui/src/app/lakes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {updateStatus} from "src/js/flows/lake/update-status"
import Current from "src/js/state/Current"
import LakeStatuses from "src/js/state/LakeStatuses"
import styled from "styled-components"
import {initCurrentTab} from "src/js/flows/initCurrentTab"
import {invoke} from "src/core/invoke"
import {Active} from "src/models/active"

const SpinnerWrap = styled.div`
width: 100%;
Expand All @@ -25,8 +25,10 @@ export function InitLake({children}) {
const status = useSelector(LakeStatuses.get(lake?.id))

useLayoutEffect(() => {
if (status) return
if (lake) dispatch(updateStatus(lake.id))
if (Active.lake) {
dispatch(updateStatus(lake.id))
Active.lake.sync()
}
}, [lake?.id, status])

useEffect(() => {
Expand All @@ -35,7 +37,7 @@ export function InitLake({children}) {

switch (status) {
case "disconnected":
return <ConnectionError onRetry={() => dispatch(initCurrentTab())} />
return <ConnectionError onRetry={() => dispatch(updateStatus(lake.id))} />
case "login-required":
return <Login lake={lake} />
case "connected":
Expand Down
4 changes: 3 additions & 1 deletion apps/zui/src/app/menus/value-context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import * as zed from "@brimdata/zed-js"
import {createMenu} from "src/core/menu"
import ZuiApi from "src/js/api/zui-api"
import QueryInfo from "src/js/state/QueryInfo"
import {Active} from "src/models/active"

function getWhenContext(api: ZuiApi, value: zed.Any) {
return {
isPrimitive: zed.isPrimitive(value),
isIterable: zed.isIterable(value),
isGroupBy: api.select(QueryInfo.hasAggregation),
isGroupBy:
Active.lake.features.describe && api.select(QueryInfo.hasAggregation),
selectedText: document.getSelection().toString() || null,
isIp: value instanceof zed.Ip,
}
Expand Down
1 change: 0 additions & 1 deletion apps/zui/src/components/toolbar-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function cancelTimer() {

function checkTimer() {
const ellapsed = new Date().getTime() - time.getTime()
console.log(ellapsed)
if (ellapsed > 10 * 1000) {
throw new Error("Expected Scaling to Be Finished After 10 Seconds")
}
Expand Down
1 change: 1 addition & 0 deletions apps/zui/src/core/main/main-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class MainObject {
}

openUrl(uri: string) {
// This is written to handle an auth0 url
const urlParts = url.parse(uri, true)
const {code, state, error, error_description} = urlParts.query as {
[key: string]: string
Expand Down
2 changes: 1 addition & 1 deletion apps/zui/src/domain/editor/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const describe = createOperation(
"editor.describe",
async (ctx, string, pool?) => {
try {
const resp = await lake.client.describeQuery(string, pool)
const resp = await lake.client.describeQuery(string, {pool})
return resp.error ? {error: resp} : resp
} catch (error) {
return {error: error.toString()}
Expand Down
2 changes: 1 addition & 1 deletion apps/zui/src/domain/results/handlers/export.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {addFuse, cutColumns} from "../utils"
import Results from "src/js/state/Results"
import {RESULTS_QUERY} from "src/views/results-pane/run-results-query"
import {RESULTS_QUERY} from "src/views/results-pane/config"
import {ResponseFormat} from "@brimdata/zed-js"
import {errorToString} from "src/util/error-to-string"
import {createHandler} from "src/core/handlers"
Expand Down
10 changes: 5 additions & 5 deletions apps/zui/src/js/components/LakeModals/ViewLakeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ const ViewLake = ({onClose, onEdit}) => {
<button type="submit" onClick={onEdit} className="button submit">
Edit
</button>
{!isDefault && (
<div className={styles.logout}>
<Link onClick={onRemove}>Logout</Link>
</div>
)}
</div>
{!isDefault && (
<div className={styles.logout}>
<Link onClick={onRemove}>Logout</Link>
</div>
)}
</form>
)
}
Expand Down
14 changes: 0 additions & 14 deletions apps/zui/src/js/flows/initCurrentTab.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/zui/src/js/flows/inspectSearch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Results from "../state/Results"
import {RESULTS_QUERY} from "src/views/results-pane/run-results-query"
import {RESULTS_QUERY} from "src/views/results-pane/config"
import {Thunk} from "../state/types"

export const inspectSearch =
Expand Down
2 changes: 1 addition & 1 deletion apps/zui/src/js/flows/lake/buildAndAuthenticateLake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const buildAndAuthenticateLake =
const lake = await dispatch(buildLake(attrs, abortSignal))

if (lake.authType === "none") {
dispatch(saveLake(lake, "connected"))
dispatch(saveLake(lake.attrs, "connected"))
return [false, null]
}

Expand Down
11 changes: 9 additions & 2 deletions apps/zui/src/js/flows/lake/saveLake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import LakeStatuses from "../../state/LakeStatuses"
import {LakeStatus} from "../../state/LakeStatuses/types"
import Window from "src/js/state/Window"
import {LakeAttrs} from "src/js/state/Lakes/types"
import {Lake} from "src/models/lake"

export const saveLake =
(attrs: LakeAttrs, status: LakeStatus) =>
(dispatch, _gs): void => {
dispatch(Lakes.add(attrs))
(dispatch): void => {
const {id} = attrs
const lake = Lake.find(id)
if (lake) {
lake.update(attrs)
} else {
dispatch(Lakes.add(attrs))
}
dispatch(LakeStatuses.set(attrs.id, status))
dispatch(Window.setLakeId(attrs.id))
dispatch(syncPoolsData())
Expand Down
5 changes: 1 addition & 4 deletions apps/zui/src/js/flows/lake/update-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const updateStatus =
try {
// check version to test that zqd is available, update lake version while doing so
const {version} = await zealot.version()
lakeModel.attrs.version = version
lakeModel.update({version})
return false
} catch (e) {
console.error(e)
Expand All @@ -36,9 +36,6 @@ export const updateStatus =

if (await isDown()) return

// update version
dispatch(Lakes.add(lakeModel.serialize()))

// no auth required
if (lakeModel.authType === "none") {
activate()
Expand Down
16 changes: 8 additions & 8 deletions apps/zui/src/js/initializers/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ export default async function initialize(
const api = new ZuiApi()
const store = await initStore(api, renderer)
const asyncTasks = initAsyncTasks(renderer)
await initGlobals(store)
await initLake(store)
api.init(store.dispatch, store.getState)
initDOM()
initIpcListeners(store)
initDomainModels({store})
initHandlers({
transition: startTransition,
oldApi: api,
Expand All @@ -59,9 +55,13 @@ export default async function initialize(
toast,
asyncTasks,
})
initDomainModels({
store,
})

await initGlobals(store)
await initLake(store)
api.init(store.dispatch, store.getState)
initDOM()
initIpcListeners(store)

ViewHandler.store = store
setMenuContext({select: (fn) => fn(store.getState()), api})
initDebugGlobals(store, api)
Expand Down
7 changes: 7 additions & 0 deletions apps/zui/src/js/state/Lakes/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const slice = createSlice({
const id = action.payload
delete state[id]
},
update: (
state,
action: PayloadAction<{id: string; changes: Partial<LakeAttrs>}>
) => {
const {id, changes} = action.payload
state[id] = {...state[id], ...changes}
},
setAccessToken: (
state,
action: PayloadAction<{lakeId: string; accessToken: string}>
Expand Down
3 changes: 3 additions & 0 deletions apps/zui/src/js/state/Lakes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export type LakeAttrs = {
version?: string
authType: AuthType
authData?: AuthData
features?: {
describe: boolean
}
}

export type AuthType = "none" | "auth0"
Expand Down
2 changes: 1 addition & 1 deletion apps/zui/src/js/state/Layout/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createSelector} from "@reduxjs/toolkit"
import activeTabSelect from "../Tab/activeTabSelect"
import {RESULTS_QUERY} from "src/views/results-pane/run-results-query"
import {RESULTS_QUERY} from "src/views/results-pane/config"
import {getShapes} from "../Results/selectors"

const getResultsView = activeTabSelect((s) => s.layout.resultsView)
Expand Down
3 changes: 3 additions & 0 deletions apps/zui/src/js/state/QueryInfo/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const slice = createSlice({
set(_, action) {
return action.payload
},
merge(state, action) {
return {...state, ...action.payload}
},
reset(_) {
return getInitialState()
},
Expand Down
2 changes: 1 addition & 1 deletion apps/zui/src/js/state/Table/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as zed from "@brimdata/zed-js"
import {TableSettingsState} from "./types"
import {ColumnSizingInfoState} from "@tanstack/react-table"
import {actions as results} from "../Results/reducer"
import {RESULTS_QUERY} from "src/views/results-pane/run-results-query"
import {RESULTS_QUERY} from "src/views/results-pane/config"

const table = createSlice({
name: "TAB_TABLE",
Expand Down
6 changes: 6 additions & 0 deletions apps/zui/src/models/active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {BrowserTab} from "./browser-tab"
import {Frame} from "./frame"
import {getActiveTab} from "src/js/state/Tabs/selectors"
import Editor from "src/js/state/Editor"
import {Lake} from "./lake"

export class Active extends DomainModel {
static get tab() {
Expand Down Expand Up @@ -36,4 +37,9 @@ export class Active extends DomainModel {
id: globalThis.windowId,
})
}

static get lake() {
const id = this.select(Current.getLakeId)
return Lake.find(id)
}
}
41 changes: 41 additions & 0 deletions apps/zui/src/models/lake.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import {DomainModel} from "src/core/domain-model"
import {LakeAttrs} from "../js/state/Lakes/types"
import {Client} from "@brimdata/zed-js"
import Slice from "src/js/state/Lakes"
import {FeatureDetector} from "./lake/feature-detector"

export class Lake extends DomainModel<LakeAttrs> {
static find(id: string) {
const attrs = this.select(Slice.id(id))
if (!attrs) return null
return new Lake(attrs)
}

getAddress(): string {
return this.attrs.port
? [this.attrs.host, this.attrs.port].join(":")
Expand Down Expand Up @@ -39,4 +48,36 @@ export class Lake extends DomainModel<LakeAttrs> {
get version() {
return this.attrs.version
}

get client() {
return new Client(this.getAddress())
}

get features() {
return this.attrs.features ?? ({} as any)
}

async sync() {
// Also authenticate (later)
// Also check status (later)
const detector = new FeatureDetector(this)
const features = await detector.detect()
this.update({features})
}

update(changes: Partial<LakeAttrs>) {
this.attrs = {...this.attrs, ...changes}
this.dispatch(Slice.update({id: this.id, changes}))
}

save() {
this.dispatch(Slice.add({...this.attrs}))
}

isRunning() {
return this.client
.version()
.then(() => true)
.catch(() => false)
}
}
21 changes: 21 additions & 0 deletions apps/zui/src/models/lake/feature-detector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {Lake} from "../lake"

export class FeatureDetector {
constructor(public lake: Lake) {}

async hasDescribe() {
try {
const resp = await this.lake.client.describeQuery("from :pools")
return !resp.error
} catch (e) {
if (/404/.test(e.message)) return false
else throw e
}
}

async detect() {
return {
describe: await this.hasDescribe(),
}
}
}
2 changes: 1 addition & 1 deletion apps/zui/src/plugins/brimcap/zeek/correlations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function activateZeekCorrelations() {
})

correlations.create(UID_CORRELATION, {
when: () => !!findUid(session.selectedRow),
when: () => !!session.poolName && !!findUid(session.selectedRow),
query: async () => {
const uid = findUid(session.selectedRow)
const pool = session.poolName
Expand Down
2 changes: 1 addition & 1 deletion apps/zui/src/views/export-modal/state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useState} from "react"
import {useSelector} from "react-redux"
import Results from "src/js/state/Results"
import {RESULTS_QUERY_COUNT} from "../results-pane/run-results-query"
import {RESULTS_QUERY_COUNT} from "../results-pane/config"

export function useExportModalState() {
const countStatus = useSelector(Results.getStatus(RESULTS_QUERY_COUNT))
Expand Down
2 changes: 2 additions & 0 deletions apps/zui/src/views/results-pane/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const RESULTS_QUERY = "zui-results/main"
export const RESULTS_QUERY_COUNT = "zui-results/main-count"
2 changes: 1 addition & 1 deletion apps/zui/src/views/results-pane/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {useNextPage} from "src/core/query/use-query"
import {useResults} from "src/core/query/use-results"
import Layout from "src/js/state/Layout"
import Results from "src/js/state/Results"
import {RESULTS_QUERY} from "src/views/results-pane/run-results-query"
import {RESULTS_QUERY} from "src/views/results-pane/config"
import {useDataTransition} from "src/util/hooks/use-data-transition"
import useResizeObserver from "use-resize-observer"
import QueryInfo from "src/js/state/QueryInfo"
Expand Down
Loading

0 comments on commit 10d8974

Please sign in to comment.