Skip to content

Commit 319b9dc

Browse files
authored
Merge branch 'main' into feat/add_links_on_insights
2 parents de42b7a + 19cad40 commit 319b9dc

File tree

29 files changed

+364
-190
lines changed

29 files changed

+364
-190
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 {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.digma.intellij.plugin.analytics;
2+
3+
import com.intellij.util.messages.Topic;
4+
5+
public interface TabsChanged {
6+
7+
@Topic.ProjectLevel
8+
Topic<TabsChanged> TABS_CHANGED_TOPIC = Topic.create("TABS_CHANGED_TOPIC", TabsChanged.class);
9+
10+
void activeTabIndexChanged(int newTabIndex);
11+
12+
}

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,31 +51,31 @@ 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 SpanScalingRootCause:
4560
return new GroupListViewItemBuilder<SpanScalingRootCauseInsight>(InsightGroupType.Span, null, spanScalingRootCauseInsight -> spanScalingRootCauseInsight.getSpanInfo().getName());
4661
case SpanDurationBreakdown:
47-
return new GroupListViewItemBuilder<SpanDurationBreakdownInsight>(InsightGroupType.Span, null, SpanDurationBreakdownInsight::getSpanName);
62+
return new GroupListViewItemBuilder<SpanDurationBreakdownInsight>(InsightGroupType.Span, null, SpanDurationBreakdownInsight::spanName);
4863
case SpanEndpointBottleneck:
49-
return new GroupListViewItemBuilder<SpanSlowEndpointsInsight>(InsightGroupType.Span, null, insight -> insight.getSpan().getName());
64+
return new GroupListViewItemBuilder<SpanSlowEndpointsInsight>(InsightGroupType.Span, null, insight -> insight.spanName());
5065
case SpaNPlusOne:
51-
return new GroupListViewItemBuilder<SpanNPlusOneInsight>(InsightGroupType.Span, null, insight -> insight.getSpan().getName());
66+
return new GroupListViewItemBuilder<SpanNPlusOneInsight>(InsightGroupType.Span, null, insight -> insight.spanName());
5267
case SlowestSpans:
53-
return new GroupListViewItemBuilder<SlowestSpansInsight>(InsightGroupType.HttpEndpoint, SlowestSpansInsight::getRoute, SlowestSpansInsight::getEndpointSpan);
68+
return new GroupListViewItemBuilder<SlowestSpansInsight>(InsightGroupType.HttpEndpoint, SlowestSpansInsight::getRoute, SlowestSpansInsight::endpointSpanName);
5469
case LowUsage:
55-
return new GroupListViewItemBuilder<LowUsageInsight>(InsightGroupType.HttpEndpoint, LowUsageInsight::getRoute, LowUsageInsight::getEndpointSpan);
70+
return new GroupListViewItemBuilder<LowUsageInsight>(InsightGroupType.HttpEndpoint, LowUsageInsight::getRoute, LowUsageInsight::endpointSpanName);
5671
case NormalUsage:
57-
return new GroupListViewItemBuilder<NormalUsageInsight>(InsightGroupType.HttpEndpoint, NormalUsageInsight::getRoute, NormalUsageInsight::getEndpointSpan);
72+
return new GroupListViewItemBuilder<NormalUsageInsight>(InsightGroupType.HttpEndpoint, NormalUsageInsight::getRoute, NormalUsageInsight::endpointSpanName);
5873
case HighUsage:
59-
return new GroupListViewItemBuilder<HighUsageInsight>(InsightGroupType.HttpEndpoint, HighUsageInsight::getRoute, HighUsageInsight::getEndpointSpan);
74+
return new GroupListViewItemBuilder<HighUsageInsight>(InsightGroupType.HttpEndpoint, HighUsageInsight::getRoute, HighUsageInsight::endpointSpanName);
6075
case SlowEndpoint:
61-
return new GroupListViewItemBuilder<SlowEndpointInsight>(InsightGroupType.HttpEndpoint, SlowEndpointInsight::getRoute, SlowEndpointInsight::getEndpointSpan);
76+
return new GroupListViewItemBuilder<SlowEndpointInsight>(InsightGroupType.HttpEndpoint, SlowEndpointInsight::getRoute, SlowEndpointInsight::endpointSpanName);
6277
case EndpointSpaNPlusOne:
63-
return new GroupListViewItemBuilder<EPNPlusSpansInsight>(InsightGroupType.HttpEndpoint, EPNPlusSpansInsight::getRoute, EPNPlusSpansInsight::getEndpointSpan);
78+
return new GroupListViewItemBuilder<EPNPlusSpansInsight>(InsightGroupType.HttpEndpoint, EPNPlusSpansInsight::getRoute, EPNPlusSpansInsight::endpointSpanName);
6479
case Unmapped:
6580
return new NoGroupListViewItemBuilder<UnmappedInsight>();
6681
default:

ide-common/src/main/kotlin/org/digma/intellij/plugin/ui/service/AbstractViewService.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class AbstractViewService(val project: Project) : Disposable {
2020

2121
private val analyticsConnectionEventsConnection: MessageBusConnection = project.messageBus.connect()
2222

23-
private val toolWindowTabsHelper = ToolWindowTabsHelper.getInstance(project)
23+
private val tabsHelper = TabsHelper.getInstance(project)
2424

2525
init {
2626
//subscribe to connection lost/gained , call doUpdateUi() on each event so that the no connection card will show or hide
@@ -43,12 +43,12 @@ abstract class AbstractViewService(val project: Project) : Disposable {
4343

4444
fun doConnectionLost() {
4545
//if a view needs to do something when connection lost can override this method and don't forget to call super
46-
if (toolWindowTabsHelper.isErrorDetailsOn()) {
47-
toolWindowTabsHelper.errorDetailsOff()
46+
if (tabsHelper.isErrorDetailsOn()) {
47+
tabsHelper.errorDetailsOff()
4848
if (this is ErrorsViewService) {
4949
this.closeErrorDetails()
5050
}
51-
toolWindowTabsHelper.errorDetailsClosed()
51+
tabsHelper.errorDetailsClosed()
5252
}
5353
}
5454

@@ -62,11 +62,11 @@ abstract class AbstractViewService(val project: Project) : Disposable {
6262
//in the view until its closed. there may be exceptions, for example the summary view can reload while error details
6363
// is on but setVisible should not run.
6464
open fun canUpdateUI(): Boolean {
65-
return !toolWindowTabsHelper.isErrorDetailsOn()
65+
return !tabsHelper.isErrorDetailsOn()
6666
}
6767

6868
open fun canSetVisible(): Boolean {
69-
return !toolWindowTabsHelper.isErrorDetailsOn()
69+
return !tabsHelper.isErrorDetailsOn()
7070
}
7171

7272

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package org.digma.intellij.plugin.ui.service
2+
3+
import com.intellij.openapi.diagnostic.Logger
4+
import com.intellij.openapi.project.Project
5+
import com.intellij.ui.content.Content
6+
import org.digma.intellij.plugin.analytics.TabsChanged
7+
import org.digma.intellij.plugin.log.Log
8+
9+
class TabsHelper(val project: Project) {
10+
private val logger: Logger = Logger.getInstance(TabsHelper::class.java)
11+
12+
var currentTabIndex = 0
13+
14+
private var visibleTabBeforeErrorDetails: Int? = null
15+
private var errorDetailsOn = false
16+
17+
companion object {
18+
const val INSIGHTS_TAB_NAME = "Insights"
19+
const val DEFAULT_ERRORS_TAB_NAME = "Errors"
20+
const val DETAILED_ERRORS_TAB_NAME = "Error Details"
21+
const val SUMMARY_TAB_NAME = "Summary"
22+
23+
@JvmStatic
24+
fun getInstance(project: Project): TabsHelper {
25+
return project.getService(TabsHelper::class.java)
26+
}
27+
}
28+
29+
fun isInsightsTab(content: Content?): Boolean {
30+
return content != null && content.tabName.equals(INSIGHTS_TAB_NAME, ignoreCase = true)
31+
}
32+
33+
fun isErrorsTab(content: Content?): Boolean {
34+
return content != null && content.tabName.equals(DEFAULT_ERRORS_TAB_NAME, ignoreCase = true)
35+
}
36+
37+
fun isSummaryTab(content: Content?): Boolean {
38+
return content != null && content.tabName.equals(SUMMARY_TAB_NAME, ignoreCase = true)
39+
}
40+
41+
42+
fun showingErrorDetails() {
43+
visibleTabBeforeErrorDetails = currentTabIndex
44+
}
45+
46+
fun errorDetailsClosed() {
47+
visibleTabBeforeErrorDetails?.let { notifyTabChanged(it) }
48+
visibleTabBeforeErrorDetails = null
49+
}
50+
51+
private fun notifyTabChanged(newTabIndex: Int) {
52+
Log.log(logger::info, "Firing TabChanged event for {}", newTabIndex)
53+
if (project.isDisposed) {
54+
return
55+
}
56+
val publisher = project.messageBus.syncPublisher(TabsChanged.TABS_CHANGED_TOPIC)
57+
publisher.activeTabIndexChanged(newTabIndex)
58+
}
59+
60+
fun errorDetailsOn() {
61+
errorDetailsOn = true
62+
notifyTabChanged(1)
63+
}
64+
65+
fun errorDetailsOff() {
66+
errorDetailsOn = false
67+
}
68+
69+
fun isErrorDetailsOn(): Boolean {
70+
return errorDetailsOn
71+
}
72+
73+
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/ui/service/ToolWindowTabsHelper.kt

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)