Skip to content

Commit

Permalink
performance optimization for rules telemetry (#399)
Browse files Browse the repository at this point in the history
* performance optimization for rules telemetry
  • Loading branch information
kirill-knize-sonarsource authored Jul 1, 2021
1 parent 2228214 commit 8e5a8b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

Expand All @@ -45,7 +46,7 @@ class TelemetryLocalStorage {
private int showHotspotRequestsCount;
private int taintVulnerabilitiesInvestigatedLocallyCount;
private int taintVulnerabilitiesInvestigatedRemotelyCount;
private final Collection<String> raisedIssuesRules;
private final Set<String> raisedIssuesRules;

TelemetryLocalStorage() {
enabled = true;
Expand All @@ -59,8 +60,8 @@ public Collection<String> getRaisedIssuesRules() {
return raisedIssuesRules;
}

public void addReportedRule(String reportedRule) {
this.raisedIssuesRules.add(reportedRule);
public void addReportedRules(Set<String> reportedRuleKeys) {
this.raisedIssuesRules.addAll(reportedRuleKeys);
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.sonarsource.sonarlint.core.telemetry;

import java.nio.file.Path;
import java.util.Set;
import javax.annotation.Nullable;
import org.sonarsource.sonarlint.core.client.api.common.Language;

Expand Down Expand Up @@ -119,8 +120,8 @@ public void taintVulnerabilitiesInvestigatedRemotely() {
storage.tryUpdateAtomically(TelemetryLocalStorage::incrementTaintVulnerabilitiesInvestigatedRemotelyCount);
}

public void addReportedRule(String ruleKey) {
storage.tryUpdateAtomically(s -> s.addReportedRule(ruleKey));
public void addReportedRules(Set<String> ruleKeys) {
storage.tryUpdateAtomically(s -> s.addReportedRules(ruleKeys));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Optional;
import java.util.function.Consumer;
import org.junit.Before;
Expand Down Expand Up @@ -366,7 +368,7 @@ public void uploadLazily_should_clear_accumulated_data() {
manager.devNotificationsClicked(FOO_EVENT);
manager.taintVulnerabilitiesInvestigatedLocally();
manager.taintVulnerabilitiesInvestigatedRemotely();
manager.addReportedRule("ruleKey");
manager.addReportedRules(new HashSet<>(Arrays.asList("ruleKey1", "ruleKey2")));

manager.uploadLazily();

Expand All @@ -383,10 +385,11 @@ public void uploadLazily_should_clear_accumulated_data() {
public void accumulate_rules_activation_settings_and_reported_rules() {
createAndSaveSampleData(storage);

manager.addReportedRule("reportedRule1");
manager.addReportedRules(new HashSet<>(Arrays.asList("ruleKey1", "ruleKey1", "ruleKey2")));

TelemetryLocalStorage reloaded = storage.tryRead();
assertThat(reloaded.getRaisedIssuesRules()).containsOnly("reportedRule1");
assertThat(reloaded.getRaisedIssuesRules()).hasSize(2);
assertThat(reloaded.getRaisedIssuesRules()).contains("ruleKey1", "ruleKey2");
}

private void createAndSaveSampleData(TelemetryLocalStorageManager storage) {
Expand Down

0 comments on commit 8e5a8b1

Please sign in to comment.