diff options
13 files changed, 99 insertions, 83 deletions
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 52c35f2b271..6d4f3e9514a 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -137,7 +137,7 @@ public class ComputeEngineContainerImplTest { + 25 // level 1 + 47 // content of DaoModule + 3 // content of EsSearchModule - + 58 // content of CorePropertyDefinitions + + 61 // content of CorePropertyDefinitions ); assertThat( picoContainer.getComponentAdapters().stream() diff --git a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryDaemon.java b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryDaemon.java index c303529b94e..7c5a6c2c89a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryDaemon.java +++ b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryDaemon.java @@ -37,15 +37,15 @@ import org.sonar.server.property.InternalProperties; import static org.sonar.api.utils.DateUtils.formatDate; import static org.sonar.api.utils.DateUtils.parseDate; -import static org.sonar.server.telemetry.TelemetryProperties.PROP_ENABLE; -import static org.sonar.server.telemetry.TelemetryProperties.PROP_URL; +import static org.sonar.core.config.TelemetryProperties.PROP_ENABLE; +import static org.sonar.core.config.TelemetryProperties.PROP_URL; @ServerSide public class TelemetryDaemon implements Startable { private static final String THREAD_NAME_PREFIX = "sq-telemetry-service-"; private static final int SEVEN_DAYS = 7 * 24 * 60 * 60 * 1_000; - private static final String I_PROP_LAST_PING = "sonar.telemetry.lastPing"; - private static final String I_PROP_OPT_OUT = "sonar.telemetry.optOut"; + static final String I_PROP_LAST_PING = "telemetry.lastPing"; + static final String I_PROP_OPT_OUT = "telemetry.optOut"; private static final Logger LOG = Loggers.get(TelemetryDaemon.class); private final TelemetryClient telemetryClient; diff --git a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryFrequency.java b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryFrequency.java index d2d11fe64d9..54b574c1c9d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryFrequency.java +++ b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryFrequency.java @@ -32,8 +32,8 @@ class TelemetryFrequency { long get() { if (frequency == null) { - frequency = config.getLong(TelemetryProperties.PROP_FREQUENCY) - .orElseThrow(() -> new IllegalStateException(String.format("Setting '%s' must be provided.", TelemetryProperties.PROP_FREQUENCY))); + frequency = config.getLong(org.sonar.core.config.TelemetryProperties.PROP_FREQUENCY) + .orElseThrow(() -> new IllegalStateException(String.format("Setting '%s' must be provided.", org.sonar.core.config.TelemetryProperties.PROP_FREQUENCY))); } return frequency; diff --git a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryModule.java b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryModule.java index 4f93a20ca3c..d9a576458dc 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryModule.java +++ b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryModule.java @@ -25,7 +25,6 @@ public class TelemetryModule extends Module { @Override protected void configureModule() { add( - TelemetryProperties.class, TelemetryDaemon.class, TelemetryClient.class); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryProperties.java b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryProperties.java deleted file mode 100644 index 90a5f437986..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryProperties.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.server.telemetry; - -import org.sonar.api.Properties; -import org.sonar.api.Property; - -@Properties({ - @Property( - key = TelemetryProperties.PROP_ENABLE, - defaultValue = "true", - name = "Share SonarQube statistics", - global = false), - @Property( - key = TelemetryProperties.PROP_FREQUENCY, - // 6 hours in seconds - defaultValue = "21600", - name = "Frequency of telemetry checks, in seconds", - global = false), - @Property( - key = TelemetryProperties.PROP_URL, - defaultValue = "https://telemetry.sonarsource.com/sonarqube", - name = "URL where telemetry data is sent", - global = false) -}) -public class TelemetryProperties { - static final String PROP_ENABLE = "sonar.telemetry.enable"; - static final String PROP_FREQUENCY = "sonar.telemetry.frequency"; - static final String PROP_URL = "sonar.telemetry.url"; -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryUrl.java b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryUrl.java index 70bf5d1244e..8e32b071170 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryUrl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryUrl.java @@ -22,7 +22,7 @@ package org.sonar.server.telemetry; import org.sonar.api.config.Configuration; -import static org.sonar.server.telemetry.TelemetryProperties.PROP_URL; +import static org.sonar.core.config.TelemetryProperties.PROP_URL; class TelemetryUrl { private final Configuration config; diff --git a/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java b/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java index 3d0d6643638..cb1aeb72ff1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.internal.TestSystem2; +import org.sonar.core.config.TelemetryProperties; import org.sonar.server.property.InternalProperties; import org.sonar.server.property.MapInternalProperties; @@ -36,6 +37,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.sonar.api.utils.DateUtils.parseDate; +import static org.sonar.core.config.TelemetryProperties.PROP_ENABLE; +import static org.sonar.core.config.TelemetryProperties.PROP_FREQUENCY; +import static org.sonar.server.telemetry.TelemetryDaemon.I_PROP_LAST_PING; public class TelemetryDaemonTest { @@ -52,7 +56,7 @@ public class TelemetryDaemonTest { @Before public void setUp() throws Exception { - settings = new MapSettings(new PropertyDefinitions(TelemetryProperties.class)); + settings = new MapSettings(new PropertyDefinitions(TelemetryProperties.all())); system2.setNow(System.currentTimeMillis()); underTest = new TelemetryDaemon(client, settings.asConfig(), internalProperties, server, system2); @@ -60,7 +64,7 @@ public class TelemetryDaemonTest { @Test public void send_data_via_client_at_startup_after_initial_delay() { - settings.setProperty("sonar.telemetry.frequency", "1"); + settings.setProperty(PROP_FREQUENCY, "1"); underTest.start(); verify(client, timeout(1_000).atLeastOnce()).send(anyString()); @@ -71,18 +75,18 @@ public class TelemetryDaemonTest { long now = system2.now(); long sixDaysAgo = now - (ONE_DAY * 6L); long sevenDaysAgo = now - (ONE_DAY * 7L); - internalProperties.write("sonar.telemetry.lastPing", String.valueOf(sixDaysAgo)); - settings.setProperty("sonar.telemetry.frequency", "1"); + internalProperties.write(I_PROP_LAST_PING, String.valueOf(sixDaysAgo)); + settings.setProperty(PROP_FREQUENCY, "1"); underTest.start(); verify(client, timeout(1_000).never()).send(anyString()); - internalProperties.write("sonar.telemetry.lastPing", String.valueOf(sevenDaysAgo)); + internalProperties.write(I_PROP_LAST_PING, String.valueOf(sevenDaysAgo)); verify(client, timeout(1_000).atLeastOnce()).send(anyString()); } @Test public void send_server_id() { - settings.setProperty("sonar.telemetry.frequency", "1"); + settings.setProperty(PROP_FREQUENCY, "1"); String id = randomAlphanumeric(40); server.setId(id); underTest.start(); @@ -92,11 +96,11 @@ public class TelemetryDaemonTest { @Test public void do_not_send_data_if_last_ping_earlier_than_one_week_ago() { - settings.setProperty("sonar.telemetry.frequency", "1"); + settings.setProperty(PROP_FREQUENCY, "1"); long now = system2.now(); long sixDaysAgo = now - (ONE_DAY * 6L); - internalProperties.write("sonar.telemetry.lastPing", String.valueOf(sixDaysAgo)); + internalProperties.write(I_PROP_LAST_PING, String.valueOf(sixDaysAgo)); underTest.start(); verify(client, timeout(2_000).never()).send(anyString()); @@ -104,23 +108,23 @@ public class TelemetryDaemonTest { @Test public void send_data_if_last_ping_is_one_week_ago() { - settings.setProperty("sonar.telemetry.frequency", "1"); + settings.setProperty(PROP_FREQUENCY, "1"); long today = parseDate("2017-08-01").getTime(); system2.setNow(today + 15 * ONE_HOUR); long now = system2.now(); long sevenDaysAgo = now - (ONE_DAY * 7L); - internalProperties.write("sonar.telemetry.lastPing", String.valueOf(sevenDaysAgo)); + internalProperties.write(I_PROP_LAST_PING, String.valueOf(sevenDaysAgo)); underTest.start(); verify(client, timeout(1_000).atLeastOnce()).send(anyString()); - assertThat(internalProperties.read("sonar.telemetry.lastPing").get()).isEqualTo(String.valueOf(today)); + assertThat(internalProperties.read(I_PROP_LAST_PING).get()).isEqualTo(String.valueOf(today)); } @Test public void opt_out_sent_once() { - settings.setProperty("sonar.telemetry.frequency", "1"); - settings.setProperty("sonar.telemetry.enable", "false"); + settings.setProperty(PROP_FREQUENCY, "1"); + settings.setProperty(PROP_ENABLE, "false"); underTest.start(); underTest.start(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryModuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryModuleTest.java index 57c07eb666f..7a3e7df1006 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryModuleTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryModuleTest.java @@ -29,6 +29,6 @@ public class TelemetryModuleTest { public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new TelemetryModule().configure(container); - assertThat(container.size()).isEqualTo(3 + 2); + assertThat(container.size()).isEqualTo(2 + 2); } } diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java index d1b3dbea6c9..66c270011c6 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java +++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java @@ -62,6 +62,7 @@ public class CorePropertyDefinitions { defs.addAll(PurgeProperties.all()); defs.addAll(EmailSettings.definitions()); defs.addAll(WebhookProperties.all()); + defs.addAll(TelemetryProperties.all()); defs.addAll(ImmutableList.of( PropertyDefinition.builder(PROP_PASSWORD) diff --git a/sonar-core/src/main/java/org/sonar/core/config/TelemetryProperties.java b/sonar-core/src/main/java/org/sonar/core/config/TelemetryProperties.java new file mode 100644 index 00000000000..7eaf0b44620 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/config/TelemetryProperties.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.config; + +import com.google.common.collect.ImmutableList; +import java.util.List; +import org.sonar.api.PropertyType; +import org.sonar.api.config.PropertyDefinition; + +public class TelemetryProperties { + + public static final String PROP_ENABLE = "sonar.telemetry.enable"; + public static final String PROP_FREQUENCY = "sonar.telemetry.frequencyInSeconds"; + public static final String PROP_URL = "sonar.telemetry.url"; + + private TelemetryProperties() { + // only static stuff + } + + public static List<PropertyDefinition> all() { + return ImmutableList.of( + PropertyDefinition.builder(PROP_ENABLE) + .defaultValue(Boolean.toString(true)) + .type(PropertyType.BOOLEAN) + .name("Share SonarQube statistics") + .description("By sharing anonymous SonarQube statistics, you help us understand how SonarQube is used so we can improve the plugin to work even better for you. " + + "We don't collect source code or IP addresses. And we don't share the data with anyone else.") + .hidden() + .build(), + PropertyDefinition.builder(PROP_FREQUENCY) + // 6 hours in seconds + .defaultValue("21600") + .type(PropertyType.INTEGER) + .name("Frequency of telemetry checks, in seconds") + .hidden() + .build(), + PropertyDefinition.builder(PROP_URL) + .defaultValue("https://telemetry.sonarsource.com/sonarqube") + .type(PropertyType.STRING) + .name("URL where telemetry data is sent") + .hidden() + .build() + ); + + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java index 50a3028672f..22b04b1f5e4 100644 --- a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java @@ -33,7 +33,7 @@ public class CorePropertyDefinitionsTest { @Test public void all() { List<PropertyDefinition> defs = CorePropertyDefinitions.all(); - assertThat(defs).hasSize(58); + assertThat(defs).hasSize(61); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryPropertiesTest.java b/sonar-core/src/test/java/org/sonar/core/config/TelemetryPropertiesTest.java index e3453ba7e47..f66919e8b6c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/telemetry/TelemetryPropertiesTest.java +++ b/sonar-core/src/test/java/org/sonar/core/config/TelemetryPropertiesTest.java @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.server.telemetry; +package org.sonar.core.config; import org.junit.Test; import org.sonar.api.config.Configuration; @@ -29,15 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat; public class TelemetryPropertiesTest { - Configuration underTest = new MapSettings(new PropertyDefinitions(TelemetryProperties.class)).asConfig(); + private Configuration underTest = new MapSettings(new PropertyDefinitions(TelemetryProperties.all())).asConfig(); @Test - public void default_frequency_is_6_hours_in_seconds() { - assertThat(underTest.getInt("sonar.telemetry.frequency")).contains(6 * 60 * 60); - } - - @Test - public void default_url_point_to_telemetry_server() { - assertThat(underTest.get("sonar.telemetry.url")).contains("https://telemetry.sonarsource.com/sonarqube"); + public void default_telemetry_properties() { + assertThat(underTest.getBoolean("sonar.telemetry.enable")).hasValue(true); + assertThat(underTest.getInt("sonar.telemetry.frequencyInSeconds")).hasValue(6 * 60 * 60); + assertThat(underTest.get("sonar.telemetry.url")).hasValue("https://telemetry.sonarsource.com/sonarqube"); } } diff --git a/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryTest.java b/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryTest.java index e65fb865180..0521010d90a 100644 --- a/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryTest.java +++ b/tests/src/test/java/org/sonarqube/tests/telemetry/TelemetryTest.java @@ -57,7 +57,7 @@ public class TelemetryTest { orchestrator = Orchestrator.builderEnv() .addPlugin(xooPlugin()) .setServerProperty("sonar.telemetry.url", url) - .setServerProperty("sonar.telemetry.frequency", "1") + .setServerProperty("sonar.telemetry.frequencyInSeconds", "1") .setServerProperty("sonar.core.id", serverId) .build(); orchestrator.start(); @@ -78,7 +78,7 @@ public class TelemetryTest { .addPlugin(xooPlugin()) .setServerProperty("sonar.telemetry.enable", "false") .setServerProperty("sonar.telemetry.url", url) - .setServerProperty("sonar.telemetry.frequency", "1") + .setServerProperty("sonar.telemetry.frequencyInSeconds", "1") .setServerProperty("sonar.core.id", serverId) .build(); orchestrator.start(); |