-
Notifications
You must be signed in to change notification settings - Fork 58
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
Traces custom source - Bug Fixes #2298
Conversation
Signed-off-by: Adam Tackett <[email protected]>
Signed-off-by: Adam Tackett <[email protected]>
Signed-off-by: Adam Tackett <[email protected]>
Signed-off-by: Adam Tackett <[email protected]>
public/components/trace_analytics/components/common/plots/service_map.tsx
Show resolved
Hide resolved
@@ -62,6 +62,17 @@ export function DataSourcePicker(props: { | |||
); | |||
}; | |||
|
|||
const updateUrlWithMode = (key: TraceAnalyticsMode) => { | |||
const currentUrl = window.location.href.split('?')[0]; | |||
const queryParams = new URLSearchParams(window.location.search); |
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.
this will only get the standard search params, but not the search param we use with hash router. for example in playground https://playground.opensearch.org/app/observability-traces#/traces?datasourceId=44cc4c50-6f80-11ed-a8ec-958f39714b93
window.location.search
is ''
, and currentUrl
is 'https://playground.opensearch.org/app/observability-traces#/traces'
. The dataSourceId
information becomes lost?
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.
Updated too
const updateUrlWithMode = (key: TraceAnalyticsMode) => {
const currentUrl = window.location.href.split('#')[0];
const hash = window.location.hash;
if (hash) {
const [hashPath, hashQueryString] = hash.split('?');
const queryParams = new URLSearchParams(hashQueryString || '');
queryParams.set('mode', key);
const newHash = `${hashPath}?${queryParams.toString()}`;
const newUrl = `${currentUrl}#${newHash}`;
window.history.replaceState(null, '', newUrl);
} else {
//Non-hash-based URL
const queryParams = new URLSearchParams(window.location.search);
queryParams.set('mode', key);
const newUrl = `${currentUrl}?${queryParams.toString()}`;
window.history.replaceState(null, '', newUrl);
}
};
); | ||
const renderTraceLinkField = (item: string) => { | ||
// Extract the current mode from the URL or session storage | ||
const queryParams = new URLSearchParams(window.location.search); |
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.
does this work correctly with hash router?
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.
Updated too
const currentUrl = window.location.href;
const traceMode = new URLSearchParams(currentUrl.split('?')[1]).get('mode') || sessionStorage.getItem('TraceAnalyticsMode');
export const appendModeToTraceViewUri = (
traceId: string,
getTraceViewUri?: (traceId: string) => string,
traceMode?: string | null
): string => {
const baseUri = getTraceViewUri ? getTraceViewUri(traceId) : '';
const isHashRouter = baseUri.includes('#');
const separator = isHashRouter ? (baseUri.includes('?') ? '&' : '?') : (baseUri.includes('?') ? '&' : '?');
if (traceMode) {
return `${baseUri}${separator}mode=${encodeURIComponent(traceMode)}`;
}
return baseUri;
};
return `${baseUri}${separator}mode=${encodeURIComponent(traceMode)}`; | ||
} | ||
return baseUri; | ||
}; |
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.
this logic is being duplicated, can it be extracted? might also need unit tests
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.
Moved to public/components/trace_analytics/components/common/helper_functions.tsx
Added unit test
describe('getTimestampPrecision', () => {
it('returns "millis" for 13-digit timestamps', () => {
expect(getTimestampPrecision(1703599200000)).toEqual('millis');
});
it('returns "micros" for 16-digit timestamps', () => {
expect(getTimestampPrecision(1703599200000000)).toEqual('micros');
});
it('returns "nanos" for 19-digit timestamps', () => {
expect(getTimestampPrecision(1703599200000000000)).toEqual('nanos');
});
it('returns "millis" for invalid or missing timestamps', () => {
expect(getTimestampPrecision(undefined as unknown as number)).toEqual('millis');
expect(getTimestampPrecision(123)).toEqual('millis');
});
});
describe('appendModeToTraceViewUri', () => {
const mockGetTraceViewUri = (traceId: string) => `#/traces/${traceId}`;
it('appends mode to the URI when mode is provided', () => {
const result = appendModeToTraceViewUri('123', mockGetTraceViewUri, 'data_prepper');
expect(result).toEqual('#/traces/123?mode=data_prepper');
});
it('appends mode correctly for hash router URIs with existing query params', () => {
const result = appendModeToTraceViewUri('123', (id) => `#/traces/${id}?foo=bar`, 'jaeger');
expect(result).toEqual('#/traces/123?foo=bar&mode=jaeger');
});
it('does not append mode if not provided', () => {
const result = appendModeToTraceViewUri('123', mockGetTraceViewUri, null);
expect(result).toEqual('#/traces/123');
});
it('handles URIs without a hash router', () => {
const result = appendModeToTraceViewUri('123', (id) => `/traces/${id}`, 'custom_data_prepper');
expect(result).toEqual('/traces/123?mode=custom_data_prepper');
});
it('handles URIs without a hash router and existing query params', () => {
const result = appendModeToTraceViewUri('123', (id) => `/traces/${id}?foo=bar`, 'jaeger');
expect(result).toEqual('/traces/123?foo=bar&mode=jaeger');
});
});
// if (mode === 'jaeger' && !response?.aggregations?.service_type?.buckets) { | ||
// console.warn('No traces or aggregations found.'); | ||
// return []; | ||
// } |
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.
is this needed?
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.
Removed, became unnecessary after the url mode implementation.
const traceMode = queryParams.get('mode') || sessionStorage.getItem('TraceAnalyticsMode'); | ||
|
||
// Update the href to include the mode if available | ||
const updatedGetTraceViewUri = (traceId: string) => { |
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.
"update get trace view uri" is not very clear, maybe
const updatedGetTraceViewUri = (traceId: string) => { | |
const appendModeToTraceViewUri = (traceId: string) => { |
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.
Updated, thank you.
Signed-off-by: Adam Tackett <[email protected]>
Signed-off-by: Adam Tackett <[email protected]>
public/components/trace_analytics/components/common/helper_functions.tsx
Outdated
Show resolved
Hide resolved
Signed-off-by: Adam Tackett <[email protected]>
Signed-off-by: Adam Tackett <[email protected]>
Signed-off-by: Adam Tackett <[email protected]>
* fix custom traces filter bug, add default metric selection Signed-off-by: Adam Tackett <[email protected]> * helper function for start time, handle date and datenanos Signed-off-by: Adam Tackett <[email protected]> * add toast messages for all errors service-traces, add mode to url Signed-off-by: Adam Tackett <[email protected]> * fix url re-direction in non custom state Signed-off-by: Adam Tackett <[email protected]> * address comments, add testing Signed-off-by: Adam Tackett <[email protected]> * update url #, send mode to applications Signed-off-by: Adam Tackett <[email protected]> * update helper function Signed-off-by: Adam Tackett <[email protected]> * add validation to url mode Signed-off-by: Adam Tackett <[email protected]> * fix applications removing traces redirect Signed-off-by: Adam Tackett <[email protected]> --------- Signed-off-by: Adam Tackett <[email protected]> Co-authored-by: Adam Tackett <[email protected]> (cherry picked from commit a57c10e) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
* fix custom traces filter bug, add default metric selection * helper function for start time, handle date and datenanos * add toast messages for all errors service-traces, add mode to url * fix url re-direction in non custom state * address comments, add testing * update url #, send mode to applications * update helper function * add validation to url mode * fix applications removing traces redirect --------- (cherry picked from commit a57c10e) Signed-off-by: Adam Tackett <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Adam Tackett <[email protected]>
Description
Before: (Bug crashing page when a selected filter was clicked again)
Before.mov
After: (No longer crashes, now removes the filter when clicked again)
After.mov
Before: (When the custom traces sources used date for the start time mapping instead of date_nanos the times would all start at 0)
After: (Now the time conversion is determined by the length of the sort metric. This example uses the mapping of start time "date", the indexes themselves have some in mili seconds and some in nanos but because the mapping of "date" is used the nanosecond precision is lost.)
Toast message example (manually setting buckets to 1 to cause failure)
ToastMessage.mov
URL redirection working:
UrlTest.mov
Issues Resolved
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.