11import { IListViewItem , IListViewItemBase , ListViewGroupItem } from "../../ListView/IListViewItem" ;
22import { CodeObjectInfo } from "../codeAnalyticsView" ;
3+ import { Duration } from "./EndpointInsight" ;
34import { CodeObjectInsight , IInsightListViewItemsCreator } from "./IInsightListViewItemsCreator" ;
45
5- export interface SpanInsight extends CodeObjectInsight
6+ export interface SpanUsagesInsight extends CodeObjectInsight
67{
78 span : string ,
89 flows :{
@@ -19,9 +20,9 @@ export interface SpanInsight extends CodeObjectInsight
1920 lastServiceSpan : string | undefined
2021 } [ ]
2122}
22- export class SpanListViewItemsCreator implements IInsightListViewItemsCreator
23+ export class SpanUsagesListViewItemsCreator implements IInsightListViewItemsCreator
2324{
24- public async create ( scope : CodeObjectInfo , codeObjectsInsight : SpanInsight [ ] ) : Promise < IListViewItemBase [ ] >
25+ public async create ( scope : CodeObjectInfo , codeObjectsInsight : SpanUsagesInsight [ ] ) : Promise < IListViewItemBase [ ] >
2526 {
2627 const groupedBySpan = codeObjectsInsight . groupBy ( o => o . span ) ;
2728 const listViewItems : IListViewItem [ ] = [ ] ;
@@ -36,7 +37,7 @@ export class SpanListViewItemsCreator implements IInsightListViewItemsCreator
3637 return listViewItems ;
3738 }
3839
39- public createListViewItem ( insight : SpanInsight ) : IListViewItem
40+ public createListViewItem ( insight : SpanUsagesInsight ) : IListViewItem
4041 {
4142 // <span class="codicon codicon-server-process" style="margin-right: 3px;"></span>
4243 const usages = insight . flows . map ( flow => {
@@ -94,6 +95,65 @@ export class SpanListViewItemsCreator implements IInsightListViewItemsCreator
9495 }
9596}
9697
98+ export interface SpanDurationsInsight extends CodeObjectInsight {
99+ span : string ,
100+ percentiles : {
101+ percentile : number ,
102+ change : number ,
103+ latestDuration : Duration
104+ } [ ]
105+ }
106+ export class SpanDurationsListViewItemsCreator implements IInsightListViewItemsCreator {
107+ public async create ( scope : CodeObjectInfo , codeObjectsInsight : SpanDurationsInsight [ ] ) : Promise < IListViewItemBase [ ] >
108+ {
109+ const groupedBySpan = codeObjectsInsight . groupBy ( o => o . span ) ;
110+ const listViewItems : IListViewItem [ ] = [ ] ;
111+ for ( let route in groupedBySpan )
112+ {
113+ const group = new SpanListViewGroupItem ( route ) ;
114+ group . sortIndex = 10 ;
115+ const items = groupedBySpan [ route ] . map ( o => this . createListViewItem ( o ) ) ;
116+ group . addItems ( ...items ) ;
117+ listViewItems . push ( group ) ;
118+ }
119+ return listViewItems ;
120+ }
121+
122+ public createListViewItem ( insight : SpanDurationsInsight ) : IListViewItem
123+ {
124+ const percentileHtmls = [ ]
125+ for ( const item of insight . percentiles ) {
126+ const changeHtml = Math . abs ( item . change * 100 ) . toFixed ( 0 ) ;
127+
128+ percentileHtmls . push ( /*html*/ `<span>P${ item . percentile } </span>` ) ;
129+ percentileHtmls . push ( /*html*/ `<span>${ item . latestDuration . value } ${ item . latestDuration . unit } </span>` ) ;
130+
131+ if ( item . change > 0.1 )
132+ percentileHtmls . push ( /*html*/ `<span class="bad-change">increased by ${ changeHtml } %</span>` ) ;
133+ else if ( item . change < - 0.1 )
134+ percentileHtmls . push ( /*html*/ `<span class="good-change">decreased by ${ changeHtml } %</span>` ) ;
135+ else
136+ percentileHtmls . push ( /*html*/ `<span></span>` ) ;
137+ }
138+
139+ const html = /*html*/ `
140+ <div class="list-item span-durations-insight">
141+ <div class="list-item-content-area">
142+ <div class="list-item-header"><strong>Duration</strong></div>
143+ <div class="percentiles-grid">
144+ ${ percentileHtmls . join ( '' ) }
145+ </div>
146+ </div>
147+ </div>` ;
148+
149+ return {
150+ getHtml : ( ) => html ,
151+ sortIndex : 0 ,
152+ groupId : undefined
153+ } ;
154+ }
155+ }
156+
97157export class SpanListViewGroupItem extends ListViewGroupItem
98158{
99159 constructor ( private span : string )
0 commit comments