Skip to content

Commit 19cad40

Browse files
committed
Feature/Add SpanInfo to SpanInsights - as in backend (#403)
1 parent 514bd59 commit 19cad40

File tree

20 files changed

+207
-94
lines changed

20 files changed

+207
-94
lines changed

analytics-provider/src/test/java/org/digma/intellij/plugin/analytics/InsightsTests.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,24 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
55
import okhttp3.mockwebserver.MockResponse;
6-
import org.digma.intellij.plugin.model.rest.insights.*;
6+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
7+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsightsStatusResponse;
8+
import org.digma.intellij.plugin.model.rest.insights.Duration;
9+
import org.digma.intellij.plugin.model.rest.insights.ErrorInsight;
10+
import org.digma.intellij.plugin.model.rest.insights.ErrorInsightNamedError;
11+
import org.digma.intellij.plugin.model.rest.insights.HighUsageInsight;
12+
import org.digma.intellij.plugin.model.rest.insights.HotspotInsight;
13+
import org.digma.intellij.plugin.model.rest.insights.InsightOfMethodsRequest;
14+
import org.digma.intellij.plugin.model.rest.insights.InsightsRequest;
15+
import org.digma.intellij.plugin.model.rest.insights.LowUsageInsight;
16+
import org.digma.intellij.plugin.model.rest.insights.MethodWithCodeObjects;
17+
import org.digma.intellij.plugin.model.rest.insights.NormalUsageInsight;
18+
import org.digma.intellij.plugin.model.rest.insights.Percentile;
19+
import org.digma.intellij.plugin.model.rest.insights.SlowEndpointInsight;
20+
import org.digma.intellij.plugin.model.rest.insights.SlowSpanInfo;
21+
import org.digma.intellij.plugin.model.rest.insights.SlowestSpansInsight;
22+
import org.digma.intellij.plugin.model.rest.insights.SpanHistogramQuery;
23+
import org.digma.intellij.plugin.model.rest.insights.SpanInfo;
724
import org.junit.jupiter.api.Test;
825

926
import java.time.temporal.ChronoUnit;
@@ -61,7 +78,7 @@ public void actualgetHtmlGraphForSpanPercentiles() {
6178
System.out.println("htmlBody:" + htmlBody);
6279
}
6380

64-
// @Test
81+
// @Test
6582
public void actualGetCodeObjectInsightStatus() {
6683
final InsightOfMethodsRequest request = new InsightOfMethodsRequest(
6784
"ARIKS-MACBOOK-PRO.LOCAL[LOCAL]",
@@ -81,6 +98,7 @@ public void actualGetCodeObjectInsightStatus() {
8198
void getInsights() throws JsonProcessingException {
8299

83100
final String ROUTE = "post transfer/transferfunds";
101+
final String SERVICE = "MyService";
84102
final String ENDPOINT_SPAN = "HTTP POST transfer/transferfunds";
85103
final String ENV_1 = "Env1";
86104
final String SCOPE_1 = "Scope1";
@@ -105,29 +123,37 @@ void getInsights() throws JsonProcessingException {
105123

106124
String expectedNormalUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
107125
NormalUsageInsight expectedNormalUsageInsight = new NormalUsageInsight(expectedNormalUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
108-
ROUTE, ENDPOINT_SPAN, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedNormalUsageInsightCodeObjectId), null, 40);
126+
actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedNormalUsageInsightCodeObjectId), null,
127+
createSpanInfo(ENDPOINT_SPAN, expectedNormalUsageInsightCodeObjectId), ROUTE, SERVICE,
128+
40);
109129
expectedCodeObjectInsights.add(expectedNormalUsageInsight);
110130

111131
String expectedLowUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$Abc";
112132
LowUsageInsight expectedLowUsageInsight = new LowUsageInsight(expectedLowUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
113-
ROUTE, ENDPOINT_SPAN, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedLowUsageInsightCodeObjectId), null, 13);
133+
actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedLowUsageInsightCodeObjectId), null,
134+
createSpanInfo(ENDPOINT_SPAN, expectedLowUsageInsightCodeObjectId), ROUTE, SERVICE,
135+
13);
114136
expectedCodeObjectInsights.add(expectedLowUsageInsight);
115137

116138
String expectedHighUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$Defg";
117139
HighUsageInsight expectedHighUsageInsight = new HighUsageInsight(expectedHighUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
118-
ROUTE, ENDPOINT_SPAN, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedHighUsageInsightCodeObjectId), null, 98);
140+
actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedHighUsageInsightCodeObjectId), null,
141+
createSpanInfo(ENDPOINT_SPAN, expectedHighUsageInsightCodeObjectId), ROUTE, SERVICE,
142+
98);
119143
expectedCodeObjectInsights.add(expectedHighUsageInsight);
120144

121-
SpanInfo spanInfo = new SpanInfo("Retrieving account", "Retrieving account", "MoneyTransferDomainService", "Sample.MoneyTransfer.API", "Sample.MoneyTransfer.API.MoneyTransferDomainService$_$Error");
122-
SlowSpanInfo slowSpanInfo = new SlowSpanInfo(spanInfo,
145+
SlowSpanInfo slowSpanInfo = new SlowSpanInfo(
146+
createSpanInfo("SomeSpan", "Sample.MoneyTransfer.API.MoneyTransferDomainService$_$Error"),
123147
new Percentile(0.10970134022722634D, new Duration(3.44D, "ms", 3441700L)),
124148
new Percentile(0.2566821090980162D, new Duration(3.44D, "ms", 3441700L)),
125149
new Percentile(0.4407383382867023D, new Duration(5.64D, "ms", 5643900L)),
126150
null, null);
127151

128152
String expectedSlowestSpansInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
129153
SlowestSpansInsight expectedSlowestSpansInsight = new SlowestSpansInsight(expectedSlowestSpansInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
130-
ROUTE, ENDPOINT_SPAN, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedSlowestSpansInsightCodeObjectId), null, Collections.singletonList(slowSpanInfo));
154+
actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedSlowestSpansInsightCodeObjectId), null,
155+
createSpanInfo(ENDPOINT_SPAN, expectedSlowestSpansInsightCodeObjectId), ROUTE, SERVICE,
156+
Collections.singletonList(slowSpanInfo));
131157
expectedCodeObjectInsights.add(expectedSlowestSpansInsight);
132158

133159
String expectedSlowEndpointInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
@@ -137,12 +163,13 @@ void getInsights() throws JsonProcessingException {
137163
, SCOPE_1
138164
, IMPORTANCE_3
139165
, null
140-
, ROUTE
141-
, ENDPOINT_SPAN
142166
, actualStartTimeNow
143167
, customStartTimeFiveDaysBefore
144168
, addPrefixToCodeObjectId(expectedSlowEndpointInsightCodeObjectId)
145169
, null
170+
, createSpanInfo(ENDPOINT_SPAN, expectedSlowEndpointInsightCodeObjectId)
171+
, ROUTE
172+
, SERVICE
146173
, new Duration(0.11D, "ms", 11000)
147174
, new Duration(0.12D, "ms", 12000)
148175
, new Duration(0.13D, "ms", 13000)
@@ -197,6 +224,11 @@ void getInsights() throws JsonProcessingException {
197224

198225
}
199226

227+
private SpanInfo createSpanInfo(String spanName, String methodCodeObjectId) {
228+
String instLib = "il";
229+
return new SpanInfo(instLib, spanName, "span:$instLib$_$" + spanName, "disp_" + spanName,
230+
methodCodeObjectId, "Internal");
231+
}
200232

201233
@Test
202234
void getInsightsEmptyResultTest() throws JsonProcessingException {

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
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.*;
4+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
5+
import org.digma.intellij.plugin.model.rest.insights.EPNPlusSpansInsight;
6+
import org.digma.intellij.plugin.model.rest.insights.ErrorInsight;
7+
import org.digma.intellij.plugin.model.rest.insights.HighUsageInsight;
8+
import org.digma.intellij.plugin.model.rest.insights.HotspotInsight;
9+
import org.digma.intellij.plugin.model.rest.insights.LowUsageInsight;
10+
import org.digma.intellij.plugin.model.rest.insights.NormalUsageInsight;
11+
import org.digma.intellij.plugin.model.rest.insights.SlowEndpointInsight;
12+
import org.digma.intellij.plugin.model.rest.insights.SlowestSpansInsight;
13+
import org.digma.intellij.plugin.model.rest.insights.SpanDurationBreakdownInsight;
14+
import org.digma.intellij.plugin.model.rest.insights.SpanDurationsInsight;
15+
import org.digma.intellij.plugin.model.rest.insights.SpanNPlusOneInsight;
16+
import org.digma.intellij.plugin.model.rest.insights.SpanScalingInsight;
17+
import org.digma.intellij.plugin.model.rest.insights.SpanSlowEndpointsInsight;
18+
import org.digma.intellij.plugin.model.rest.insights.SpanUsagesInsight;
19+
import org.digma.intellij.plugin.model.rest.insights.UnmappedInsight;
520
import org.digma.intellij.plugin.ui.model.insights.InsightGroupType;
621
import org.digma.intellij.plugin.view.EmptyListViewItemBuilder;
722
import org.digma.intellij.plugin.view.ListViewItemBuilder;
@@ -36,29 +51,29 @@ private ListViewItemBuilder<? extends CodeObjectInsight> newBuilder(InsightType
3651
case Errors:
3752
return new NoGroupListViewItemBuilder<ErrorInsight>();
3853
case SpanUsages:
39-
return new GroupListViewItemBuilder<SpanUsagesInsight>(InsightGroupType.Span, null, SpanUsagesInsight::getSpan);
54+
return new GroupListViewItemBuilder<SpanUsagesInsight>(InsightGroupType.Span, null, SpanUsagesInsight::spanName);
4055
case SpanDurations:
41-
return new GroupListViewItemBuilder<SpanDurationsInsight>(InsightGroupType.Span, null, spanDurationsInsight -> spanDurationsInsight.getSpan().getName());
56+
return new GroupListViewItemBuilder<SpanDurationsInsight>(InsightGroupType.Span, null, spanDurationsInsight -> spanDurationsInsight.spanName());
4257
case SpanScaling:
43-
return new GroupListViewItemBuilder<SpanScalingInsight>(InsightGroupType.Span, null, SpanScalingInsight::getSpanName);
58+
return new GroupListViewItemBuilder<SpanScalingInsight>(InsightGroupType.Span, null, SpanScalingInsight::spanName);
4459
case SpanDurationBreakdown:
45-
return new GroupListViewItemBuilder<SpanDurationBreakdownInsight>(InsightGroupType.Span, null, SpanDurationBreakdownInsight::getSpanName);
60+
return new GroupListViewItemBuilder<SpanDurationBreakdownInsight>(InsightGroupType.Span, null, SpanDurationBreakdownInsight::spanName);
4661
case SpanEndpointBottleneck:
47-
return new GroupListViewItemBuilder<SpanSlowEndpointsInsight>(InsightGroupType.Span, null, insight -> insight.getSpan().getName());
62+
return new GroupListViewItemBuilder<SpanSlowEndpointsInsight>(InsightGroupType.Span, null, insight -> insight.spanName());
4863
case SpaNPlusOne:
49-
return new GroupListViewItemBuilder<SpanNPlusOneInsight>(InsightGroupType.Span, null, insight -> insight.getSpan().getName());
64+
return new GroupListViewItemBuilder<SpanNPlusOneInsight>(InsightGroupType.Span, null, insight -> insight.spanName());
5065
case SlowestSpans:
51-
return new GroupListViewItemBuilder<SlowestSpansInsight>(InsightGroupType.HttpEndpoint, SlowestSpansInsight::getRoute, SlowestSpansInsight::getEndpointSpan);
66+
return new GroupListViewItemBuilder<SlowestSpansInsight>(InsightGroupType.HttpEndpoint, SlowestSpansInsight::getRoute, SlowestSpansInsight::endpointSpanName);
5267
case LowUsage:
53-
return new GroupListViewItemBuilder<LowUsageInsight>(InsightGroupType.HttpEndpoint, LowUsageInsight::getRoute, LowUsageInsight::getEndpointSpan);
68+
return new GroupListViewItemBuilder<LowUsageInsight>(InsightGroupType.HttpEndpoint, LowUsageInsight::getRoute, LowUsageInsight::endpointSpanName);
5469
case NormalUsage:
55-
return new GroupListViewItemBuilder<NormalUsageInsight>(InsightGroupType.HttpEndpoint, NormalUsageInsight::getRoute, NormalUsageInsight::getEndpointSpan);
70+
return new GroupListViewItemBuilder<NormalUsageInsight>(InsightGroupType.HttpEndpoint, NormalUsageInsight::getRoute, NormalUsageInsight::endpointSpanName);
5671
case HighUsage:
57-
return new GroupListViewItemBuilder<HighUsageInsight>(InsightGroupType.HttpEndpoint, HighUsageInsight::getRoute, HighUsageInsight::getEndpointSpan);
72+
return new GroupListViewItemBuilder<HighUsageInsight>(InsightGroupType.HttpEndpoint, HighUsageInsight::getRoute, HighUsageInsight::endpointSpanName);
5873
case SlowEndpoint:
59-
return new GroupListViewItemBuilder<SlowEndpointInsight>(InsightGroupType.HttpEndpoint, SlowEndpointInsight::getRoute, SlowEndpointInsight::getEndpointSpan);
74+
return new GroupListViewItemBuilder<SlowEndpointInsight>(InsightGroupType.HttpEndpoint, SlowEndpointInsight::getRoute, SlowEndpointInsight::endpointSpanName);
6075
case EndpointSpaNPlusOne:
61-
return new GroupListViewItemBuilder<EPNPlusSpansInsight>(InsightGroupType.HttpEndpoint, EPNPlusSpansInsight::getRoute, EPNPlusSpansInsight::getEndpointSpan);
76+
return new GroupListViewItemBuilder<EPNPlusSpansInsight>(InsightGroupType.HttpEndpoint, EPNPlusSpansInsight::getRoute, EPNPlusSpansInsight::endpointSpanName);
6277
case Unmapped:
6378
return new NoGroupListViewItemBuilder<UnmappedInsight>();
6479
default:
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.digma.intellij.plugin.model.rest.insights
22

33
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
45
import org.digma.intellij.plugin.model.InsightType
56
import java.beans.ConstructorProperties
6-
import java.util.*
7+
import java.util.Date
78

9+
//TODO: rename to EndpointSuspectedNPlusOne
10+
@JsonIgnoreProperties(ignoreUnknown = true)
811
data class EPNPlusSpansInsight
912
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
1013
@ConstructorProperties(
@@ -13,12 +16,13 @@ data class EPNPlusSpansInsight
1316
"scope",
1417
"importance",
1518
"decorators",
16-
"route",
17-
"endpointSpan",
1819
"actualStartTime",
1920
"customStartTime",
2021
"prefixedCodeObjectId",
2122
"shortDisplayInfo",
23+
"spanInfo",
24+
"route",
25+
"serviceName",
2226
"spans"
2327
)
2428
constructor(
@@ -27,13 +31,14 @@ constructor(
2731
override val scope: String,
2832
override val importance: Int,
2933
override val decorators: List<CodeObjectDecorator>?,
30-
override var route: String,
31-
override var endpointSpan: String,
3234
override val actualStartTime: Date?,
3335
override val customStartTime: Date?,
3436
override val prefixedCodeObjectId: String?,
3537
override val shortDisplayInfo: ShortDisplayInfo?,
38+
override val spanInfo: SpanInfo,
39+
override var route: String,
40+
override var serviceName: String,
3641
val spans: List<HighlyOccurringSpanInfo>,
3742
) : EndpointInsight {
38-
override val type: InsightType = InsightType.EndpointSpaNPlusOne
43+
override val type: InsightType = InsightType.EndpointSpaNPlusOne
3944
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.digma.intellij.plugin.model.rest.insights
22

3-
interface EndpointInsight : CodeObjectInsight {
3+
interface EndpointInsight : SpanInsight {
44
var route: String
5-
var endpointSpan: String
5+
var serviceName: String
6+
7+
fun endpointSpanName(): String {
8+
return spanInfo.name
9+
}
610
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.digma.intellij.plugin.model.rest.insights
22

33
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
45
import org.digma.intellij.plugin.model.InsightType
56
import java.beans.ConstructorProperties
6-
import java.util.*
7+
import java.util.Date
78

9+
@JsonIgnoreProperties(ignoreUnknown = true)
810
data class HighUsageInsight
911
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
1012
@ConstructorProperties(
@@ -13,25 +15,27 @@ data class HighUsageInsight
1315
"scope",
1416
"importance",
1517
"decorators",
16-
"route",
17-
"endpointSpan",
1818
"actualStartTime",
1919
"customStartTime",
2020
"prefixedCodeObjectId",
2121
"shortDisplayInfo",
22+
"spanInfo",
23+
"route",
24+
"serviceName",
2225
"maxCallsIn1Min")
2326
constructor(
2427
override val codeObjectId: String,
2528
override val environment: String,
2629
override val scope: String,
2730
override val importance: Int,
2831
override val decorators: List<CodeObjectDecorator>?,
29-
override var route: String,
30-
override var endpointSpan: String,
3132
override val actualStartTime: Date?,
3233
override val customStartTime: Date?,
3334
override val prefixedCodeObjectId: String?,
3435
override val shortDisplayInfo: ShortDisplayInfo?,
36+
override val spanInfo: SpanInfo,
37+
override var route: String,
38+
override var serviceName: String,
3539
val maxCallsIn1Min: Int,
3640
) : EndpointInsight {
3741
override val type: InsightType = InsightType.HighUsage

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.digma.intellij.plugin.model.rest.insights
22

33
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
45
import org.digma.intellij.plugin.model.InsightType
56
import java.beans.ConstructorProperties
6-
import java.util.*
7+
import java.util.Date
78

9+
@JsonIgnoreProperties(ignoreUnknown = true)
810
data class LowUsageInsight
911
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
1012
@ConstructorProperties(
@@ -13,12 +15,13 @@ data class LowUsageInsight
1315
"scope",
1416
"importance",
1517
"decorators",
16-
"route",
17-
"endpointSpan",
1818
"actualStartTime",
1919
"customStartTime",
2020
"prefixedCodeObjectId",
2121
"shortDisplayInfo",
22+
"spanInfo",
23+
"route",
24+
"serviceName",
2225
"maxCallsIn1Min"
2326
)
2427
constructor(
@@ -27,12 +30,13 @@ constructor(
2730
override val scope: String,
2831
override val importance: Int,
2932
override val decorators: List<CodeObjectDecorator>?,
30-
override var route: String,
31-
override var endpointSpan: String,
3233
override val actualStartTime: Date?,
3334
override val customStartTime: Date?,
3435
override val prefixedCodeObjectId: String?,
3536
override val shortDisplayInfo: ShortDisplayInfo?,
37+
override val spanInfo: SpanInfo,
38+
override var route: String,
39+
override var serviceName: String,
3640
val maxCallsIn1Min: Int,
3741
) : EndpointInsight {
3842
override val type: InsightType = InsightType.LowUsage

0 commit comments

Comments
 (0)