Skip to content

Commit 9368134

Browse files
committed
SLCORE-1815 Use SQ:IDE key.
1 parent 7ad4a5d commit 9368134

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

API_CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Introduce a new `org.sonarsource.sonarlint.core.rpc.protocol.backend.labs.IdeLabsRpcService` service and a `joinIdeLabsProgram` method.
1414
* Use it to allow users to join the SonarQube for IDE Labs program
1515
* The method accepts user email and IDE name as parameters
16-
* Add a new `GESSIE_TELEMETRY` value in `org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.BackendCapability`. Clients using the feature need to declare it at initialization time.
16+
* Add a new `GESSIE_TELEMETRY` capability in `org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.BackendCapability`. Clients using the feature need to declare it at initialization time. Enables sending data to Gessie (Generic Event System) alongside previous telemetry implementation.
1717

1818
# 10.35
1919

backend/core/src/main/java/org/sonarsource/sonarlint/core/telemetry/gessie/GessieSpringConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@
3131
public class GessieSpringConfig {
3232

3333
public static final String PROPERTY_GESSIE_ENDPOINT = "sonarlint.internal.telemetry.gessie.endpoint";
34+
public static final String PROPERTY_GESSIE_API_KEY = "sonarlint.internal.telemetry.gessie.api.key";
3435
private static final String GESSIE_ENDPOINT = "https://events.sonardata.io";
36+
private static final String IDE_SOURCE = "CiiwpdWnR21rWEOkgJ8tr3EYSXb7dzaQ5ezbipLb";
3537

3638
@Bean
3739
String gessieEndpoint() {
3840
return System.getProperty(PROPERTY_GESSIE_ENDPOINT, GESSIE_ENDPOINT);
3941
}
42+
43+
@Bean
44+
String gessieApiKey() {
45+
return System.getProperty(PROPERTY_GESSIE_API_KEY, IDE_SOURCE);
46+
}
4047
}

backend/telemetry/src/main/java/org/sonarsource/sonarlint/core/telemetry/gessie/GessieHttpClient.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@
3434
public class GessieHttpClient {
3535

3636
private static final SonarLintLogger LOG = SonarLintLogger.get();
37-
private static final String X_API_KEY_IDE = "value";
3837

3938
private final Gson gson = configureGson();
4039
private final HttpClient client;
4140
private final String endpoint;
4241
@Value("${SONARLINT_TELEMETRY_LOG:false}")
4342
private boolean isTelemetryLogEnabled;
4443

45-
public GessieHttpClient(HttpClientProvider httpClientProvider, @Qualifier("gessieEndpoint") String gessieEndpoint) {
46-
this.client = httpClientProvider.getHttpClientWithXApiKeyAndRetries(X_API_KEY_IDE);
44+
public GessieHttpClient(HttpClientProvider httpClientProvider,
45+
@Qualifier("gessieEndpoint") String gessieEndpoint,
46+
@Qualifier("gessieApiKey") String gessieApiKey) {
47+
this.client = httpClientProvider.getHttpClientWithXApiKeyAndRetries(gessieApiKey);
4748
this.endpoint = gessieEndpoint;
4849
}
4950

@@ -56,8 +57,7 @@ public void postEvent(GessieEvent event) {
5657

5758
private void logGessiePayload(String json) {
5859
if (isTelemetryLogEnabled) {
59-
LOG.info("Sending Gessie payload.");
60-
LOG.info(json);
60+
LOG.info("Sending Gessie payload.\n{}", json);
6161
}
6262
}
6363

@@ -71,7 +71,8 @@ private static Gson configureGson() {
7171
private static void handleGessieResponse(CompletableFuture<HttpClient.Response> responseCompletableFuture) {
7272
responseCompletableFuture.thenAccept(response -> {
7373
if (!response.isSuccessful() && InternalDebug.isEnabled()) {
74-
LOG.error("Failed to upload telemetry to Gessie: {}", response);
74+
LOG.error("Failed to upload telemetry to Gessie: {} \n{}", response,
75+
response.bodyAsString());
7576
}
7677
}).exceptionally(exception -> {
7778
if (InternalDebug.isEnabled()) {

backend/telemetry/src/test/java/org/sonarsource/sonarlint/core/telemetry/gessie/GessieHttpClientTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class GessieHttpClientTests {
5858

5959
@BeforeEach
6060
void setUp() {
61-
tested = new GessieHttpClient(HttpClientProvider.forTesting(), mockGessie.baseUrl());
61+
tested = new GessieHttpClient(HttpClientProvider.forTesting(), mockGessie.baseUrl(), "value");
6262
}
6363

6464
@Test

its/tests/src/test/java/its/SonarQubeEnterpriseEditionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ void should_return_risk_dependency_details() {
431431

432432
assertThat(riskDetailsResponse)
433433
.usingRecursiveComparison()
434-
.isEqualTo(new GetDependencyRiskDetailsResponse(firstDependencyRiskKey, DependencyRiskDto.Severity.MEDIUM,
434+
.isEqualTo(new GetDependencyRiskDetailsResponse(firstDependencyRiskKey, DependencyRiskDto.Severity.LOW,
435435
DependencyRiskDto.SoftwareQuality.SECURITY, "com.fasterxml.woodstox:woodstox-core", "6.2.7",
436436
DependencyRiskDto.Type.VULNERABILITY, "CVE-2022-40152",
437437
"Those using Woodstox to parse XML data may be vulnerable to Denial of Service attacks (DOS) if DTD support is enabled. If the parser is running on user supplied input, an attacker may supply content that causes the parser to crash by stackoverflow. This effect may support a denial of service attack.",

medium-tests/src/test/java/mediumtest/gessie/GessieIntegrationMediumTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.junit.jupiter.api.extension.ExtendWith;
3535
import org.junit.jupiter.api.extension.RegisterExtension;
3636
import org.sonarsource.sonarlint.core.telemetry.InternalDebug;
37+
import org.sonarsource.sonarlint.core.telemetry.gessie.GessieSpringConfig;
3738
import org.sonarsource.sonarlint.core.test.utils.junit5.SonarLintTest;
3839
import org.sonarsource.sonarlint.core.test.utils.junit5.SonarLintTestHarness;
3940
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
@@ -53,7 +54,7 @@
5354
class GessieIntegrationMediumTests {
5455

5556
private static final String IDE_ENDPOINT = "/ide";
56-
public static final String FAILED_ONCE = "Failed once";
57+
private static final String FAILED_ONCE = "Failed once";
5758

5859
@SystemStub
5960
private EnvironmentVariables environmentVariables;
@@ -75,12 +76,14 @@ void setUp() {
7576
this.oldDebugValue = InternalDebug.isEnabled();
7677
InternalDebug.setEnabled(true);
7778
environmentVariables.set("SONARLINT_HTTP_RETRY_INTERVAL_SECONDS", "0");
79+
System.setProperty(GessieSpringConfig.PROPERTY_GESSIE_API_KEY, "value");
7880
}
7981

8082
@AfterEach
8183
void tearDown() {
8284
InternalDebug.setEnabled(oldDebugValue);
8385
environmentVariables.remove("SONARLINT_HTTP_RETRY_INTERVAL_SECONDS");
86+
System.clearProperty(GessieSpringConfig.PROPERTY_GESSIE_API_KEY);
8487
}
8588

8689
@SonarLintTest

0 commit comments

Comments
 (0)