Skip to content

Commit 34c8459

Browse files
authored
Merge pull request #2221 from digma-ai/close-wizard-when-replacing-deployment
close wizard when changing to centralized Closes #2216
2 parents 6dd1615 + 5e4e3d6 commit 34c8459

File tree

6 files changed

+94
-36
lines changed

6 files changed

+94
-36
lines changed

build.gradle.kts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ intellijPlatform {
217217
tasks {
218218

219219
prepareSandbox {
220+
221+
/*
222+
sometimes runIde fails with this error:
223+
Execution failed for task ':prepareSandbox'.
224+
> Cannot access output property '$1$4' of task ':prepareSandbox'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by using Task.doNotTrackState(). For more information, please refer to https://docs.gradle.org/8.8/userguide/incremental_build.html#sec:disable-state-tracking in the Gradle documentation.
225+
> java.io.IOException: Cannot snapshot /home/shalom/workspace/digma/digma-intellij-plugin/build/idea-sandbox/IC-2024.1.3/system/jcef_cache/SingletonSocket: not a regular file
226+
*/
227+
doNotTrackState("prepareSandbox needs to re-run every time")
228+
220229
//copy rider dlls to the plugin sandbox, so it is packaged in the zip
221230
from(configurations.getByName("riderDotNetObjects")) {
222231
into("${rootProject.name}/dotnet/")
@@ -264,7 +273,12 @@ tasks {
264273

265274
val deleteLog by registering(Delete::class) {
266275
outputs.upToDateWhen { false }
267-
project.layout.buildDirectory.dir("idea-sandbox/system/log").get().asFile.walk().forEach {
276+
val ideFolderName = if(platformType == IntelliJPlatformType.Rider){
277+
"${platformType.code}-${project.currentProfile().riderVersion}"
278+
}else{
279+
"${platformType.code}-${project.currentProfile().platformVersion}"
280+
}
281+
project.layout.buildDirectory.dir("idea-sandbox/$ideFolderName/log").get().asFile.walk().forEach {
268282
if (it.name.endsWith(".log")) {
269283
delete(it)
270284
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,16 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
670670
throw new AnalyticsServiceException(e);
671671
}
672672

673+
674+
//this message should help us understand the logs when debugging issues. it will help
675+
// understand that there are more and more exceptions.
676+
//code below and in handleInvocationTargetException will log the exceptions but our Log class
677+
// will not explode the logs, so we don't see all the exceptions in the log as they happen.
678+
//this message will explode the idea.log if user has digma trace logging on and no backend running,
679+
// which shouldn't happen, users should not have digma trace logging on all the time.
680+
Log.log(LOGGER::trace,"got exception in AnalyticsService {}",ExceptionUtils.findFirstRealExceptionCause(e));
681+
682+
673683
//Note: when logging LOGGER.error idea will pop up a red message which we don't want, so only report warn messages.
674684

675685
//handle only InvocationTargetException, other exceptions are probably a bug.

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.intellij.openapi.diagnostic.Logger;
77
import com.intellij.openapi.project.*;
88
import org.digma.intellij.plugin.auth.AuthManager;
9-
import org.digma.intellij.plugin.common.ProjectUtilsKt;
9+
import org.digma.intellij.plugin.common.*;
1010
import org.digma.intellij.plugin.log.Log;
1111
import org.digma.intellij.plugin.settings.SettingsState;
1212

@@ -32,31 +32,33 @@ public AnalyticsServiceSettingsWatcher() {
3232

3333
SettingsState.getInstance().addChangeListener(state -> {
3434

35-
Log.log(LOGGER::debug, "settings changed event");
35+
Backgroundable.executeOnPooledThread(() -> {
36+
Log.log(LOGGER::debug, "settings changed event");
3637

37-
boolean shouldReplaceClient = false;
38+
boolean shouldReplaceClient = false;
3839

39-
if (!Objects.equals(state.apiUrl, myApiUrl)) {
40-
myApiUrl = state.apiUrl;
41-
shouldReplaceClient = true;
42-
}
43-
44-
//replace the client only when apiUrl is changed.
45-
//there is no need to replace the client when api token is changed because there is an
46-
// AuthenticationProvider that always takes it from the settings
47-
if (shouldReplaceClient) {
48-
Log.log(LOGGER::debug, "api url changed to {}, calling replace client", myApiUrl);
49-
AuthManager.getInstance().logout();
50-
AuthManager.getInstance().pauseBeforeClientChange();
51-
AuthManager.getInstance().replaceClient(myApiUrl);
40+
if (!Objects.equals(state.apiUrl, myApiUrl)) {
41+
myApiUrl = state.apiUrl;
42+
shouldReplaceClient = true;
43+
}
5244

53-
for (Project openProject : ProjectManager.getInstance().getOpenProjects()) {
54-
if (ProjectUtilsKt.isProjectValid(openProject)) {
55-
var analyticsService = AnalyticsService.getInstance(openProject);
56-
analyticsService.replaceClient(myApiUrl);
45+
//replace the client only when apiUrl is changed.
46+
//there is no need to replace the client when api token is changed because there is an
47+
// AuthenticationProvider that always takes it from the settings
48+
if (shouldReplaceClient) {
49+
Log.log(LOGGER::debug, "api url changed to {}, calling replace client", myApiUrl);
50+
AuthManager.getInstance().logout();
51+
AuthManager.getInstance().pauseBeforeClientChange();
52+
AuthManager.getInstance().replaceClient(myApiUrl);
53+
54+
for (Project openProject : ProjectManager.getInstance().getOpenProjects()) {
55+
if (ProjectUtilsKt.isProjectValid(openProject)) {
56+
var analyticsService = AnalyticsService.getInstance(openProject);
57+
analyticsService.replaceClient(myApiUrl);
58+
}
5759
}
5860
}
59-
}
61+
});
6062

6163
}, this);
6264

ide-common/src/main/java/org/digma/intellij/plugin/ui/MainToolWindowCardsController.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.intellij.openapi.wm.ToolWindow;
77
import com.intellij.ui.content.*;
88
import org.digma.intellij.plugin.analytics.*;
9-
import org.digma.intellij.plugin.common.EDT;
9+
import org.digma.intellij.plugin.common.*;
1010
import org.digma.intellij.plugin.log.Log;
1111
import org.digma.intellij.plugin.ui.panels.DisposablePanel;
1212
import org.digma.intellij.plugin.updates.*;
@@ -89,9 +89,34 @@ public void connectionGained() {
8989
project.getMessageBus().connect().subscribe(AggressiveUpdateStateChangedEvent.Companion.getUPDATE_STATE_CHANGED_TOPIC(),
9090
(AggressiveUpdateStateChangedEvent) this::updateStateChanged);
9191

92+
93+
project.getMessageBus().connect().subscribe(ApiClientChangedEvent.getAPI_CLIENT_CHANGED_TOPIC(),new ApiClientChangedEvent(){
94+
95+
@Override
96+
public void apiClientChanged(@NotNull String newUrl) {
97+
Backgroundable.ensurePooledThread(() -> {
98+
if (wizard.isOn()){
99+
if(isCentralized()){
100+
EDT.ensureEDT(() -> wizardFinished());
101+
}
102+
}
103+
});
104+
}
105+
});
92106
}
93107

94108

109+
private boolean isCentralized(){
110+
try{
111+
var about = AnalyticsService.getInstance(project).getAbout();
112+
return Boolean.TRUE.equals(about.isCentralize());
113+
}catch (Throwable e){
114+
return false;
115+
}
116+
}
117+
118+
119+
95120
public static MainToolWindowCardsController getInstance(@NotNull Project project) {
96121
return project.getService(MainToolWindowCardsController.class);
97122
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/analytics/BackendConnectionMonitor.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package org.digma.intellij.plugin.analytics
22

33
import com.intellij.openapi.Disposable
44
import com.intellij.openapi.components.Service
5+
import com.intellij.openapi.diagnostic.Logger
56
import com.intellij.openapi.project.Project
67
import com.intellij.util.messages.MessageBusConnection
8+
import org.digma.intellij.plugin.log.Log
79

810
/**
911
* This service keeps track of the analytics service connection status. it is used to decide when to show the
@@ -13,6 +15,9 @@ import com.intellij.util.messages.MessageBusConnection
1315
@Service(Service.Level.PROJECT)
1416
class BackendConnectionMonitor(val project: Project) : Disposable, AnalyticsServiceConnectionEvent {
1517

18+
19+
private val logger: Logger = Logger.getInstance(this::class.java)
20+
1621
companion object {
1722
@JvmStatic
1823
fun getInstance(project: Project): BackendConnectionMonitor {
@@ -53,10 +58,12 @@ class BackendConnectionMonitor(val project: Project) : Disposable, AnalyticsServ
5358
}
5459

5560
override fun connectionLost() {
61+
Log.log(logger::trace,"got connectionLost")
5662
connectionError()
5763
}
5864

5965
override fun connectionGained() {
66+
Log.log(logger::trace,"got connectionGained")
6067
connectionOk()
6168
}
6269

src/main/kotlin/org/digma/intellij/plugin/ui/jcef/JCefComponent.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ private constructor(
205205
//this event run on EDT
206206
Backgroundable.executeOnPooledThread {
207207
try {
208+
//can not rely here on backend about info because this event may be processed before the api client was changed.
209+
//the API_CLIENT_CHANGED_TOPIC is more suitable. it is handled here.
208210
val apiUrl = settings.apiUrl
209211
sendApiUrl(jbCefBrowser.cefBrowser, apiUrl)
210212
sendIsMicrometerProject(jbCefBrowser.cefBrowser, SpringBootMicrometerConfigureDepsService.isSpringBootWithMicrometer())
@@ -255,16 +257,14 @@ private constructor(
255257

256258

257259
project.messageBus.connect(observabilityChangeParentDisposable).subscribe(
258-
ObservabilityChanged.OBSERVABILITY_CHANGED_TOPIC, object : ObservabilityChanged {
259-
override fun observabilityChanged(isObservabilityEnabled: Boolean) {
260-
try {
261-
sendObservabilityEnabledMessage(
262-
jbCefBrowser.cefBrowser,
263-
isObservabilityEnabled
264-
)
265-
} catch (e: Throwable) {
266-
ErrorReporter.getInstance().reportError("JCefComponent.observabilityChanged", e)
267-
}
260+
ObservabilityChanged.OBSERVABILITY_CHANGED_TOPIC, ObservabilityChanged { isObservabilityEnabled ->
261+
try {
262+
sendObservabilityEnabledMessage(
263+
jbCefBrowser.cefBrowser,
264+
isObservabilityEnabled
265+
)
266+
} catch (e: Throwable) {
267+
ErrorReporter.getInstance().reportError("JCefComponent.observabilityChanged", e)
268268
}
269269
}
270270
)
@@ -281,9 +281,9 @@ private constructor(
281281
scope,
282282
codeLocation,
283283
hasErrors,
284-
insightsStats?.analyticsInsightsCount ?: 0,
285-
insightsStats?.issuesInsightsCount ?: 0,
286-
insightsStats?.unreadInsightsCount ?: 0
284+
insightsStats.analyticsInsightsCount,
285+
insightsStats.issuesInsightsCount,
286+
insightsStats.unreadInsightsCount
287287
)
288288
} catch (e: Throwable) {
289289
ErrorReporter.getInstance().reportError("JCefComponent.scopeChanged", e)

0 commit comments

Comments
 (0)