Skip to content

Commit b1aaf26

Browse files
authored
Feature/Backward compatible group HTTP (#109)
* add missing space * support endpoint route schema support endpoint route schema - epHTTP: and epRPC: * rename * cosmetic
1 parent 72b62e4 commit b1aaf26

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

src/services/analyticsProvider.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ export enum ErrorFlowsSortBy
2424
NewOrTrending = "NewOrTrending",
2525
}
2626

27+
export enum EndpointType
28+
{
29+
HTTP,
30+
RPC,
31+
}
32+
33+
export class EndpointSchema {
34+
public static readonly HTTP: string = "epHTTP:";
35+
public static readonly RPC: string = "epRPC:";
36+
37+
// strips the scheme and returns the rest of the of name
38+
public static getShortRouteName(fullRouteName: string): string {
39+
if (fullRouteName.startsWith(EndpointSchema.HTTP)) {
40+
return fullRouteName.replace(EndpointSchema.HTTP, "");
41+
}
42+
if (fullRouteName.startsWith(EndpointSchema.RPC)) {
43+
return fullRouteName.replace(EndpointSchema.RPC, "");
44+
}
45+
// did not manage to find relevant Scheme, so returning value as is
46+
return fullRouteName;
47+
}
48+
49+
}
50+
2751
export interface ParamStats
2852
{
2953
paramName: string;

src/views/codeAnalytics/InsightListView/EndpointInsight.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IListViewItem, ListViewGroupItem } from "../../ListView/IListViewItem";
22
import { CodeObjectInfo } from "../codeAnalyticsView";
33
import { CodeObjectInsight, IInsightListViewItemsCreator } from "./IInsightListViewItemsCreator";
4+
import { EndpointType, EndpointSchema } from '../../../services/analyticsProvider';
45
import { WebviewChannel, WebViewUris } from "../../webViewUtils";
56
import { DecimalRounder } from "../../utils/valueFormatting";
67
import { EditorHelper } from "../../../services/EditorHelper";
@@ -10,8 +11,12 @@ import { Uri } from "vscode";
1011
import path = require("path");
1112
import moment = require("moment");
1213

13-
export interface LowUsageInsight extends CodeObjectInsight {
14+
15+
export interface EndpointInsight extends CodeObjectInsight {
1416
route: string;
17+
}
18+
19+
export interface LowUsageInsight extends EndpointInsight {
1520
maxCallsIn1Min: number;
1621
}
1722

@@ -73,8 +78,7 @@ export class LowUsageListViewItemsCreator implements IInsightListViewItemsCreato
7378

7479
}
7580

76-
export interface NormalUsageInsight extends CodeObjectInsight {
77-
route: string;
81+
export interface NormalUsageInsight extends EndpointInsight {
7882
maxCallsIn1Min: number;
7983
}
8084

@@ -108,8 +112,7 @@ export class NormalUsageListViewItemsCreator implements IInsightListViewItemsCre
108112

109113
}
110114

111-
export interface HighUsageInsight extends CodeObjectInsight {
112-
route: string;
115+
export interface HighUsageInsight extends EndpointInsight {
113116
maxCallsIn1Min: number;
114117
}
115118

@@ -120,8 +123,7 @@ export interface Duration {
120123
}
121124

122125

123-
export interface SlowEndpointInsight extends CodeObjectInsight {
124-
route: string;
126+
export interface SlowEndpointInsight extends EndpointInsight {
125127
endpointsMedian: Duration;
126128
endpointsMedianOfMedians: Duration;
127129
endpointsMedianOfP75: Duration;
@@ -182,9 +184,8 @@ export interface Percentile {
182184
fraction: number,
183185
maxDuration: Duration,
184186
}
185-
export interface SlowestSpansInsight extends CodeObjectInsight {
187+
export interface SlowestSpansInsight extends EndpointInsight {
186188
spans: SlowSpanInfo[];
187-
route: string;
188189
}
189190

190191
export class SlowestSpansListViewItemsCreator implements IInsightListViewItemsCreator {
@@ -357,21 +358,32 @@ export class SlowEndpointListViewItemsCreator implements IInsightListViewItemsCr
357358
}
358359

359360

360-
361+
export function adjustHttpRouteIfNeeded(endpointInsight: EndpointInsight): void {
362+
const origValue = endpointInsight.route;
363+
if (origValue.startsWith(EndpointSchema.HTTP)) {
364+
return;
365+
}
366+
if (origValue.startsWith(EndpointSchema.RPC)) {
367+
return;
368+
}
369+
// default behaviour, to be backword compatible, where did not have the scheme part of the route, so adding it as HTTP one
370+
endpointInsight.route = EndpointSchema.HTTP + origValue;
371+
}
361372

362373
export class HttpEndpointListViewGroupItem extends ListViewGroupItem {
363374
constructor(private route: string) {
364375
super(`HTTP ${route}`, 10);
365376
}
366377

367378
public getGroupHtml(itemsHtml: string): string {
368-
const parts = this.route.split(' ');
379+
const shortRouteName = EndpointSchema.getShortRouteName(this.route);
380+
const parts = shortRouteName.split(' ');
369381
return /*html*/ `
370382
<div class="group-item">
371383
<span class="scope">REST: </span>
372384
<span class="codicon codicon-symbol-interface" title="Endpoint"></span>
373385
<span class="uppercase">
374-
<strong>HTTP </strong>${parts[0]}</span>
386+
<strong>HTTP </strong>${parts[0]}&nbsp;</span>
375387
<span>${parts[1]}</span>
376388
</div>
377389

src/views/codeAnalytics/InsightListView/IInsightListViewItemsCreator.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { IListViewItemBase } from "../../ListView/IListViewItem";
22
import { CodeObjectInfo } from "../codeAnalyticsView";
3+
import { EndpointInsight, adjustHttpRouteIfNeeded } from "./EndpointInsight";
34

45
export interface CodeObjectInsight{
56
codeObjectId: string,
67
type: string
78
}
9+
810
export interface IInsightListViewItemsCreator
911
{
1012
create(scope: CodeObjectInfo, codeObjectInsight: CodeObjectInsight []): Promise<IListViewItemBase[]>;
@@ -23,7 +25,7 @@ export class InsightListViewItemsCreator implements IInsightListViewItemsCreator
2325
}
2426

2527
public async create(scope: CodeObjectInfo, codeObjectInsight: CodeObjectInsight[]): Promise<IListViewItemBase[]> {
26-
28+
this.adjustToHttpIfNeeded(codeObjectInsight);
2729
const groupedByType = codeObjectInsight.groupBy(x => x.type);
2830
const items: IListViewItemBase [] = [];
2931
for(let type in groupedByType)
@@ -40,4 +42,13 @@ export class InsightListViewItemsCreator implements IInsightListViewItemsCreator
4042
return items;
4143
}
4244

45+
protected adjustToHttpIfNeeded(codeObjectInsights: CodeObjectInsight[]) {
46+
codeObjectInsights.forEach(coi => {
47+
if (coi.hasOwnProperty("route")) {
48+
const endpointInsight = coi as EndpointInsight;
49+
adjustHttpRouteIfNeeded(endpointInsight);
50+
}
51+
});
52+
}
53+
4354
}

0 commit comments

Comments
 (0)