Skip to content

Commit

Permalink
Stacktrace and Stackframes IDs not encoded in Kibana, use ES values (#6)
Browse files Browse the repository at this point in the history
* removed dead code
* remove b64 encoding function, retrieve IDs from ES
  • Loading branch information
inge4pres authored and rockdaboot committed Jun 8, 2022
1 parent f629a01 commit d883346
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 66 deletions.
56 changes: 0 additions & 56 deletions src/plugins/profiling/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,3 @@
* Side Public License, v 1.
*/
export { registerRoutes } from './register_routes';

export function getBase64Encoding(hex: string) {
const bin = [];
let i = 0;
let d;
let b;
while (i < hex.length) {
d = parseInt(hex.slice(i, i + 2), 16);
b = String.fromCharCode(d);
bin.push(b);
i += 2;
}
return btoa(bin.join('')).replace('+', '-').replace('/', '_');
}

export function getDocID(hi: bigint, lo: bigint) {
let hex = hi.toString(16);
const hexLo = lo.toString(16);
hex = '0'.repeat(16 - hex.length) + hex;
hex = hex + '0'.repeat(16 - hexLo.length) + hexLo;

const bin = [];
let i = 0;
let d;
let b;
while (i < hex.length) {
d = parseInt(hex.slice(i, i + 2), 16);
b = String.fromCharCode(d);
bin.push(b);
i += 2;
}

return btoa(bin.join('')).replace('+', '-').replace('/', '_');
}

export function getOtherDocID(hi: bigint, lo: bigint, other: bigint): string {
let hex = hi.toString(16);
const hexLo = lo.toString(16);
const hexOther = other.toString(16);
hex = '0'.repeat(16 - hex.length) + hex;
hex = hex + '0'.repeat(16 - hexLo.length) + hexLo;
hex = hex + '0'.repeat(16 - hexOther.length) + other;

const bin = [];
let i = 0;
let d;
let b;
while (i < hex.length) {
d = parseInt(hex.slice(i, i + 2), 24);
b = String.fromCharCode(d);
bin.push(b);
i += 2;
}

return btoa(bin.join('')).replace('+', '-').replace('/', '_');
}
7 changes: 2 additions & 5 deletions src/plugins/profiling/server/routes/search_flameChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { IEsSearchResponse } from '../../../data/common';
import type { DataRequestHandlerContext } from '../../../data/server';
import type { IRouter } from '../../../../core/server';
import { getRemoteRoutePaths } from '../../common';
import { getBase64Encoding } from './index';

export function registerFlameChartSearchRoute(router: IRouter<DataRequestHandlerContext>) {
const paths = getRemoteRoutePaths();
Expand Down Expand Up @@ -143,8 +142,7 @@ export function registerFlameChartSearchRoute(router: IRouter<DataRequestHandler
const tracesDocIDs: string[] = [];
resFlamegraphTraces.rawResponse.aggregations.sample.group_by.buckets.forEach(
(stackTraceItem: any) => {
const docID = getBase64Encoding(stackTraceItem.key);
tracesDocIDs.push(docID);
tracesDocIDs.push(stackTraceItem.key);
}
);

Expand All @@ -161,8 +159,7 @@ export function registerFlameChartSearchRoute(router: IRouter<DataRequestHandler
// profiling-events to profiling-stack-traces
if (trace._source) {
for (let i = 0; i < trace._source.Offset.length; i++) {
const docID = getBase64Encoding(trace._source.FileIDHash[i]);
stackFrameDocIDs.push(docID);
stackFrameDocIDs.push(trace._source.FrameID[i]);
}
}
});
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/profiling/server/routes/search_topN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { IEsSearchRequest } from '../../../data/server';
import { IEsSearchResponse } from '../../../data/common';
import type { DataRequestHandlerContext } from '../../../data/server';
import type { IRouter } from '../../../../core/server';
import { getBase64Encoding } from './index';

export function queryTopNCommon(
router: IRouter<DataRequestHandlerContext>,
Expand Down Expand Up @@ -100,9 +99,7 @@ export function queryTopNCommon(
const docIDs: string[] = [];
resTopNStackTraces.rawResponse.aggregations.histogram.buckets.forEach((timeInterval) => {
timeInterval.group_by.buckets.forEach((stackTraceItem: any) => {
const docID = getBase64Encoding(stackTraceItem.key);

docIDs.push(docID);
docIDs.push(stackTraceItem.key);
});
});

Expand Down Expand Up @@ -130,7 +127,7 @@ export function queryTopNCommon(
return response.customError({
statusCode: e.statusCode ?? 500,
body: {
message: e.message,
message: 'Profiling TopN request failed: ' + e.message + '; full error ' + e.toString(),
},
});
}
Expand Down

0 comments on commit d883346

Please sign in to comment.