Skip to content

Commit

Permalink
refactor: report telemetry when listing rels/charts (#650)
Browse files Browse the repository at this point in the history
* refactor: report telemetry when listing rels/charts

Signed-off-by: Andre Dietisheim <[email protected]>

* async send telemetry where makes sense

Signed-off-by: Andre Dietisheim <[email protected]>

---------

Signed-off-by: Andre Dietisheim <[email protected]>
  • Loading branch information
adietish authored Jan 11, 2024
1 parent 96e0fa4 commit dada6a8
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.jboss.tools.intellij.openshift.actions.ActionUtils.runWithProgress;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.PREFIX_ACTION;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.asyncSend;

public class RefreshAction extends StructureTreeAction {
public RefreshAction() {
Expand All @@ -45,10 +46,11 @@ public void doActionPerformed(ApplicationsRootNode root) {
}
runWithProgress((ProgressIndicator progress) -> {
root.refresh();
TelemetryService.instance().getBuilder()
.action(PREFIX_ACTION + "refresh cluster")
.success()
.send();
asyncSend(
TelemetryService.instance().getBuilder()
.action(PREFIX_ACTION + "refresh cluster")
.success()
);
},
"Refreshing...",
root.getProject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.FeedbackMessage;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.ui.feedback.FeedBackDialog;
import org.jetbrains.annotations.NotNull;

import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.asyncSend;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.instance;

public class FeedBackAction extends AnAction {

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
FeedbackMessage feedback = TelemetryService.instance().getBuilder().feedback("feedback");
FeedbackMessage feedback = instance().getBuilder().feedback("feedback");
FeedBackDialog dialog = new FeedBackDialog();
dialog.show();
if (dialog.isOK()) {
Expand All @@ -35,11 +37,10 @@ public void actionPerformed(@NotNull AnActionEvent e) {
.property("missing", dialog.getMissingFeature())
.property("best", dialog.getBestFeature())
.property("contact", dialog.getContact())
.success()
.send();
.success();
asyncSend(feedback);
} else {
feedback.aborted()
.send();
asyncSend(feedback.aborted());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

import java.util.regex.Pattern;

import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.asyncSend;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.instance;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.TelemetryResult;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.TelemetryResult.ERROR;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.VALUE_ABORTED;

Expand All @@ -29,11 +32,11 @@ public class TelemetrySender implements TelemetryHandler {
private final TelemetryMessageBuilder.ActionMessage telemetry;

public TelemetrySender(String actionName) {
telemetry = TelemetryService.instance().getBuilder().action(actionName);
telemetry = instance().getBuilder().action(actionName);
}

@Override
public void sendTelemetryResults(TelemetryService.TelemetryResult result) {
public void sendTelemetryResults(TelemetryResult result) {
switch (result) {
case SUCCESS:
telemetry.success();
Expand All @@ -45,7 +48,7 @@ public void sendTelemetryResults(TelemetryService.TelemetryResult result) {
default:
break;
}
telemetry.send();
asyncSend(telemetry);
}

public void sendTelemetryError(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
******************************************************************************/
package org.jboss.tools.intellij.openshift.telemetry;

import com.intellij.openapi.application.ApplicationManager;
import com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder;
import com.redhat.devtools.intellij.telemetry.core.util.Lazy;

import static com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage;
import static com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.FeedbackMessage;

public class TelemetryService {

public enum TelemetryResult {
Expand Down Expand Up @@ -61,4 +65,12 @@ public TelemetryMessageBuilder getBuilder(){
return instance.builder.get();
}

public static void asyncSend(ActionMessage message) {
ApplicationManager.getApplication().executeOnPooledThread(message::send);
}

public static void asyncSend(FeedbackMessage message) {
ApplicationManager.getApplication().executeOnPooledThread(message::send);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class InstallPanel extends JBPanel<InstallPanel> implements ChartPanel, Disposab
private final Disposable disposable = Disposer.newDisposable();

private final TelemetryMessageBuilder.ActionMessage telemetry =
TelemetryService.instance().getBuilder().action(TelemetryService.NAME_PREFIX_MISC + "install helm chart");
TelemetryService.instance().getBuilder().action(TelemetryService.PREFIX_ACTION + "install helm chart");

private ChartVersions chart;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.intellij.openapi.util.text.StringUtil;
import com.redhat.devtools.intellij.common.utils.ExecHelper;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.utils.Serialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -26,7 +27,9 @@
import java.util.Map;
import java.util.stream.Collectors;

import static com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage;
import static org.jboss.tools.intellij.openshift.Constants.HOME_FOLDER;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.asyncSend;

public class HelmCli implements Helm {

Expand All @@ -40,26 +43,53 @@ public HelmCli(String command) {

@Override
public String addRepo(String name, String url) throws IOException {
LOGGER.info("Adding repo " + name + " at " + url + ".");
return execute(command, Collections.emptyMap(), "repo", "add", name, url);
ActionMessage telemetry = TelemetryService.instance().getBuilder().action(
TelemetryService.NAME_PREFIX_MISC + "helm-add repo");
try {
LOGGER.info("Adding repo {} at {}.", name, url);
String result = execute(command, Collections.emptyMap(), "repo", "add", name, url);
asyncSend(telemetry.success());
return result;
} catch (IOException e) {
asyncSend(telemetry.error(e));
throw e;
}
}

@Override
public List<Chart> search() throws IOException {
LOGGER.info("Listing all charts.");
String charts = execute(command, Collections.emptyMap(), "search", "repo", "-l", "-o=json");
return Serialization.json().readValue(charts, new TypeReference<>(){});
ActionMessage telemetry = TelemetryService.instance().getBuilder().action(
TelemetryService.NAME_PREFIX_MISC + "helm-list charts");
try {
LOGGER.info("Listing all charts.");
String charts = execute(command, Collections.emptyMap(), "search", "repo", "-l", "-o=json");
asyncSend(telemetry.success());
return Serialization.json().readValue(charts, new TypeReference<>() {
});
} catch (IOException e) {
asyncSend(telemetry.error(e));
throw e;
}
}

@Override
public List<Chart> search(String regex) throws IOException {
LOGGER.info("Searching all charts that match " + regex + ".");
String charts = execute(command, Collections.emptyMap(), "search", "repo", "-r", regex, "-o=json");
return Serialization.json().readValue(charts, new TypeReference<>(){});
ActionMessage telemetry = TelemetryService.instance().getBuilder().action(
TelemetryService.NAME_PREFIX_MISC + "helm-search charts");
try {
LOGGER.info("Searching all charts that match {}.", regex);
String charts = execute(command, Collections.emptyMap(), "search", "repo", "-r", regex, "-o=json");
asyncSend(telemetry.success());
return Serialization.json().readValue(charts, new TypeReference<>() {});
} catch (IOException e) {
asyncSend(telemetry.error(e));
throw e;
}
}

@Override
public String install(String name, String chart, String version, String additionalArguments) throws IOException {
// telemetry sent in ChartsDialog
List<String> arguments = new ArrayList<>();
arguments.add("install");
arguments.add(name);
Expand All @@ -69,19 +99,28 @@ public String install(String name, String chart, String version, String addition
if (!StringUtil.isEmptyOrSpaces(additionalArguments)) {
arguments.addAll(Arrays.stream(additionalArguments.split(" ")).collect(Collectors.toList()));
}
LOGGER.info("Installing chart " + chart + " in version " + version + ".");
LOGGER.info("Installing chart {} in version {}.", chart, version);
return execute(command, Collections.emptyMap(), arguments.toArray(new String[arguments.size()]));
}

@Override
public List<ChartRelease> list() throws IOException {
LOGGER.info("listing all releases.");
String charts = execute(command, Collections.emptyMap(), "list", "-o=json");
return Serialization.json().readValue(charts, new TypeReference<>(){});
ActionMessage telemetry = TelemetryService.instance().getBuilder().action(
TelemetryService.NAME_PREFIX_MISC + "helm-list releases");
try {
LOGGER.info("listing all releases.");
String charts = execute(command, Collections.emptyMap(), "list", "-o=json");
asyncSend(telemetry.success());
return Serialization.json().readValue(charts, new TypeReference<>() {});
} catch (IOException e) {
asyncSend(telemetry.error(e));
throw e;
}
}

@Override
public String uninstall(String name) throws IOException {
// telemetry sent in UninstallReleaseAction
return execute(command, Collections.emptyMap(), "uninstall", name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.jboss.tools.intellij.openshift.KubernetesLabels;
import org.jboss.tools.intellij.openshift.telemetry.TelemetryService;
import org.jboss.tools.intellij.openshift.utils.Serialization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -103,7 +102,10 @@
import static org.jboss.tools.intellij.openshift.Constants.PLUGIN_FOLDER;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.IS_OPENSHIFT;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.KUBERNETES_VERSION;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.NAME_PREFIX_MISC;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.OPENSHIFT_VERSION;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.asyncSend;
import static org.jboss.tools.intellij.openshift.telemetry.TelemetryService.instance;

public class OdoCli implements Odo {

Expand Down Expand Up @@ -192,25 +194,16 @@ private void computeTelemetrySettings() {
}

private void reportTelemetry() {
TelemetryMessageBuilder.ActionMessage telemetry = TelemetryService.instance().getBuilder().action(TelemetryService.NAME_PREFIX_MISC + "login");
TelemetryMessageBuilder.ActionMessage telemetry = instance().getBuilder().action(NAME_PREFIX_MISC + "login");
try {
ClusterInfo info = ClusterHelper.getClusterInfo(client);
telemetry.property(KUBERNETES_VERSION, info.getKubernetesVersion());
telemetry.property(IS_OPENSHIFT, Boolean.toString(info.isOpenshift()));
telemetry.property(OPENSHIFT_VERSION, info.getOpenshiftVersion());
telemetry.send();
asyncSend(telemetry);
} catch (RuntimeException e) {
// do not send telemetry when there is no context ( ie default kube URL as master URL )
try {
//workaround to not send null values
if (e.getMessage() != null) {
telemetry.error(e).send();
} else {
telemetry.error(e.toString()).send();
}
} catch (RuntimeException ex) {
LOGGER.warn(ex.getLocalizedMessage(), ex);
}
asyncSend(telemetry.error(e));
}
}

Expand Down

0 comments on commit dada6a8

Please sign in to comment.