Skip to content

Commit 84be245

Browse files
committed
Feature/Insights pending and no data yet (#396)
1 parent 8650167 commit 84be245

File tree

17 files changed

+337
-27
lines changed

17 files changed

+337
-27
lines changed

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import org.digma.intellij.plugin.model.rest.errordetails.CodeObjectErrorDetails;
55
import org.digma.intellij.plugin.model.rest.errors.CodeObjectError;
66
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
7+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsightsStatusResponse;
78
import org.digma.intellij.plugin.model.rest.insights.CustomStartTimeInsightRequest;
89
import org.digma.intellij.plugin.model.rest.insights.GlobalInsight;
10+
import org.digma.intellij.plugin.model.rest.insights.InsightOfMethodsRequest;
911
import org.digma.intellij.plugin.model.rest.insights.InsightsRequest;
1012
import org.digma.intellij.plugin.model.rest.insights.SpanHistogramQuery;
1113
import org.digma.intellij.plugin.model.rest.recentactivity.RecentActivityRequest;
@@ -28,6 +30,8 @@ public interface AnalyticsProvider extends Closeable {
2830

2931
List<CodeObjectError> getErrorsOfCodeObject(String environment, List<String> codeObjectIds);
3032

33+
CodeObjectInsightsStatusResponse getCodeObjectInsightStatus(InsightOfMethodsRequest request);
34+
3135
void setInsightCustomStartTime(CustomStartTimeInsightRequest customStartTimeInsightRequest);
3236

3337
CodeObjectErrorDetails getCodeObjectErrorDetails(String errorSourceId);

analytics-provider/src/main/java/org/digma/intellij/plugin/analytics/RestAnalyticsProvider.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import org.digma.intellij.plugin.model.rest.errordetails.CodeObjectErrorDetails;
1111
import org.digma.intellij.plugin.model.rest.errors.CodeObjectError;
1212
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
13+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsightsStatusResponse;
1314
import org.digma.intellij.plugin.model.rest.insights.CustomStartTimeInsightRequest;
1415
import org.digma.intellij.plugin.model.rest.insights.GlobalInsight;
16+
import org.digma.intellij.plugin.model.rest.insights.InsightOfMethodsRequest;
1517
import org.digma.intellij.plugin.model.rest.insights.InsightsRequest;
1618
import org.digma.intellij.plugin.model.rest.insights.SpanHistogramQuery;
1719
import org.digma.intellij.plugin.model.rest.recentactivity.RecentActivityRequest;
@@ -68,7 +70,7 @@ public List<String> getEnvironments() {
6870
}
6971

7072

71-
public void sendDebuggerEvent(DebuggerEventRequest debuggerEventRequest){
73+
public void sendDebuggerEvent(DebuggerEventRequest debuggerEventRequest) {
7274
execute(() -> client.analyticsProvider.sendDebuggerEvent(debuggerEventRequest));
7375
}
7476

@@ -87,6 +89,11 @@ public List<CodeObjectError> getErrorsOfCodeObject(String environment, List<Stri
8789
return execute(() -> client.analyticsProvider.getErrorsOfCodeObject(environment, codeObjectIds));
8890
}
8991

92+
@Override
93+
public CodeObjectInsightsStatusResponse getCodeObjectInsightStatus(InsightOfMethodsRequest request) {
94+
return execute(() -> client.analyticsProvider.getCodeObjectInsightStatus(request));
95+
}
96+
9097
@Override
9198
public void setInsightCustomStartTime(CustomStartTimeInsightRequest customStartTimeInsightRequest) {
9299
execute(() -> client.analyticsProvider.setInsightCustomStartTime(customStartTimeInsightRequest));
@@ -305,6 +312,13 @@ private interface AnalyticsProviderRetrofit {
305312
@POST("/CodeAnalytics/insights")
306313
Call<List<GlobalInsight>> getGlobalInsights(@Body InsightsRequest insightsRequest);
307314

315+
@Headers({
316+
"Accept: application/+json",
317+
"Content-Type:application/json"
318+
})
319+
@POST("/CodeAnalytics/codeObjects/insight_status")
320+
Call<CodeObjectInsightsStatusResponse> getCodeObjectInsightStatus(@Body InsightOfMethodsRequest insightsRequest);
321+
308322
@Headers({
309323
"Accept: application/+json",
310324
"Content-Type:application/json"

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ public void actualgetHtmlGraphForSpanPercentiles() {
6161
System.out.println("htmlBody:" + htmlBody);
6262
}
6363

64+
// @Test
65+
public void actualGetCodeObjectInsightStatus() {
66+
final InsightOfMethodsRequest request = new InsightOfMethodsRequest(
67+
"ARIKS-MACBOOK-PRO.LOCAL[LOCAL]",
68+
List.of(
69+
new MethodWithCodeObjects("method:org.springframework.samples.petclinic.sample.SampleInsightsController$_$doWorkForBottleneck2", List.of(), List.of())
70+
)
71+
);
72+
AnalyticsProvider analyticsProvider = new RestAnalyticsProvider("https://localhost:5051");
73+
74+
75+
CodeObjectInsightsStatusResponse response = analyticsProvider.getCodeObjectInsightStatus(request);
76+
77+
System.out.println("response:" + response);
78+
}
79+
6480
@Test
6581
void getInsights() throws JsonProcessingException {
6682

@@ -88,29 +104,29 @@ void getInsights() throws JsonProcessingException {
88104
expectedCodeObjectInsights.add(expectedErrorInsight);
89105

90106
String expectedNormalUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
91-
NormalUsageInsight expectedNormalUsageInsight = new NormalUsageInsight( expectedNormalUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
107+
NormalUsageInsight expectedNormalUsageInsight = new NormalUsageInsight(expectedNormalUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
92108
ROUTE, ENDPOINT_SPAN, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedNormalUsageInsightCodeObjectId), null, 40);
93109
expectedCodeObjectInsights.add(expectedNormalUsageInsight);
94110

95111
String expectedLowUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$Abc";
96-
LowUsageInsight expectedLowUsageInsight = new LowUsageInsight( expectedLowUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
112+
LowUsageInsight expectedLowUsageInsight = new LowUsageInsight(expectedLowUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
97113
ROUTE, ENDPOINT_SPAN, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedLowUsageInsightCodeObjectId), null, 13);
98114
expectedCodeObjectInsights.add(expectedLowUsageInsight);
99115

100116
String expectedHighUsageInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$Defg";
101-
HighUsageInsight expectedHighUsageInsight = new HighUsageInsight( expectedHighUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
117+
HighUsageInsight expectedHighUsageInsight = new HighUsageInsight(expectedHighUsageInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
102118
ROUTE, ENDPOINT_SPAN, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedHighUsageInsightCodeObjectId), null, 98);
103119
expectedCodeObjectInsights.add(expectedHighUsageInsight);
104120

105-
SpanInfo spanInfo = new SpanInfo("Retrieving account", "Retrieving account", "MoneyTransferDomainService", "Sample.MoneyTransfer.API","Sample.MoneyTransfer.API.MoneyTransferDomainService$_$Error");
121+
SpanInfo spanInfo = new SpanInfo("Retrieving account", "Retrieving account", "MoneyTransferDomainService", "Sample.MoneyTransfer.API", "Sample.MoneyTransfer.API.MoneyTransferDomainService$_$Error");
106122
SlowSpanInfo slowSpanInfo = new SlowSpanInfo(spanInfo,
107-
new Percentile(0.10970134022722634D,new Duration(3.44D,"ms",3441700L)),
108-
new Percentile(0.2566821090980162D,new Duration(3.44D,"ms",3441700L)),
109-
new Percentile(0.4407383382867023D,new Duration(5.64D,"ms",5643900L)),
123+
new Percentile(0.10970134022722634D, new Duration(3.44D, "ms", 3441700L)),
124+
new Percentile(0.2566821090980162D, new Duration(3.44D, "ms", 3441700L)),
125+
new Percentile(0.4407383382867023D, new Duration(5.64D, "ms", 5643900L)),
110126
null, null);
111127

112128
String expectedSlowestSpansInsightCodeObjectId = "Sample.MoneyTransfer.API.Domain.Services.MoneyTransferDomainService$_$TransferFunds";
113-
SlowestSpansInsight expectedSlowestSpansInsight = new SlowestSpansInsight( expectedSlowestSpansInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
129+
SlowestSpansInsight expectedSlowestSpansInsight = new SlowestSpansInsight(expectedSlowestSpansInsightCodeObjectId, ENV_1, SCOPE_1, IMPORTANCE_3, null,
114130
ROUTE, ENDPOINT_SPAN, actualStartTimeNow, customStartTimeFiveDaysBefore, addPrefixToCodeObjectId(expectedSlowestSpansInsightCodeObjectId), null, Collections.singletonList(slowSpanInfo));
115131
expectedCodeObjectInsights.add(expectedSlowestSpansInsight);
116132

ide-common/src/main/java/org/digma/intellij/plugin/analytics/AnalyticsService.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@
1111
import org.digma.intellij.plugin.common.usageStatusChange.UsageStatusChangeListener;
1212
import org.digma.intellij.plugin.log.Log;
1313
import org.digma.intellij.plugin.model.InsightType;
14+
import org.digma.intellij.plugin.model.discovery.MethodInfo;
1415
import org.digma.intellij.plugin.model.rest.debugger.DebuggerEventRequest;
1516
import org.digma.intellij.plugin.model.rest.errordetails.CodeObjectErrorDetails;
1617
import org.digma.intellij.plugin.model.rest.errors.CodeObjectError;
17-
import org.digma.intellij.plugin.model.rest.insights.*;
18+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
19+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsightsStatusResponse;
20+
import org.digma.intellij.plugin.model.rest.insights.CustomStartTimeInsightRequest;
21+
import org.digma.intellij.plugin.model.rest.insights.GlobalInsight;
22+
import org.digma.intellij.plugin.model.rest.insights.InsightOfMethodsRequest;
23+
import org.digma.intellij.plugin.model.rest.insights.InsightsRequest;
24+
import org.digma.intellij.plugin.model.rest.insights.MethodWithCodeObjects;
25+
import org.digma.intellij.plugin.model.rest.insights.SpanHistogramQuery;
1826
import org.digma.intellij.plugin.model.rest.recentactivity.RecentActivityRequest;
1927
import org.digma.intellij.plugin.model.rest.recentactivity.RecentActivityResult;
2028
import org.digma.intellij.plugin.model.rest.usage.UsageStatusRequest;
@@ -24,6 +32,7 @@
2432
import org.digma.intellij.plugin.settings.SettingsState;
2533
import org.jetbrains.annotations.NotNull;
2634
import org.jetbrains.annotations.Nullable;
35+
import org.jetbrains.annotations.VisibleForTesting;
2736

2837
import javax.net.ssl.SSLException;
2938
import java.io.Closeable;
@@ -37,7 +46,13 @@
3746
import java.net.UnknownHostException;
3847
import java.net.http.HttpTimeoutException;
3948
import java.time.Instant;
40-
import java.util.*;
49+
import java.util.ArrayList;
50+
import java.util.Arrays;
51+
import java.util.Collections;
52+
import java.util.HashMap;
53+
import java.util.List;
54+
import java.util.Map;
55+
import java.util.Objects;
4156
import java.util.concurrent.TimeUnit;
4257
import java.util.concurrent.atomic.AtomicBoolean;
4358
import java.util.function.Supplier;
@@ -180,6 +195,22 @@ public List<CodeObjectError> getErrorsOfCodeObject(List<String> codeObjectIds) t
180195
return executeCatching(() -> analyticsProviderProxy.getErrorsOfCodeObject(env, codeObjectIds));
181196
}
182197

198+
public CodeObjectInsightsStatusResponse getCodeObjectInsightStatus(List<MethodInfo> methodInfos) throws AnalyticsServiceException {
199+
var env = getCurrentEnvironment();
200+
var methodWithCodeObjects = methodInfos.stream()
201+
.map(it -> toMethodWithCodeObjects(it))
202+
.toList();
203+
return executeCatching(() -> analyticsProviderProxy.getCodeObjectInsightStatus(new InsightOfMethodsRequest(env, methodWithCodeObjects)));
204+
}
205+
206+
@VisibleForTesting
207+
public static MethodWithCodeObjects toMethodWithCodeObjects(MethodInfo methodInfo) {
208+
return new MethodWithCodeObjects(methodInfo.idWithType(),
209+
methodInfo.getSpans().stream().map(it -> it.idWithType()).toList(),
210+
methodInfo.getEndpoints().stream().map(it -> it.idWithType()).toList()
211+
);
212+
}
213+
183214
public void setInsightCustomStartTime(String codeObjectId, InsightType insightType) throws AnalyticsServiceException {
184215
var env = getCurrentEnvironment();
185216
String formattedActualDate = Instant.now().toString();//FYI: by UTC time zone

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
import com.intellij.openapi.project.Project;
55
import org.apache.commons.lang3.time.StopWatch;
66
import org.digma.intellij.plugin.analytics.AnalyticsService;
7+
import org.digma.intellij.plugin.analytics.AnalyticsServiceException;
78
import org.digma.intellij.plugin.document.DocumentInfoService;
89
import org.digma.intellij.plugin.insights.view.BuildersHolder;
910
import org.digma.intellij.plugin.insights.view.InsightsViewBuilder;
1011
import org.digma.intellij.plugin.log.Log;
1112
import org.digma.intellij.plugin.model.InsightType;
1213
import org.digma.intellij.plugin.model.discovery.MethodInfo;
1314
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
15+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsightsStatusResponse;
16+
import org.digma.intellij.plugin.model.rest.insights.InsightStatus;
17+
import org.digma.intellij.plugin.model.rest.insights.MethodWithInsightStatus;
1418
import org.digma.intellij.plugin.model.rest.usage.UsageStatusResult;
1519
import org.digma.intellij.plugin.ui.model.listview.ListViewItem;
1620
import org.jetbrains.annotations.NotNull;
@@ -42,7 +46,7 @@ public InsightsListContainer getCachedInsights(@NotNull MethodInfo methodInfo) {
4246

4347
public InsightsListContainer getInsightsListContainer(@NotNull MethodInfo methodInfo, List<? extends CodeObjectInsight> insightsList) {
4448
List<String> objectIds = getObjectIdsWithType(methodInfo);
45-
Log.log(LOGGER::debug, "Got following code object ids for method {}: {}",methodInfo.getId(), objectIds);
49+
Log.log(LOGGER::debug, "Got following code object ids for method {}: {}", methodInfo.getId(), objectIds);
4650
var stopWatch = StopWatch.createStarted();
4751

4852
try {
@@ -51,7 +55,7 @@ public InsightsListContainer getInsightsListContainer(@NotNull MethodInfo method
5155
Log.log(LOGGER::debug, "CodeObjectInsights for {}: {}", methodInfo.getId(), codeObjectInsights);
5256
final UsageStatusResult usageStatus = documentInfoService.getCachedUsageStatus(methodInfo, objectIds);
5357
InsightsViewBuilder insightsViewBuilder = new InsightsViewBuilder(buildersHolder);
54-
List<ListViewItem<?>> listViewItems = insightsViewBuilder.build(project,methodInfo, codeObjectInsights);
58+
List<ListViewItem<?>> listViewItems = insightsViewBuilder.build(project, methodInfo, codeObjectInsights);
5559
Log.log(LOGGER::debug, "ListViewItems for {}: {}", methodInfo.getId(), listViewItems);
5660
return new InsightsListContainer(listViewItems, codeObjectInsights.size(), usageStatus);
5761
} finally {
@@ -60,6 +64,17 @@ public InsightsListContainer getInsightsListContainer(@NotNull MethodInfo method
6064
}
6165
}
6266

67+
public InsightStatus getInsightStatus(@NotNull MethodInfo methodInfo) {
68+
try {
69+
CodeObjectInsightsStatusResponse response = analyticsService.getCodeObjectInsightStatus(List.of(methodInfo));
70+
MethodWithInsightStatus methodResp = response.getCodeObjectsWithInsightsStatus().iterator().next();
71+
return methodResp.getInsightStatus();
72+
} catch (AnalyticsServiceException e) {
73+
Log.log(LOGGER::debug, "AnalyticsServiceException for getCodeObjectInsightStatus for {}: {}", methodInfo.getId(), e.getMessage());
74+
return InsightStatus.Unknown;
75+
}
76+
}
77+
6378
private List<String> getObjectIdsWithType(@NotNull MethodInfo methodInfo) {
6479
List<String> objectIds = new ArrayList<>();
6580
objectIds.addAll(methodInfo.allIdsWithType());
@@ -70,7 +85,7 @@ private List<String> getObjectIdsWithType(@NotNull MethodInfo methodInfo) {
7085
private List<? extends CodeObjectInsight> filterUnmapped(List<? extends CodeObjectInsight> codeObjectInsights) {
7186
var filteredInsights = new ArrayList<CodeObjectInsight>();
7287
codeObjectInsights.forEach(codeObjectInsight -> {
73-
if (!codeObjectInsight.getType().equals(InsightType.Unmapped)){
88+
if (!codeObjectInsight.getType().equals(InsightType.Unmapped)) {
7489
filteredInsights.add(codeObjectInsight);
7590
}
7691
});

0 commit comments

Comments
 (0)