diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-06-28 10:10:21 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-06-30 20:03:13 +0000 |
commit | 551db520fa153e6654e9d39bde8404aeae14f9d3 (patch) | |
tree | 80e870a75ec74fc490eebcdcbed32ca7f2839cd2 /server | |
parent | 2b1e236fa390e079bb4277b93b2dc9be25a77c5b (diff) | |
download | sonarqube-551db520fa153e6654e9d39bde8404aeae14f9d3.tar.gz sonarqube-551db520fa153e6654e9d39bde8404aeae14f9d3.zip |
SONAR-14917 Misleading memory amounts displayed in Administration > System
Diffstat (limited to 'server')
4 files changed, 21 insertions, 20 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStep.java index bd0302be14a..a3c1668554e 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ExtractReportStep.java @@ -24,7 +24,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Optional; -import org.apache.commons.io.FileUtils; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; import org.sonar.api.utils.ZipUtils; @@ -38,6 +37,8 @@ import org.sonar.db.DbSession; import org.sonar.db.ce.CeTaskInputDao; import org.sonar.process.FileUtils2; +import static org.sonar.core.util.FileUtils.humanReadableByteCountSI; + /** * Extracts the content zip file of the {@link CeTask} to a temp directory and adds a {@link File} * representing that temp directory to the {@link MutableBatchReportDirectoryHolder}. @@ -76,7 +77,7 @@ public class ExtractReportStep implements ComputationStep { // size is not added to context statistics because computation // can take time. It's enabled only if log level is DEBUG. try { - String dirSize = FileUtils.byteCountToDisplaySize(FileUtils2.sizeOf(unzippedDir.toPath())); + String dirSize = humanReadableByteCountSI(FileUtils2.sizeOf(unzippedDir.toPath())); LOGGER.debug("Analysis report is {} uncompressed", dirSize); } catch (IOException e) { LOGGER.warn("Fail to compute size of directory " + unzippedDir, e); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java index bf355f2d4f6..ba32960616a 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStep.java @@ -22,7 +22,6 @@ package org.sonar.ce.task.projectanalysis.step; import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.apache.commons.io.FileUtils; import org.sonar.api.utils.System2; import org.sonar.ce.task.projectanalysis.issue.ProtoIssueCache; import org.sonar.ce.task.projectanalysis.issue.RuleRepository; @@ -39,6 +38,7 @@ import org.sonar.db.issue.IssueDto; import org.sonar.db.issue.IssueMapper; import org.sonar.server.issue.IssueStorage; +import static org.sonar.core.util.FileUtils.humanReadableByteCountSI; import static org.sonar.core.util.stream.MoreCollectors.toList; import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; @@ -68,7 +68,7 @@ public class PersistIssuesStep implements ComputationStep { @Override public void execute(ComputationStep.Context context) { - context.getStatistics().add("cacheSize", FileUtils.byteCountToDisplaySize(protoIssueCache.fileSize())); + context.getStatistics().add("cacheSize", humanReadableByteCountSI(protoIssueCache.fileSize())); IssueStatistics statistics = new IssueStatistics(); try (DbSession dbSession = dbClient.openSession(true); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsIndexesSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsIndexesSection.java index ffc38bfc979..12d50d9c84c 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsIndexesSection.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsIndexesSection.java @@ -29,7 +29,7 @@ import org.sonar.server.es.EsClient; import org.sonar.server.es.response.IndexStats; import org.sonar.server.es.response.IndicesStatsResponse; -import static org.apache.commons.io.FileUtils.byteCountToDisplaySize; +import static org.sonar.core.util.FileUtils.humanReadableByteCountSI; import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute; @ServerSide @@ -60,7 +60,7 @@ public class EsIndexesSection implements SystemInfoSection, Global { String prefix = "Index " + indexStats.getName() + " - "; setAttribute(protobuf, prefix + "Docs", indexStats.getDocCount()); setAttribute(protobuf, prefix + "Shards", indexStats.getShardsCount()); - setAttribute(protobuf, prefix + "Store Size", byteCountToDisplaySize(indexStats.getStoreSizeBytes())); + setAttribute(protobuf, prefix + "Store Size", humanReadableByteCountSI(indexStats.getStoreSizeBytes())); } } } diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java index 1329bc940ed..d4f62864601 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/EsStateSection.java @@ -31,7 +31,7 @@ import org.sonar.server.es.response.NodeStats; import org.sonar.server.es.response.NodeStatsResponse; import static java.lang.String.format; -import static org.apache.commons.io.FileUtils.byteCountToDisplaySize; +import static org.sonar.core.util.FileUtils.humanReadableByteCountSI; import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute; public class EsStateSection implements SystemInfoSection { @@ -70,28 +70,28 @@ public class EsStateSection implements SystemInfoSection { public static void toProtobuf(NodeStats stats, ProtobufSystemInfo.Section.Builder protobuf) { setAttribute(protobuf, "CPU Usage (%)", stats.getCpuUsage()); - setAttribute(protobuf, "Disk Available", byteCountToDisplaySize(stats.getDiskAvailableBytes())); - setAttribute(protobuf, "Store Size", byteCountToDisplaySize(stats.getIndicesStats().getStoreSizeInBytes())); - setAttribute(protobuf, "Translog Size", byteCountToDisplaySize(stats.getIndicesStats().getTranslogSizeInBytes())); + setAttribute(protobuf, "Disk Available", humanReadableByteCountSI(stats.getDiskAvailableBytes())); + setAttribute(protobuf, "Store Size", humanReadableByteCountSI(stats.getIndicesStats().getStoreSizeInBytes())); + setAttribute(protobuf, "Translog Size", humanReadableByteCountSI(stats.getIndicesStats().getTranslogSizeInBytes())); setAttribute(protobuf, "Open File Descriptors", stats.getOpenFileDescriptors()); setAttribute(protobuf, "Max File Descriptors", stats.getMaxFileDescriptors()); setAttribute(protobuf, "JVM Heap Usage", formatPercent(stats.getJvmStats().getHeapUsedPercent())); - setAttribute(protobuf, "JVM Heap Used", byteCountToDisplaySize(stats.getJvmStats().getHeapUsedInBytes())); - setAttribute(protobuf, "JVM Heap Max", byteCountToDisplaySize(stats.getJvmStats().getHeapMaxInBytes())); - setAttribute(protobuf, "JVM Non Heap Used", byteCountToDisplaySize(stats.getJvmStats().getNonHeapUsedInBytes())); + setAttribute(protobuf, "JVM Heap Used", humanReadableByteCountSI(stats.getJvmStats().getHeapUsedInBytes())); + setAttribute(protobuf, "JVM Heap Max", humanReadableByteCountSI(stats.getJvmStats().getHeapMaxInBytes())); + setAttribute(protobuf, "JVM Non Heap Used", humanReadableByteCountSI(stats.getJvmStats().getNonHeapUsedInBytes())); setAttribute(protobuf, "JVM Threads", stats.getJvmStats().getThreadCount()); - setAttribute(protobuf, "Field Data Memory", byteCountToDisplaySize(stats.getIndicesStats().getFieldDataMemorySizeInBytes())); + setAttribute(protobuf, "Field Data Memory", humanReadableByteCountSI(stats.getIndicesStats().getFieldDataMemorySizeInBytes())); setAttribute(protobuf, "Field Data Circuit Breaker Limit", - byteCountToDisplaySize(stats.getFieldDataCircuitBreakerLimit())); + humanReadableByteCountSI(stats.getFieldDataCircuitBreakerLimit())); setAttribute(protobuf, "Field Data Circuit Breaker Estimation", - byteCountToDisplaySize(stats.getFieldDataCircuitBreakerEstimation())); + humanReadableByteCountSI(stats.getFieldDataCircuitBreakerEstimation())); setAttribute(protobuf, "Request Circuit Breaker Limit", - byteCountToDisplaySize(stats.getRequestCircuitBreakerLimit())); + humanReadableByteCountSI(stats.getRequestCircuitBreakerLimit())); setAttribute(protobuf, "Request Circuit Breaker Estimation", - byteCountToDisplaySize(stats.getRequestCircuitBreakerEstimation())); - setAttribute(protobuf, "Query Cache Memory", byteCountToDisplaySize(stats.getIndicesStats().getQueryCacheMemorySizeInBytes())); + humanReadableByteCountSI(stats.getRequestCircuitBreakerEstimation())); + setAttribute(protobuf, "Query Cache Memory", humanReadableByteCountSI(stats.getIndicesStats().getQueryCacheMemorySizeInBytes())); setAttribute(protobuf, "Request Cache Memory", - byteCountToDisplaySize(stats.getIndicesStats().getRequestCacheMemorySizeInBytes())); + humanReadableByteCountSI(stats.getIndicesStats().getRequestCacheMemorySizeInBytes())); } private static String formatPercent(long amount) { |