Skip to content

Commit 2a865f4

Browse files
Used new field 'endpointSpan' for grouping logic (#123)
1 parent d112e61 commit 2a865f4

File tree

16 files changed

+52
-42
lines changed

16 files changed

+52
-42
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public void actualgetHtmlGraphForSpanPercentiles() {
6464
@Test
6565
void getInsights() throws JsonProcessingException {
6666

67+
final String ROUTE = "post transfer/transferfunds";
68+
final String ENDPOINT_SPAN = "HTTP POST transfer/transferfunds";
69+
6770
String codeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
6871
String prefixedCodeObjectId = addPrefixToCodeObjectId(codeObjectId);
6972
Date actualStartTimeNow = new Date();
@@ -83,17 +86,17 @@ void getInsights() throws JsonProcessingException {
8386

8487
String expectedNormalUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
8588
NormalUsageInsight expectedNormalUsageInsight = new NormalUsageInsight( expectedNormalUsageInsightCodeObjectId,
86-
"post transfer/transferfunds", actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedNormalUsageInsightCodeObjectId), 40);
89+
ROUTE, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedNormalUsageInsightCodeObjectId), ENDPOINT_SPAN, 40);
8790
expectedCodeObjectInsights.add(expectedNormalUsageInsight);
8891

8992
String expectedLowUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$Abc";
9093
LowUsageInsight expectedLowUsageInsight = new LowUsageInsight( expectedLowUsageInsightCodeObjectId,
91-
"post transfer/transferfunds", actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedLowUsageInsightCodeObjectId), 13);
94+
ROUTE, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedLowUsageInsightCodeObjectId), ENDPOINT_SPAN, 13);
9295
expectedCodeObjectInsights.add(expectedLowUsageInsight);
9396

9497
String expectedHighUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$Defg";
9598
HighUsageInsight expectedHighUsageInsight = new HighUsageInsight( expectedHighUsageInsightCodeObjectId,
96-
"post transfer/transferfunds", actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedHighUsageInsightCodeObjectId), 98);
99+
ROUTE, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedHighUsageInsightCodeObjectId), ENDPOINT_SPAN, 98);
97100
expectedCodeObjectInsights.add(expectedHighUsageInsight);
98101

99102
SpanInfo spanInfo = new SpanInfo("Retrieving account", "Retrieving account", "MoneyTransferDomainService", "Sample.MoneyTransfer.API","Sample.MoneyTransfer.API.MoneyTransferDomainService$_$Error");
@@ -105,16 +108,17 @@ void getInsights() throws JsonProcessingException {
105108

106109
String expectedSlowestSpansInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
107110
SlowestSpansInsight expectedSlowestSpansInsight = new SlowestSpansInsight( expectedSlowestSpansInsightCodeObjectId,
108-
"post transfer/transferfunds", actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedSlowestSpansInsightCodeObjectId), Collections.singletonList(slowSpanInfo));
111+
ROUTE, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedSlowestSpansInsightCodeObjectId), ENDPOINT_SPAN, Collections.singletonList(slowSpanInfo));
109112
expectedCodeObjectInsights.add(expectedSlowestSpansInsight);
110113

111114
String expectedSlowEndpointInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
112115
SlowEndpointInsight expectedSlowEndpointInsight = new SlowEndpointInsight(
113116
expectedSlowEndpointInsightCodeObjectId
114-
, "post transfer/transferfunds"
117+
, ROUTE
115118
, actualStartTimeNow
116119
, customStartTimeFiveDaysBefore
117120
, addPrefixToCodeObjectId(expectedSlowEndpointInsightCodeObjectId)
121+
, ENDPOINT_SPAN
118122
, new Duration(0.11D, "ms", 11000)
119123
, new Duration(0.12D, "ms", 12000)
120124
, new Duration(0.13D, "ms", 13000)

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ private ListViewItemBuilder<? extends CodeObjectInsight> newBuilder(InsightType
3636
case Errors:
3737
return new NoGroupListViewItemBuilder<ErrorInsight>();
3838
case SpanUsages:
39-
return new GroupListViewItemBuilder<SpanUsagesInsight>(InsightGroupType.Span, SpanUsagesInsight::getSpan);
39+
return new GroupListViewItemBuilder<SpanUsagesInsight>(InsightGroupType.Span, null, SpanUsagesInsight::getSpan);
4040
case SpanDurations:
41-
return new GroupListViewItemBuilder<SpanDurationsInsight>(InsightGroupType.Span, spanDurationsInsight -> spanDurationsInsight.getSpan().getName());
41+
return new GroupListViewItemBuilder<SpanDurationsInsight>(InsightGroupType.Span, null, spanDurationsInsight -> spanDurationsInsight.getSpan().getName());
4242
case SpanDurationBreakdown:
43-
return new GroupListViewItemBuilder<SpanDurationBreakdownInsight>(InsightGroupType.Span, SpanDurationBreakdownInsight::getSpanName);
43+
return new GroupListViewItemBuilder<SpanDurationBreakdownInsight>(InsightGroupType.Span, null, SpanDurationBreakdownInsight::getSpanName);
4444
case SpanEndpointBottleneck:
45-
return new GroupListViewItemBuilder<SpanSlowEndpointsInsight>(InsightGroupType.Span, insight -> insight.getSpan().getName());
45+
return new GroupListViewItemBuilder<SpanSlowEndpointsInsight>(InsightGroupType.Span, null, insight -> insight.getSpan().getName());
4646
case SlowestSpans:
47-
return new GroupListViewItemBuilder<SlowestSpansInsight>(InsightGroupType.HttpEndpoint, SlowestSpansInsight::getRoute);
47+
return new GroupListViewItemBuilder<SlowestSpansInsight>(InsightGroupType.HttpEndpoint, SlowestSpansInsight::getRoute, SlowestSpansInsight::getEndpointSpan);
4848
case LowUsage:
49-
return new GroupListViewItemBuilder<LowUsageInsight>(InsightGroupType.HttpEndpoint, LowUsageInsight::getRoute);
49+
return new GroupListViewItemBuilder<LowUsageInsight>(InsightGroupType.HttpEndpoint, LowUsageInsight::getRoute, LowUsageInsight::getEndpointSpan);
5050
case NormalUsage:
51-
return new GroupListViewItemBuilder<NormalUsageInsight>(InsightGroupType.HttpEndpoint, NormalUsageInsight::getRoute);
51+
return new GroupListViewItemBuilder<NormalUsageInsight>(InsightGroupType.HttpEndpoint, NormalUsageInsight::getRoute, NormalUsageInsight::getEndpointSpan);
5252
case HighUsage:
53-
return new GroupListViewItemBuilder<HighUsageInsight>(InsightGroupType.HttpEndpoint, HighUsageInsight::getRoute);
53+
return new GroupListViewItemBuilder<HighUsageInsight>(InsightGroupType.HttpEndpoint, HighUsageInsight::getRoute, HighUsageInsight::getEndpointSpan);
5454
case SlowEndpoint:
55-
return new GroupListViewItemBuilder<SlowEndpointInsight>(InsightGroupType.HttpEndpoint, SlowEndpointInsight::getRoute);
55+
return new GroupListViewItemBuilder<SlowEndpointInsight>(InsightGroupType.HttpEndpoint, SlowEndpointInsight::getRoute, SlowEndpointInsight::getEndpointSpan);
5656
case Unmapped:
5757
return new NoGroupListViewItemBuilder<UnmappedInsight>();
5858
default:

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717
public class GroupListViewItemBuilder<T extends CodeObjectInsight> implements ListViewItemBuilder<T> {
1818

1919
private final InsightGroupType insightGroupType;
20-
private final Function<T, String> groupByFunction;
20+
private final Function<T, String> routeFunction;
21+
private final Function<T, String> endpointSpan;
2122

22-
public GroupListViewItemBuilder(InsightGroupType insightGroupType, Function<T, String> groupByFunction) {
23+
public GroupListViewItemBuilder(InsightGroupType insightGroupType, Function<T, String> routeFunction, Function<T, String> endpointSpan) {
2324
this.insightGroupType = insightGroupType;
24-
this.groupByFunction = groupByFunction;
25+
this.routeFunction = routeFunction;
26+
this.endpointSpan = endpointSpan;
2527
}
2628

2729
@Override
2830
public List<ListViewItem<?>> build(Project project, T insight, ListGroupManager groupManager) {
29-
final String groupId = groupByFunction.apply(insight);
31+
final String route = routeFunction != null ? routeFunction.apply(insight) : "";
32+
final String groupId = endpointSpan.apply(insight);
3033
final InsightGroupListViewItem theGroup = (InsightGroupListViewItem)
31-
groupManager.getOrCreateGroup(groupId, () -> new InsightGroupListViewItem(groupId, insightGroupType));
34+
groupManager.getOrCreateGroup(groupId, () -> new InsightGroupListViewItem(groupId, insightGroupType, route));
3235

3336
final var theListView = new InsightListViewItem<>(insight);
3437

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55
import java.util.Collection;
66
import java.util.HashMap;
77
import java.util.Map;
8-
import java.util.Optional;
98
import java.util.function.Supplier;
109

1110
public class ListGroupManager {
1211

1312
private final Map<String, GroupListViewItem> groups = new HashMap<>();
1413

1514
public GroupListViewItem getOrCreateGroup(String groupKey, Supplier<GroupListViewItem> supplier) {
16-
Optional<String> existingMatchingGroupKey = groups.keySet()
17-
.stream()
18-
//FYI: Temporary fix because from BE we receive some insights with groupId = "epHTTP:POST Transfer/TransferFunds" and some insights with groupId = "HTTP POST Transfer/TransferFunds" but all these items should be displayed on the same group on UI
19-
.filter(s -> s.endsWith(groupKey.replace("HTTP ", "")))
20-
.findFirst();
21-
return groups.computeIfAbsent(existingMatchingGroupKey.orElse(groupKey), key -> supplier.get());
15+
return groups.computeIfAbsent(groupKey, key -> supplier.get());
2216
}
2317

2418
public Collection<GroupListViewItem> getGroupItems() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ package org.digma.intellij.plugin.model.rest.insights
22

33
interface EndpointInsight : CodeObjectInsight {
44
var route: String
5+
var endpointSpan: String
56
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import java.util.*
77

88
data class HighUsageInsight
99
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
10-
@ConstructorProperties("codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "maxCallsIn1Min")
10+
@ConstructorProperties("codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "endpointSpan", "maxCallsIn1Min")
1111
constructor(
1212
override val codeObjectId: String,
1313
override var route: String,
1414
override val actualStartTime: Date?,
1515
override val customStartTime: Date?,
1616
override val prefixedCodeObjectId: String?,
17+
override var endpointSpan: String,
1718
val maxCallsIn1Min: Int,
1819
) : EndpointInsight {
1920
override val type: InsightType = InsightType.HighUsage

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import java.util.*
77

88
data class LowUsageInsight
99
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
10-
@ConstructorProperties("codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "maxCallsIn1Min")
10+
@ConstructorProperties("codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "endpointSpan", "maxCallsIn1Min")
1111
constructor(
1212
override val codeObjectId: String,
1313
override var route: String,
1414
override val actualStartTime: Date?,
1515
override val customStartTime: Date?,
1616
override val prefixedCodeObjectId: String?,
17+
override var endpointSpan: String,
1718
val maxCallsIn1Min: Int,
1819
) : EndpointInsight {
1920
override val type: InsightType = InsightType.LowUsage

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import java.util.*
77

88
data class NormalUsageInsight
99
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
10-
@ConstructorProperties("codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "maxCallsIn1Min")
10+
@ConstructorProperties("codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "endpointSpan", "maxCallsIn1Min")
1111
constructor(
1212
override val codeObjectId: String,
1313
override var route: String,
1414
override val actualStartTime: Date?,
1515
override val customStartTime: Date?,
1616
override val prefixedCodeObjectId: String?,
17+
override var endpointSpan: String,
1718
val maxCallsIn1Min: Int,
1819
) : EndpointInsight {
1920
override val type: InsightType = InsightType.NormalUsage

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.util.*
88
data class SlowEndpointInsight
99
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
1010
@ConstructorProperties(
11-
"codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId",
11+
"codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "endpointSpan",
1212
"endpointsMedian", "endpointsMedianOfMedians", "endpointsMedianOfP75", "endpointsP75",
1313
"min", "max", "mean", "median",
1414
"p75", "p95", "p99",
@@ -19,6 +19,7 @@ constructor(
1919
override val actualStartTime: Date?,
2020
override val customStartTime: Date?,
2121
override val prefixedCodeObjectId: String?,
22+
override var endpointSpan: String,
2223
val endpointsMedian: Duration,
2324
val endpointsMedianOfMedians: Duration,
2425
val endpointsMedianOfP75: Duration,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import java.util.*
77

88
data class SlowestSpansInsight
99
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
10-
@ConstructorProperties("codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "spans")
10+
@ConstructorProperties("codeObjectId", "route", "actualStartTime", "customStartTime", "prefixedCodeObjectId", "endpointSpan", "spans")
1111
constructor(
1212
override val codeObjectId: String,
1313
override var route: String,
1414
override val actualStartTime: Date?,
1515
override val customStartTime: Date?,
1616
override val prefixedCodeObjectId: String?,
17+
override var endpointSpan: String,
1718
val spans: List<SlowSpanInfo>,
1819
) : EndpointInsight {
1920
override val type: InsightType = InsightType.SlowestSpans

0 commit comments

Comments
 (0)