]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9802 rename section Search Statistics to Search Indexes
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 24 Sep 2017 20:05:31 +0000 (22:05 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 26 Sep 2017 21:49:38 +0000 (23:49 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsIndexesSection.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStatisticsSection.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/WebSystemInfoModule.java
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsStatisticsSectionTest.java [deleted file]

diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsIndexesSection.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsIndexesSection.java
new file mode 100644 (file)
index 0000000..d35f5d6
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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.platform.monitoring;
+
+import java.util.Map;
+import org.elasticsearch.ElasticsearchException;
+import org.elasticsearch.action.admin.indices.stats.IndexStats;
+import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
+import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.process.systeminfo.Global;
+import org.sonar.process.systeminfo.SystemInfoSection;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.es.EsClient;
+
+import static org.apache.commons.io.FileUtils.byteCountToDisplaySize;
+import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
+
+@ServerSide
+public class EsIndexesSection implements SystemInfoSection, Global {
+
+  private final EsClient esClient;
+
+  public EsIndexesSection(EsClient esClient) {
+    this.esClient = esClient;
+  }
+
+  @Override
+  public ProtobufSystemInfo.Section toProtobuf() {
+    ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
+    protobuf.setName("Search Indexes");
+    try {
+      completeIndexAttributes(protobuf);
+    } catch (Exception es) {
+      Loggers.get(EsIndexesSection.class).warn("Failed to retrieve ES attributes. There will be only a single \"Error\" attribute.", es);
+      setAttribute(protobuf, "Error", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage());
+    }
+    return protobuf.build();
+  }
+
+  private void completeIndexAttributes(ProtobufSystemInfo.Section.Builder protobuf) {
+    IndicesStatsResponse indicesStats = esClient.prepareStats().all().get();
+    for (Map.Entry<String, IndexStats> indexStats : indicesStats.getIndices().entrySet()) {
+      String prefix = "Index " + indexStats.getKey() + " - ";
+      setAttribute(protobuf, prefix + "Docs", indexStats.getValue().getPrimaries().getDocs().getCount());
+      setAttribute(protobuf, prefix + "Shards", indexStats.getValue().getShards().length);
+      setAttribute(protobuf, prefix + "Store Size", byteCountToDisplaySize(indexStats.getValue().getPrimaries().getStore().getSizeInBytes()));
+    }
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStatisticsSection.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStatisticsSection.java
deleted file mode 100644 (file)
index c317854..0000000
+++ /dev/null
@@ -1,67 +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.platform.monitoring;
-
-import java.util.Map;
-import org.elasticsearch.ElasticsearchException;
-import org.elasticsearch.action.admin.indices.stats.IndexStats;
-import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.process.systeminfo.Global;
-import org.sonar.process.systeminfo.SystemInfoSection;
-import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-import org.sonar.server.es.EsClient;
-
-import static org.apache.commons.io.FileUtils.byteCountToDisplaySize;
-import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
-
-@ServerSide
-public class EsStatisticsSection implements SystemInfoSection, Global {
-
-  private final EsClient esClient;
-
-  public EsStatisticsSection(EsClient esClient) {
-    this.esClient = esClient;
-  }
-
-  @Override
-  public ProtobufSystemInfo.Section toProtobuf() {
-    ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
-    protobuf.setName("Search Statistics");
-    try {
-      completeIndexAttributes(protobuf);
-    } catch (Exception es) {
-      Loggers.get(EsStatisticsSection.class).warn("Failed to retrieve ES attributes. There will be only a single \"Error\" attribute.", es);
-      setAttribute(protobuf, "Error", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage());
-    }
-    return protobuf.build();
-  }
-
-  private void completeIndexAttributes(ProtobufSystemInfo.Section.Builder protobuf) {
-    IndicesStatsResponse indicesStats = esClient.prepareStats().all().get();
-    for (Map.Entry<String, IndexStats> indexStats : indicesStats.getIndices().entrySet()) {
-      String prefix = "Index " + indexStats.getKey() + " - ";
-      setAttribute(protobuf, prefix + "Docs", indexStats.getValue().getPrimaries().getDocs().getCount());
-      setAttribute(protobuf, prefix + "Shards", indexStats.getValue().getShards().length);
-      setAttribute(protobuf, prefix + "Store Size", byteCountToDisplaySize(indexStats.getValue().getPrimaries().getStore().getSizeInBytes()));
-    }
-  }
-}
index 01dec926e3ab7ed278a6c73526207339408f365f..aae7dc5c087d2a2b1fe79cbf80eb71d5981e7660 100644 (file)
@@ -43,7 +43,7 @@ public class WebSystemInfoModule {
       new JvmStateSection("Web JVM State"),
       DatabaseSection.class,
       EsStateSection.class,
-      EsStatisticsSection.class,
+      EsIndexesSection.class,
       PluginsSection.class,
       SettingsSection.class,
       StandaloneSystemSection.class,
@@ -59,7 +59,7 @@ public class WebSystemInfoModule {
       new JvmPropertiesSection("Web JVM Properties"),
       new JvmStateSection("Web JVM State"),
       DatabaseSection.class,
-      EsStatisticsSection.class,
+      EsIndexesSection.class,
       GlobalSystemSection.class,
       LoggingSection.class,
       NodeSystemSection.class,
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java
new file mode 100644 (file)
index 0000000..eac9b66
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * 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.platform.monitoring;
+
+import org.elasticsearch.ElasticsearchException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.config.internal.MapSettings;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.es.EsClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.issue.index.IssueIndexDefinition;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
+import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
+
+public class EsIndexesSectionTest {
+
+  @Rule
+  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
+
+  private EsIndexesSection underTest = new EsIndexesSection(esTester.client());
+
+  @Test
+  public void name() {
+    assertThat(underTest.toProtobuf().getName()).isEqualTo("Search Indexes");
+  }
+
+  @Test
+  public void index_attributes() {
+    ProtobufSystemInfo.Section section = underTest.toProtobuf();
+
+    // one index "issues"
+    assertThat(attribute(section, "Index issues - Docs").getLongValue()).isEqualTo(0L);
+    assertThat(attribute(section, "Index issues - Shards").getLongValue()).isGreaterThan(0);
+    assertThat(attribute(section, "Index issues - Store Size").getStringValue()).isNotNull();
+  }
+
+  @Test
+  public void attributes_displays_exception_message_when_cause_null_when_client_fails() {
+    EsClient esClientMock = mock(EsClient.class);
+    EsIndexesSection underTest = new EsIndexesSection(esClientMock);
+    when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with no cause"));
+
+    ProtobufSystemInfo.Section section = underTest.toProtobuf();
+    assertThatAttributeIs(section, "Error", "RuntimeException with no cause");
+  }
+
+  @Test
+  public void attributes_displays_exception_message_when_cause_is_not_ElasticSearchException_when_client_fails() {
+    EsClient esClientMock = mock(EsClient.class);
+    EsIndexesSection underTest = new EsIndexesSection(esClientMock);
+    when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with cause not ES", new IllegalArgumentException("some cause message")));
+
+    ProtobufSystemInfo.Section section = underTest.toProtobuf();
+    assertThatAttributeIs(section, "Error", "RuntimeException with cause not ES");
+  }
+
+  @Test
+  public void attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails() {
+    EsClient esClientMock = mock(EsClient.class);
+    EsIndexesSection underTest = new EsIndexesSection(esClientMock);
+    when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with ES cause", new ElasticsearchException("some cause message")));
+
+    ProtobufSystemInfo.Section section = underTest.toProtobuf();
+    assertThatAttributeIs(section, "Error", "some cause message");
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsStatisticsSectionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsStatisticsSectionTest.java
deleted file mode 100644 (file)
index 44c583e..0000000
+++ /dev/null
@@ -1,88 +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.platform.monitoring;
-
-import org.elasticsearch.ElasticsearchException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.config.internal.MapSettings;
-import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-import org.sonar.server.es.EsClient;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.issue.index.IssueIndexDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
-import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
-
-public class EsStatisticsSectionTest {
-
-  @Rule
-  public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()));
-
-  private EsStatisticsSection underTest = new EsStatisticsSection(esTester.client());
-
-  @Test
-  public void name() {
-    assertThat(underTest.toProtobuf().getName()).isEqualTo("Search Statistics");
-  }
-
-  @Test
-  public void index_attributes() {
-    ProtobufSystemInfo.Section section = underTest.toProtobuf();
-
-    // one index "issues"
-    assertThat(attribute(section, "Index issues - Docs").getLongValue()).isEqualTo(0L);
-    assertThat(attribute(section, "Index issues - Shards").getLongValue()).isGreaterThan(0);
-    assertThat(attribute(section, "Index issues - Store Size").getStringValue()).isNotNull();
-  }
-
-  @Test
-  public void attributes_displays_exception_message_when_cause_null_when_client_fails() {
-    EsClient esClientMock = mock(EsClient.class);
-    EsStatisticsSection underTest = new EsStatisticsSection(esClientMock);
-    when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with no cause"));
-
-    ProtobufSystemInfo.Section section = underTest.toProtobuf();
-    assertThatAttributeIs(section, "Error", "RuntimeException with no cause");
-  }
-
-  @Test
-  public void attributes_displays_exception_message_when_cause_is_not_ElasticSearchException_when_client_fails() {
-    EsClient esClientMock = mock(EsClient.class);
-    EsStatisticsSection underTest = new EsStatisticsSection(esClientMock);
-    when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with cause not ES", new IllegalArgumentException("some cause message")));
-
-    ProtobufSystemInfo.Section section = underTest.toProtobuf();
-    assertThatAttributeIs(section, "Error", "RuntimeException with cause not ES");
-  }
-
-  @Test
-  public void attributes_displays_cause_message_when_cause_is_ElasticSearchException_when_client_fails() {
-    EsClient esClientMock = mock(EsClient.class);
-    EsStatisticsSection underTest = new EsStatisticsSection(esClientMock);
-    when(esClientMock.prepareStats()).thenThrow(new RuntimeException("RuntimeException with ES cause", new ElasticsearchException("some cause message")));
-
-    ProtobufSystemInfo.Section section = underTest.toProtobuf();
-    assertThatAttributeIs(section, "Error", "some cause message");
-  }
-}