+ 25 // level 1
+ 47 // content of DaoModule
+ 3 // content of EsSearchModule
- + 58 // content of CorePropertyDefinitions
+ + 61 // content of CorePropertyDefinitions
);
assertThat(
picoContainer.getComponentAdapters().stream()
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;
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;
@Override
protected void configureModule() {
add(
- TelemetryProperties.class,
TelemetryDaemon.class,
TelemetryClient.class);
}
+++ /dev/null
-/*
- * 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";
-}
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;
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;
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 {
@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);
@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());
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();
@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());
@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();
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);
}
}
+++ /dev/null
-/*
- * 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.junit.Test;
-import org.sonar.api.config.Configuration;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.api.config.internal.MapSettings;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TelemetryPropertiesTest {
-
- Configuration underTest = new MapSettings(new PropertyDefinitions(TelemetryProperties.class)).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");
- }
-}
defs.addAll(PurgeProperties.all());
defs.addAll(EmailSettings.definitions());
defs.addAll(WebhookProperties.all());
+ defs.addAll(TelemetryProperties.all());
defs.addAll(ImmutableList.of(
PropertyDefinition.builder(PROP_PASSWORD)
--- /dev/null
+/*
+ * 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()
+ );
+
+ }
+}
@Test
public void all() {
List<PropertyDefinition> defs = CorePropertyDefinitions.all();
- assertThat(defs).hasSize(58);
+ assertThat(defs).hasSize(61);
}
@Test
--- /dev/null
+/*
+ * 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 org.junit.Test;
+import org.sonar.api.config.Configuration;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.internal.MapSettings;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TelemetryPropertiesTest {
+
+ private Configuration underTest = new MapSettings(new PropertyDefinitions(TelemetryProperties.all())).asConfig();
+
+ @Test
+ 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");
+ }
+}
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();
.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();