Skip to content

Commit 39b11e3

Browse files
authored
Merge pull request #2373 from digma-ai/reset-plugin
reset user id Closes #2372
2 parents d280bf8 + e0af753 commit 39b11e3

File tree

6 files changed

+143
-26
lines changed

6 files changed

+143
-26
lines changed

build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ tasks {
315315
//"org.digma.otel.digmaAgentUrl" to "some url
316316

317317
)
318+
319+
//to simulate external user
320+
// environment(
321+
// "devenv" to "notdigma"
322+
// )
323+
318324
}
319325

320326

ide-common/src/main/java/org/digma/intellij/plugin/settings/ProjectSettings.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.intellij.openapi.options.*;
44
import com.intellij.openapi.util.NlsContexts;
55
import org.digma.intellij.plugin.common.*;
6+
import org.digma.intellij.plugin.reset.ResetService;
67
import org.jetbrains.annotations.Nullable;
78

89
import javax.swing.*;
@@ -38,7 +39,8 @@ public JComponent getPreferredFocusedComponent() {
3839
@Override
3940
public boolean isModified() {
4041
SettingsState settings = SettingsState.getInstance();
41-
return isApiUrlChanged(settings) ||
42+
return mySettingsComponent.isResetPluginRequested() ||
43+
isApiUrlChanged(settings) ||
4244
isApiTokenChanged(settings) ||
4345
isJaegerUrlChanged(settings) ||
4446
isJaegerQueryUrlChanged(settings) ||
@@ -148,6 +150,10 @@ public void apply() throws ConfigurationException {
148150

149151

150152
updateSettingsAndFireChange();
153+
154+
if (mySettingsComponent.isResetPluginRequested()) {
155+
ResetService.getInstance().resetUserId();
156+
}
151157
}
152158

153159

@@ -175,6 +181,8 @@ private void updateSettingsAndFireChange() {
175181
@Override
176182
public void reset() {
177183
SettingsState settings = SettingsState.getInstance();
184+
mySettingsComponent.resetResetPluginRequested();
185+
mySettingsComponent.hidePluginResetWarning();
178186
mySettingsComponent.setApiUrl(settings.getApiUrl());
179187
mySettingsComponent.setApiToken(settings.getApiToken());
180188
mySettingsComponent.setJaegerUrl(settings.getJaegerUrl());
@@ -191,4 +199,11 @@ public void reset() {
191199
public void disposeUIResources() {
192200
mySettingsComponent = null;
193201
}
202+
203+
@Override
204+
public void cancel() {
205+
if (mySettingsComponent != null) {
206+
mySettingsComponent.resetResetPluginRequested();
207+
}
208+
}
194209
}

ide-common/src/main/java/org/digma/intellij/plugin/settings/SettingsComponent.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.digma.intellij.plugin.settings;
22

3-
import com.intellij.openapi.ui.ComboBox;
3+
import com.intellij.icons.AllIcons;
4+
import com.intellij.openapi.ui.*;
45
import com.intellij.ui.*;
56
import com.intellij.ui.components.*;
67
import com.intellij.ui.components.fields.ExpandableTextField;
@@ -27,6 +28,7 @@ class SettingsComponent {
2728
private static final List<String> ALLOW_HTTPS = Collections.singletonList("https");
2829
private static final List<String> ALLOW_HTTP_AND_HTTPS = Arrays.asList("http", "https");
2930

31+
private boolean resetPluginRequested = false;
3032

3133
private final JPanel myMainPanel;
3234
private final JBTextField myApiUrlTextField = new JBTextField();
@@ -43,6 +45,8 @@ class SettingsComponent {
4345
private final ExpandableTextField extendedObservabilityTextFiled = new ExpandableTextField();
4446
private final ExpandableTextField extendedObservabilityExcludeTextField = new ExpandableTextField();
4547

48+
private final JBLabel pluginResetWarning = new JBLabel("Plugin will reset and IDE will restart when this dialog is confirmed. click cancel to cancel reset.");
49+
4650
public SettingsComponent() {
4751

4852
extendedObservabilityTextFiled.setToolTipText("package names in format 'my.pkg1;my.pkg2");
@@ -154,6 +158,7 @@ public boolean verify(JComponent input) {
154158
);
155159

156160
var resetButton = new JButton("Reset to defaults");
161+
resetButton.setToolTipText("<html><body>Reset the settings to initial defaults</body>");
157162
resetButton.addActionListener(e -> resetToDefaults());
158163

159164

@@ -174,6 +179,25 @@ public boolean verify(JComponent input) {
174179
}
175180
}
176181

182+
183+
pluginResetWarning.setForeground(JBColor.RED);
184+
pluginResetWarning.setVisible(false);
185+
var resetPluginButton = new JButton("Reset plugin");
186+
resetPluginButton.setToolTipText("<html><body>Reset plugin persistent properties to initial values to simulate fresh start</body>");
187+
resetPluginButton.setVisible("true".equalsIgnoreCase(System.getProperty("org.digma.plugin.resetPlugin.enabled")));
188+
resetPluginButton.addActionListener(e -> {
189+
var confirmation = Messages.showYesNoDialog("Are you sure?\n(Plugin will reset and IDE will restart when the settings window is closed)", "Reset Confirmation", AllIcons.General.WarningDialog);
190+
if (confirmation == 0) {
191+
resetPluginRequested = true;
192+
pluginResetWarning.setVisible(true);
193+
} else {
194+
resetPluginRequested = false;
195+
pluginResetWarning.setVisible(false);
196+
}
197+
});
198+
199+
200+
177201
myMainPanel = FormBuilder.createFormBuilder()
178202
.addLabeledComponent(myUrlLabel, myApiUrlTextField, 1, false)
179203
.addLabeledComponent(new JBLabel("Api token:"), myApiTokenTestField, 1, false)
@@ -188,6 +212,8 @@ public boolean verify(JComponent input) {
188212
.addComponent(resetButton)
189213
.addLabeledComponent(new JBLabel("User id"), userIdLabel)
190214
.addLabeledComponent(new JBLabel("Backend version"), backendVersionLabel)
215+
.addComponent(resetPluginButton)
216+
.addComponent(pluginResetWarning)
191217
.addComponentFillVertically(new JPanel(), 0)
192218
.getPanel();
193219
}
@@ -313,9 +339,21 @@ public void setExtendedObservabilityExclude(@Nullable String extendedObservabili
313339
}
314340

315341

342+
public boolean isResetPluginRequested() {
343+
return resetPluginRequested;
344+
}
345+
346+
public void resetResetPluginRequested() {
347+
resetPluginRequested = false;
348+
}
349+
350+
351+
316352
private void resetToDefaults() {
317353
//create a new SettingsState object and use it for default startup values
318354
SettingsState settingsState = new SettingsState();
355+
resetResetPluginRequested();
356+
hidePluginResetWarning();
319357
this.setApiUrl(settingsState.getApiUrl());
320358
this.setApiToken(settingsState.getApiToken());
321359
this.setJaegerUrl(settingsState.getJaegerUrl());
@@ -328,4 +366,8 @@ private void resetToDefaults() {
328366

329367
this.myEmbeddedJaegerMessage.setVisible(true);
330368
}
369+
370+
public void hidePluginResetWarning() {
371+
this.pluginResetWarning.setVisible(false);
372+
}
331373
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/persistence/PersistenceService.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ class PersistenceService {
203203
state.userEmail = userEmail
204204
}
205205

206+
fun nullifyUserEmail() {
207+
state.userEmail = null
208+
}
209+
206210

207211
fun getUserRegistrationEmail(): String? {
208212
return state.userRegistrationEmail
@@ -212,6 +216,10 @@ class PersistenceService {
212216
state.userRegistrationEmail = userRegistrationEmail
213217
}
214218

219+
fun nullifyUserRegistrationEmail() {
220+
state.userRegistrationEmail = null
221+
}
222+
215223
fun getUserId(): String? {
216224
return state.userId
217225
}
@@ -220,6 +228,10 @@ class PersistenceService {
220228
state.userId = userId
221229
}
222230

231+
fun nullifyUserId() {
232+
state.userId = null
233+
}
234+
223235
fun getLastInsightsEventTime(): String? {
224236
return state.lastInsightsEventTime
225237
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/posthog/ActivityMonitor.kt

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
8888
private var serverInfo: AboutResult? = null
8989
private val simpleEventInterceptor = SimpleEventInterceptor(project)
9090

91-
private val userId: String = UniqueGeneratedUserId.userId
92-
private val isDevUser: Boolean = UniqueGeneratedUserId.isDevUser
9391
private var postHog: PostHog? = null
9492
private val settingsChangeTracker = SettingsChangeTracker()
9593

@@ -173,7 +171,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
173171
mutableDetails["server.deploymentType"] = serverInfo?.deploymentType.toString()
174172

175173
postHog?.capture(
176-
userId,
174+
UniqueGeneratedUserId.userId,
177175
eventName,
178176
mutableDetails
179177
)
@@ -183,7 +181,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
183181
fun registerFramework(framework: MonitoredFramework) {
184182
capture("framework detected", mapOf("framework.name" to framework.name))
185183
postHog?.set(
186-
userId, mapOf(
184+
UniqueGeneratedUserId.userId, mapOf(
187185
"framework.last" to framework.name,
188186
"framework.${framework.name}.last-seen" to Instant.now().toString()
189187
)
@@ -192,13 +190,13 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
192190

193191
fun registerEmail(email: String, courseRequested: Boolean) {
194192
postHog?.identify(
195-
userId, mapOf(
193+
UniqueGeneratedUserId.userId, mapOf(
196194
"email" to getEmailForEvent(),
197195
INSTALL_STATUS_PROPERTY_NAME to getCurrentInstallStatus(),
198196
"user_requested_course" to courseRequested.toString()
199197
)
200198
)
201-
postHog?.alias(userId, email)
199+
postHog?.alias(UniqueGeneratedUserId.userId, email)
202200
}
203201

204202
fun registerCustomEvent(eventName: String, tags: Map<String, Any> = mapOf()) {
@@ -243,7 +241,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
243241
detailsToSend
244242
)
245243
postHog?.set(
246-
userId, mapOf(
244+
UniqueGeneratedUserId.userId, mapOf(
247245
"last-user-action" to action,
248246
"last-user-action-timestamp" to lastUserActionTimestamp.toString()
249247
)
@@ -320,7 +318,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
320318
fun registerFirstAssetsReceived() {
321319
capture("plugin first-assets")
322320
postHog?.set(
323-
userId, mapOf(
321+
UniqueGeneratedUserId.userId, mapOf(
324322
"first-assets-timestamp" to Instant.now().toString()
325323
)
326324
)
@@ -365,7 +363,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
365363
"ide.build" to ideBuildNumber,
366364
"plugin.version" to pluginVersion,
367365
"server.version" to serverInfo?.applicationVersion.toString(),
368-
"user.type" to if (isDevUser) "internal" else "external"
366+
"user.type" to if (UniqueGeneratedUserId.isDevUser) "internal" else "external"
369367
)
370368

371369

@@ -470,7 +468,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
470468
"ide.build" to ideBuildNumber,
471469
"plugin.version" to pluginVersion,
472470
"server.version" to serverInfo?.applicationVersion.toString(),
473-
"user.type" to if (isDevUser) "internal" else "external",
471+
"user.type" to if (UniqueGeneratedUserId.isDevUser) "internal" else "external",
474472
"frequency" to frequency.frequencySinceStart,
475473
"frequency.since.minutes" to frequency.formatDurationToMinutes()
476474
)
@@ -649,15 +647,15 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
649647

650648
//todo: remove at some point
651649
fun registerFirstTimePluginLoaded() {
652-
postHog?.capture(userId, "plugin first-loaded")
650+
postHog?.capture(UniqueGeneratedUserId.userId, "plugin first-loaded")
653651
}
654652

655653
fun registerFirstTimePluginLoadedNew() {
656-
postHog?.capture(userId, "plugin first-init")
654+
postHog?.capture(UniqueGeneratedUserId.userId, "plugin first-init")
657655
}
658656

659657
fun registerPluginLoaded() {
660-
postHog?.capture(userId, "plugin loaded")
658+
postHog?.capture(UniqueGeneratedUserId.userId, "plugin loaded")
661659
}
662660

663661
fun registerPluginUninstalled(): String {
@@ -678,12 +676,12 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
678676
)
679677
}
680678
postHog?.set(
681-
userId, mapOf(
679+
UniqueGeneratedUserId.userId, mapOf(
682680
INSTALL_STATUS_PROPERTY_NAME to getCurrentInstallStatus(),
683681
INSTALL_STATUS_PROPERTY_NAME + "_timestamp" to SessionMetadataProperties.getInstance().getCreatedAsString(CURRENT_INSTALL_STATUS_KEY)
684682
)
685683
)
686-
return userId
684+
return UniqueGeneratedUserId.userId
687685
}
688686

689687
fun registerPluginDisabled(): String {
@@ -704,12 +702,12 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
704702
)
705703
}
706704
postHog?.set(
707-
userId, mapOf(
705+
UniqueGeneratedUserId.userId, mapOf(
708706
INSTALL_STATUS_PROPERTY_NAME to getCurrentInstallStatus(),
709707
INSTALL_STATUS_PROPERTY_NAME + "_timestamp" to SessionMetadataProperties.getInstance().getCreatedAsString(CURRENT_INSTALL_STATUS_KEY)
710708
)
711709
)
712-
return userId
710+
return UniqueGeneratedUserId.userId
713711
}
714712

715713

@@ -718,7 +716,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
718716
if (this.serverInfo != serverInfo) {
719717
this.serverInfo = serverInfo
720718
postHog?.set(
721-
userId,
719+
UniqueGeneratedUserId.userId,
722720
mapOf(
723721
"server.version" to serverInfo.applicationVersion,
724722
"server.deploymentType" to (serverInfo.deploymentType ?: BackendDeploymentType.Unknown),
@@ -768,7 +766,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
768766

769767
fun registerContainerEngine(containerPlatform: String) {
770768
postHog?.set(
771-
userId,
769+
UniqueGeneratedUserId.userId,
772770
mapOf("user.container-engine" to containerPlatform)
773771
)
774772
}
@@ -841,14 +839,14 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
841839
val isJcefSupported = JBCefApp.isSupported()
842840

843841
postHog?.set(
844-
userId,
842+
UniqueGeneratedUserId.userId,
845843
mapOf(
846844
"os.type" to osType,
847845
"ide.name" to ideName,
848846
"ide.version" to ideVersion,
849847
"ide.build" to ideBuildNumber,
850848
"plugin.version" to pluginVersion,
851-
"user.type" to if (isDevUser) "internal" else "external",
849+
"user.type" to if (UniqueGeneratedUserId.isDevUser) "internal" else "external",
852850
"jcef.supported" to isJcefSupported,
853851
INSTALL_STATUS_PROPERTY_NAME to getCurrentInstallStatus()
854852
)
@@ -887,7 +885,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
887885
)
888886

889887
postHog?.identify(
890-
userId,
888+
UniqueGeneratedUserId.userId,
891889
mapOf(
892890
LOAD_WARNING_APPEARED_PROPERTY_NAME + "_timestamp" to PersistenceService.getInstance().getLoadWarningAppearedTimestamp(),
893891
"user_requested_course" to "false"
@@ -919,7 +917,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
919917
registerUserAction(eventName, eventDetails)
920918

921919
postHog?.identify(
922-
userId,
920+
UniqueGeneratedUserId.userId,
923921
mapOf(
924922
ENVIRONMENT_ADDED_PROPERTY_NAME + "_timestamp" to PersistenceService.getInstance().getEnvironmentAddedTimestamp(),
925923
"user_requested_course" to "false"
@@ -951,7 +949,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
951949
)
952950

953951
postHog?.identify(
954-
userId,
952+
UniqueGeneratedUserId.userId,
955953
mapOf(
956954
JIRA_FIELD_COPIED_PROPERTY_NAME + "_timestamp" to PersistenceService.getInstance().getJiraFieldCopiedTimestamp(),
957955
"user_requested_course" to "false"

0 commit comments

Comments
 (0)