Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public Pair<String, Server> selectForSql(SqlQuery sqlQuery)
}
}

// Use defaut if not resolved by strategies
// Use default if not resolved by strategies
if (brokerServiceName == null) {
brokerServiceName = tierConfig.getDefaultBrokerServiceName();

Expand Down
10 changes: 9 additions & 1 deletion web-console/src/entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type { QueryContext } from './druid-models';
import type { Links } from './links';
import { setLinkOverrides } from './links';
import { Api, UrlBaser } from './singletons';
import { initMouseTooltip, setLocalStorageNamespace } from './utils';
import { initMouseTooltip, setConsoleBrokerService, setLocalStorageNamespace } from './utils';

import './entry.scss';

Expand Down Expand Up @@ -70,6 +70,10 @@ interface ConsoleConfig {

// Allow for namespacing the local storage in case multiple clusters share a URL due to proxying
localStorageNamespace?: string;

// Broker service name to use for all console SQL queries (for tier isolation)
// This injects "brokerService" into the query context for routing via the manual strategy
consoleBrokerService?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about exposing this config via web-console-config.tsx as well? It has this dialog on the console, which seems cool:

Image

I think web-console-config.tsx is session-based that stores config overrides in the browser, while the ConsoleConfig from console-config.js is persistent via the build. Not super familiar with the web-console code here, so correct me if I'm missing something here.

Can console-config.js be overridden per environment, given that this file is baked into the build as part of the source code?

}

const consoleConfig: ConsoleConfig = (window as any).consoleConfig;
Expand Down Expand Up @@ -101,6 +105,10 @@ if (consoleConfig.localStorageNamespace) {
setLocalStorageNamespace(consoleConfig.localStorageNamespace);
}

if (consoleConfig.consoleBrokerService) {
setConsoleBrokerService(consoleConfig.consoleBrokerService);
}

QueryRunner.defaultQueryExecutor = ({ payload, isSql, signal }) => {
return Api.instance.post(`/druid/v2${isSql ? '/sql' : ''}`, payload, { signal });
};
Expand Down
37 changes: 35 additions & 2 deletions web-console/src/utils/druid-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,35 @@ export class DruidError extends Error {
}
}

// Broker service to use for all console queries (for tier isolation)
let consoleBrokerService: string | undefined;

export function setConsoleBrokerService(brokerService: string | undefined): void {
consoleBrokerService = brokerService;
}

export function getConsoleBrokerService(): string | undefined {
return consoleBrokerService;
}
Comment on lines +332 to +334
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?


export async function queryDruidRune(
runeQuery: Record<string, any>,
signal?: AbortSignal,
): Promise<any> {
let runeResultResp: AxiosResponse;
try {
runeResultResp = await Api.instance.post('/druid/v2', runeQuery, { signal });
// Inject brokerService into context if configured
const query = consoleBrokerService
? {
...runeQuery,
context: {
...runeQuery.context,
brokerService: consoleBrokerService,
},
}
: runeQuery;

runeResultResp = await Api.instance.post('/druid/v2', query, { signal });
} catch (e) {
throw new Error(getDruidErrorMessage(e));
}
Expand All @@ -341,7 +363,18 @@ export async function queryDruidSql<T = any>(
): Promise<T[]> {
let sqlResultResp: AxiosResponse;
try {
sqlResultResp = await Api.instance.post('/druid/v2/sql', sqlQueryPayload, { signal });
// Inject brokerService into context if configured
const payload = consoleBrokerService
? {
...sqlQueryPayload,
context: {
...sqlQueryPayload.context,
brokerService: consoleBrokerService,
},
}
: sqlQueryPayload;

sqlResultResp = await Api.instance.post('/druid/v2/sql', payload, { signal });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that https://github.com/apache/druid/blob/master/web-console/src/views/explore-view/explore-view.tsx#L64
directly calls the /druid/v2/sql endpoint without invoking queryDruidSql. Should we update it to use this function instead, so the context is appended for the Explore view as well?

} catch (e) {
throw new Error(getDruidErrorMessage(e));
}
Expand Down
Loading