Skip to content

Commit 927a43c

Browse files
authored
Feature/build dynamic groups - including RPC (#122)
1 parent 909b738 commit 927a43c

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

src/views/codeAnalytics/InsightListView/EndpointInsight.ts

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class LowUsageListViewItemsCreator implements IInsightListViewItemsCreato
5858
const groupedByRoute = codeObjectsInsight.groupBy(o => o.route);
5959
const listViewItems: IListViewItem[] = [];
6060
for (let route in groupedByRoute) {
61-
const group = new HttpEndpointListViewGroupItem(route);
61+
const group = buildEndpointListViewGroupItem(route);
6262
group.sortIndex = 10;
6363
const items = groupedByRoute[route].map(o => this.createListViewItem(o));
6464
group.addItems(...items);
@@ -93,7 +93,7 @@ export class NormalUsageListViewItemsCreator implements IInsightListViewItemsCre
9393
const groupedByRoute = codeObjectsInsight.groupBy(o => o.route);
9494
const listViewItems: IListViewItem[] = [];
9595
for (let route in groupedByRoute) {
96-
const group = new HttpEndpointListViewGroupItem(route);
96+
const group = buildEndpointListViewGroupItem(route);
9797
group.sortIndex = 10;
9898
const items = groupedByRoute[route].map(o => this.createListViewItem(o));
9999
group.addItems(...items);
@@ -156,7 +156,7 @@ export class HighUsageListViewItemsCreator implements IInsightListViewItemsCreat
156156
const groupedByRoute = codeObjectsInsight.groupBy(o => o.route);
157157
const listViewItems: IListViewItem[] = [];
158158
for (let route in groupedByRoute) {
159-
const group = new HttpEndpointListViewGroupItem(route);
159+
const group = buildEndpointListViewGroupItem(route);
160160
group.sortIndex = 10;
161161
const items = groupedByRoute[route].map(o => this.createListViewItem(o));
162162
group.addItems(...items);
@@ -283,7 +283,7 @@ P99: ${(span.p99.fraction*100).toFixed(0)}% ~${span.p99.maxDuration.value}${s
283283
const groupedByRoute = codeObjectsInsight.groupBy(o => o.route);
284284
const listViewItems: IListViewItem[] = [];
285285
for (let route in groupedByRoute) {
286-
const group = new HttpEndpointListViewGroupItem(route);
286+
const group = buildEndpointListViewGroupItem(route);
287287
group.sortIndex = 10;
288288
const items = (await Promise.all(groupedByRoute[route].map(o => this.createListViewItem(o))));
289289
group.addItems(...items);
@@ -346,7 +346,7 @@ export class SlowEndpointListViewItemsCreator implements IInsightListViewItemsCr
346346
const groupedByRoute = codeObjectsInsight.groupBy(o => o.route);
347347
const listViewItems: IListViewItem[] = [];
348348
for (let route in groupedByRoute) {
349-
const group = new HttpEndpointListViewGroupItem(route);
349+
const group = buildEndpointListViewGroupItem(route);
350350
group.sortIndex = 10;
351351
const items = groupedByRoute[route].map(o => this.createListViewItem(o));
352352
group.addItems(...items);
@@ -370,6 +370,19 @@ export function adjustHttpRouteIfNeeded(endpointInsight: EndpointInsight): void
370370
endpointInsight.route = EndpointSchema.HTTP + origValue;
371371
}
372372

373+
function buildEndpointListViewGroupItem(fullEndpointName: string): ListViewGroupItem {
374+
375+
if (fullEndpointName.startsWith(EndpointSchema.HTTP)) {
376+
return new HttpEndpointListViewGroupItem(fullEndpointName);
377+
}
378+
if (fullEndpointName.startsWith(EndpointSchema.RPC)) {
379+
return new RpcEndpointListViewGroupItem(fullEndpointName);
380+
}
381+
382+
// fallback to UnknownEndpointListViewGroupItem
383+
return new UnknownEndpointListViewGroupItem(fullEndpointName);
384+
}
385+
373386
export class HttpEndpointListViewGroupItem extends ListViewGroupItem {
374387
constructor(private route: string) {
375388
super(`HTTP ${route}`, 10);
@@ -391,4 +404,45 @@ export class HttpEndpointListViewGroupItem extends ListViewGroupItem {
391404

392405
}
393406

394-
}
407+
}
408+
409+
export class RpcEndpointListViewGroupItem extends ListViewGroupItem {
410+
411+
private endpointName;
412+
413+
constructor(fullEndpointName: string) {
414+
super(fullEndpointName, 10);
415+
this.endpointName = EndpointSchema.getShortRouteName(fullEndpointName);
416+
}
417+
418+
public getGroupHtml(itemsHtml: string): string {
419+
return /*html*/ `
420+
<div class="group-item">
421+
<span class="scope">RPC: </span>
422+
<span class="codicon codicon-symbol-interface" title="Endpoint"></span>
423+
<span>${this.endpointName}</span>
424+
</div>
425+
426+
${itemsHtml}`;
427+
}
428+
429+
}
430+
431+
export class UnknownEndpointListViewGroupItem extends ListViewGroupItem {
432+
433+
constructor(fullEndpointName: string) {
434+
super(fullEndpointName, 10);
435+
}
436+
437+
public getGroupHtml(itemsHtml: string): string {
438+
return /*html*/ `
439+
<div class="group-item">
440+
<span class="scope">Unknown Endpoint: </span>
441+
<span class="codicon codicon-symbol-interface" title="Endpoint"></span>
442+
<span>${this.groupId}</span>
443+
</div>
444+
445+
${itemsHtml}`;
446+
}
447+
448+
}

0 commit comments

Comments
 (0)