Skip to content

Commit 09fb0ee

Browse files
committed
Add support for dynamically querying multiple tenants in trace domain
Signed-off-by: Shweta Padubidri <spadubid@redhat.com>
1 parent 877f363 commit 09fb0ee

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

web/src/hooks/useTroubleshootingPanel.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@ import * as React from 'react';
44
import { useTranslation } from 'react-i18next';
55
import { useDispatch } from 'react-redux';
66
import { openTP } from '../redux-actions';
7+
import { replaceTraceStore } from '../korrel8r-client';
8+
import { extractTraceContext, buildTraceStoreConfig } from '../utils/traceStoreUtils';
79
import { useKorrel8r } from './useKorrel8r';
810

911
const useTroubleshootingPanel: ExtensionHook<Array<Action>> = () => {
1012
const { isKorrel8rReachable } = useKorrel8r();
1113
const { t } = useTranslation('plugin__troubleshooting-panel-console-plugin');
1214
const [perspective] = useActivePerspective();
1315
const dispatch = useDispatch();
14-
const open = React.useCallback(() => {
16+
const open = React.useCallback(async () => {
17+
// Check if we're on a traces page with tenant information
18+
const traceContext = extractTraceContext();
19+
20+
if (traceContext) {
21+
try {
22+
// Update korrel8r's trace store to match the selected tenant
23+
const storeConfig = buildTraceStoreConfig(traceContext);
24+
await replaceTraceStore(storeConfig);
25+
// eslint-disable-next-line no-console
26+
console.log('Trace store updated for tenant:', traceContext.tenant);
27+
} catch (error) {
28+
// Log error but don't block panel from opening
29+
// The panel will still work with other domains even if trace store update fails
30+
// eslint-disable-next-line no-console
31+
console.error('Failed to update trace store:', error);
32+
}
33+
}
34+
1535
dispatch(openTP());
1636
}, [dispatch]);
1737

web/src/korrel8r-client.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,26 @@ export const getGoalsGraph = (goals: Goals) => {
3535

3636
return korrel8rClient.default.postGraphsGoals(goals);
3737
};
38+
39+
export interface StoreConfig {
40+
domain: string;
41+
tempoStack?: string;
42+
certificateAuthority?: string;
43+
[key: string]: string | undefined;
44+
}
45+
46+
export const replaceTraceStore = async (storeConfig: StoreConfig): Promise<void> => {
47+
const response = await fetch(`${KORREL8R_ENDPOINT}/stores/trace`, {
48+
method: 'PUT',
49+
headers: {
50+
'Content-Type': 'application/json',
51+
'X-CSRFToken': getCSRFToken(),
52+
},
53+
body: JSON.stringify(storeConfig),
54+
});
55+
56+
if (!response.ok) {
57+
const errorText = await response.text();
58+
throw new Error(`Failed to replace trace store: ${response.status} ${errorText}`);
59+
}
60+
};

web/src/korrel8r/trace.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { Class, Constraint, Domain, Query, unixMilliseconds, URIRef } from './ty
66
// Search for get selected spans
77
// observe/traces/?namespace=<tempoNamespace>&name=<tempoName>&tenant=<tempoTenant>&q=<traceQL>
88

9-
// TODO hard-coded tempo location, need to make this configurable between console & korrel8r.
10-
// Get from the console page environment (change from using URL as context?)
9+
// NOTE: Default tempo location for generating links.
10+
// When the troubleshooting panel opens, it reads the actual tenant from the URL
11+
// and updates korrel8r's trace store configuration via PUT /stores/trace.
12+
// These defaults are used when generating links back to the console.
1113
const [tempoNamespace, tempoName, tempoTenant] = ['openshift-tracing', 'platform', 'platform'];
1214

1315
export class TraceDomain extends Domain {

0 commit comments

Comments
 (0)