@@ -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() |
@@ -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; |
@@ -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; |
@@ -25,7 +25,6 @@ public class TelemetryModule extends Module { | |||
@Override | |||
protected void configureModule() { | |||
add( | |||
TelemetryProperties.class, | |||
TelemetryDaemon.class, | |||
TelemetryClient.class); | |||
} |
@@ -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"; | |||
} |
@@ -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; |
@@ -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(); | |||
@@ -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); | |||
} | |||
} |
@@ -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) |
@@ -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() | |||
); | |||
} | |||
} |
@@ -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 |
@@ -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"); | |||
} | |||
} |
@@ -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(); |