Skip to content

Commit 9448f25

Browse files
Implement Duration Breakdown insight
1 parent 301c535 commit 9448f25

File tree

13 files changed

+259
-54
lines changed

13 files changed

+259
-54
lines changed

ide-common/src/main/java/org/digma/intellij/plugin/insights/view/BuildersHolder.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
package org.digma.intellij.plugin.insights.view;
22

33
import org.digma.intellij.plugin.model.InsightType;
4-
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
5-
import org.digma.intellij.plugin.model.rest.insights.ErrorInsight;
6-
import org.digma.intellij.plugin.model.rest.insights.HighUsageInsight;
7-
import org.digma.intellij.plugin.model.rest.insights.HotspotInsight;
8-
import org.digma.intellij.plugin.model.rest.insights.LowUsageInsight;
9-
import org.digma.intellij.plugin.model.rest.insights.NormalUsageInsight;
10-
import org.digma.intellij.plugin.model.rest.insights.SlowEndpointInsight;
11-
import org.digma.intellij.plugin.model.rest.insights.SlowestSpansInsight;
12-
import org.digma.intellij.plugin.model.rest.insights.SpanDurationsInsight;
13-
import org.digma.intellij.plugin.model.rest.insights.SpanSlowEndpointsInsight;
14-
import org.digma.intellij.plugin.model.rest.insights.SpanUsagesInsight;
15-
import org.digma.intellij.plugin.model.rest.insights.UnmappedInsight;
4+
import org.digma.intellij.plugin.model.rest.insights.*;
165
import org.digma.intellij.plugin.ui.model.insights.InsightGroupType;
176
import org.digma.intellij.plugin.view.EmptyListViewItemBuilder;
187
import org.digma.intellij.plugin.view.ListViewItemBuilder;
@@ -50,6 +39,8 @@ private ListViewItemBuilder<? extends CodeObjectInsight> newBuilder(InsightType
5039
return new GroupListViewItemBuilder<SpanUsagesInsight>(InsightGroupType.Span, SpanUsagesInsight::getSpan);
5140
case SpanDurations:
5241
return new GroupListViewItemBuilder<SpanDurationsInsight>(InsightGroupType.Span, spanDurationsInsight -> spanDurationsInsight.getSpan().getName());
42+
case SpanDurationBreakdown:
43+
return new GroupListViewItemBuilder<SpanDurationBreakdownInsight>(InsightGroupType.Span, SpanDurationBreakdownInsight::getSpanName);
5344
case SpanEndpointBottleneck:
5445
return new GroupListViewItemBuilder<SpanSlowEndpointsInsight>(InsightGroupType.Span, insight -> insight.getSpan().getName());
5546
case SlowestSpans:

ide-common/src/main/java/org/digma/intellij/plugin/insights/view/GroupListViewItemBuilder.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.digma.intellij.plugin.insights.view;
22

33
import com.intellij.openapi.project.Project;
4-
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
5-
import org.digma.intellij.plugin.model.rest.insights.SlowSpanInfo;
6-
import org.digma.intellij.plugin.model.rest.insights.SlowestSpansInsight;
7-
import org.digma.intellij.plugin.model.rest.insights.SpanInfo;
4+
import org.digma.intellij.plugin.document.CodeObjectsUtil;
5+
import org.digma.intellij.plugin.model.rest.insights.*;
86
import org.digma.intellij.plugin.ui.model.insights.InsightGroupListViewItem;
97
import org.digma.intellij.plugin.ui.model.insights.InsightGroupType;
108
import org.digma.intellij.plugin.ui.model.insights.InsightListViewItem;
@@ -37,8 +35,11 @@ public List<ListViewItem<?>> build(Project project, T insight, ListGroupManager
3735

3836
switch (insight.getType()){
3937
case SlowestSpans:{
40-
List<SpanInfo> spanInfos = ((SlowestSpansInsight) insight).getSpans().stream().map(SlowSpanInfo::getSpanInfo).collect(Collectors.toList());
41-
SlowestSpansHelper.findWorkspaceUrisForSpans(project, theListView, spanInfos, insight.getCodeObjectId());
38+
WorkspaceUrisHelper.findWorkspaceUrisForSpans(project, theListView, getSpanIds((SlowestSpansInsight) insight), insight.getCodeObjectId());
39+
break;
40+
}
41+
case SpanDurationBreakdown:{
42+
WorkspaceUrisHelper.findWorkspaceUrisForSpans(project,theListView, getSpanIds((SpanDurationBreakdownInsight) insight), insight.getCodeObjectId());
4243
break;
4344
}
4445
}
@@ -48,7 +49,17 @@ public List<ListViewItem<?>> build(Project project, T insight, ListGroupManager
4849
return List.of();
4950
}
5051

52+
private List<String> getSpanIds(SlowestSpansInsight insight) {
53+
return insight.getSpans().stream()
54+
.map(it -> CodeObjectsUtil.createSpanId(it.getSpanInfo().getInstrumentationLibrary(), it.getSpanInfo().getName()))
55+
.collect(Collectors.toList());
56+
}
5157

52-
58+
private List<String> getSpanIds(SpanDurationBreakdownInsight insight) {
59+
return insight.getBreakdownEntries()
60+
.stream().map(durationBreakdown ->
61+
CodeObjectsUtil.createSpanId(durationBreakdown.getSpanInstrumentationLibrary(), durationBreakdown.getSpanName()))
62+
.collect(Collectors.toList());
63+
}
5364

5465
}

ide-common/src/main/java/org/digma/intellij/plugin/insights/view/SlowestSpansHelper.java renamed to ide-common/src/main/java/org/digma/intellij/plugin/insights/view/WorkspaceUrisHelper.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
package org.digma.intellij.plugin.insights.view;
22

33
import com.intellij.openapi.project.Project;
4-
import org.digma.intellij.plugin.document.CodeObjectsUtil;
5-
import org.digma.intellij.plugin.model.rest.insights.SpanInfo;
64
import org.digma.intellij.plugin.psi.LanguageService;
75
import org.digma.intellij.plugin.ui.model.listview.ListViewItem;
86
import org.jetbrains.annotations.NotNull;
97
import org.jetbrains.annotations.Nullable;
108

11-
import java.util.ArrayList;
129
import java.util.List;
1310

14-
public class SlowestSpansHelper {
11+
public class WorkspaceUrisHelper {
1512

16-
private SlowestSpansHelper() {
13+
private WorkspaceUrisHelper() {
1714
}
1815

19-
public static void findWorkspaceUrisForSpans(Project project, ListViewItem<?> theListView, @NotNull List<SpanInfo> spanInfos, @Nullable String methodCodeObjectId) {
20-
21-
var spanIds = new ArrayList<String>();
22-
23-
spanInfos.forEach(spanInfo -> {
24-
var spanId = CodeObjectsUtil.createSpanId(spanInfo.getInstrumentationLibrary(), spanInfo.getName());
25-
spanIds.add(spanId);
26-
});
27-
16+
public static void findWorkspaceUrisForSpans(Project project, ListViewItem<?> theListView, @NotNull List<String> spanIds, @Nullable String methodCodeObjectId) {
2817
//when this method is called there is not always a related file.
2918
//if called while building SlowestSpansInsight then there is a method id and the related file is probably opened
3019
//and DocumentInfoService should find the method info and by that the language.

ide-common/src/main/java/org/digma/intellij/plugin/summary/SummariesProvider.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import com.intellij.openapi.project.Project;
55
import org.digma.intellij.plugin.analytics.AnalyticsService;
66
import org.digma.intellij.plugin.analytics.AnalyticsServiceException;
7+
import org.digma.intellij.plugin.document.CodeObjectsUtil;
78
import org.digma.intellij.plugin.log.Log;
89
import org.digma.intellij.plugin.model.rest.insights.GlobalInsight;
910
import org.digma.intellij.plugin.model.rest.insights.SpanDurationChangeInsight;
10-
import org.digma.intellij.plugin.model.rest.insights.SpanInfo;
1111
import org.digma.intellij.plugin.model.rest.usage.EnvironmentUsageStatus;
1212
import org.digma.intellij.plugin.model.rest.usage.UsageStatusResult;
1313
import org.digma.intellij.plugin.ui.model.listview.ListViewItem;
@@ -17,7 +17,7 @@
1717
import java.util.List;
1818
import java.util.stream.Collectors;
1919

20-
import static org.digma.intellij.plugin.insights.view.SlowestSpansHelper.findWorkspaceUrisForSpans;
20+
import static org.digma.intellij.plugin.insights.view.WorkspaceUrisHelper.findWorkspaceUrisForSpans;
2121

2222
public class SummariesProvider {
2323

@@ -71,8 +71,7 @@ private List<ListViewItem<GlobalInsight>> toListViewItems(List<GlobalInsight> in
7171
@SuppressWarnings("OptionalGetWithoutIsPresent")//no need ,it only happens if getSpanDurationChanges is not empty
7272
SpanDurationChangeInsight.Change change = ((SpanDurationChangeInsight) insight).getSpanDurationChanges().stream().findAny().get();
7373
var methodId = change.getCodeObjectId();
74-
List<SpanInfo> spanInfos = ((SpanDurationChangeInsight) insight).getSpanDurationChanges().stream().map(SpanDurationChangeInsight.Change::getSpan).collect(Collectors.toList());
75-
findWorkspaceUrisForSpans(project, item, spanInfos, methodId);
74+
findWorkspaceUrisForSpans(project, item, getSpanIds((SpanDurationChangeInsight) insight), methodId);
7675
}
7776
}
7877

@@ -81,4 +80,11 @@ private List<ListViewItem<GlobalInsight>> toListViewItems(List<GlobalInsight> in
8180

8281
return items;
8382
}
83+
84+
private List<String> getSpanIds(SpanDurationChangeInsight insight) {
85+
return insight.getSpanDurationChanges().stream()
86+
.map(it -> CodeObjectsUtil.createSpanId(it.getSpan().getInstrumentationLibrary(), it.getSpan().getName()))
87+
.collect(Collectors.toList());
88+
}
89+
8490
}

model/src/main/kotlin/org/digma/intellij/plugin/model/model.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ enum class InsightType {
3131
TopErrorFlows,
3232
SpanDurationChange,
3333
SpanEndpointBottleneck,
34+
SpanDurationBreakdown,
3435
;
3536
}

model/src/main/kotlin/org/digma/intellij/plugin/model/rest/insights/CodeObjectInsight.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.digma.intellij.plugin.model.InsightType
2525
JsonSubTypes.Type(value = SlowEndpointInsight::class, name = "SlowEndpoint"),
2626
JsonSubTypes.Type(value = SpanDurationsInsight::class, name = "SpanDurations"),
2727
JsonSubTypes.Type(value = SpanSlowEndpointsInsight::class, name = "SpanEndpointBottleneck"),
28+
JsonSubTypes.Type(value = SpanDurationBreakdownInsight::class, name = "SpanDurationBreakdown"),
2829
)
2930
interface CodeObjectInsight {
3031
val type: InsightType
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.digma.intellij.plugin.model.rest.insights
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
5+
import java.beans.ConstructorProperties
6+
7+
@JsonIgnoreProperties(ignoreUnknown = true)
8+
data class SpanDurationBreakdown
9+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
10+
@ConstructorProperties("spanName", "spanDisplayName", "spanInstrumentationLibrary", "spanCodeObjectId", "percentiles")
11+
constructor(
12+
val spanName: String,
13+
val spanDisplayName: String,
14+
val spanInstrumentationLibrary: String,
15+
val spanCodeObjectId: String,
16+
val percentiles: List<SpanDurationBreakdownPercentile>
17+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.digma.intellij.plugin.model.rest.insights
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import org.digma.intellij.plugin.model.InsightType
5+
import java.beans.ConstructorProperties
6+
7+
data class SpanDurationBreakdownInsight
8+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
9+
@ConstructorProperties("codeObjectId", "spanName", "breakdownEntries")
10+
constructor(
11+
override val codeObjectId: String,
12+
val spanName: String,
13+
val breakdownEntries: List<SpanDurationBreakdown>
14+
) : CodeObjectInsight {
15+
16+
override val type: InsightType = InsightType.SpanDurationBreakdown
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.digma.intellij.plugin.model.rest.insights
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
5+
import java.beans.ConstructorProperties
6+
7+
@JsonIgnoreProperties(ignoreUnknown = true)
8+
data class SpanDurationBreakdownPercentile
9+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
10+
@ConstructorProperties("percentile", "duration")
11+
constructor(
12+
val percentile: Float,
13+
val duration: Duration,
14+
)

model/src/main/kotlin/org/digma/intellij/plugin/ui/model/insights/InsightListViewItem.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ open class InsightListViewItem<INSIGHT : CodeObjectInsight>(insight: INSIGHT) :
1919
InsightType.SpanDurations -> 65
2020
InsightType.SpanDurationChange -> 66
2121
InsightType.SpanEndpointBottleneck -> 67
22+
InsightType.SpanDurationBreakdown -> 68
2223
// HTTP Endpoints
2324
InsightType.SlowestSpans -> 40
2425
InsightType.LowUsage -> 30

0 commit comments

Comments
 (0)