Skip to content

Commit 7bb748d

Browse files
authored
Remove sporadic min/max usage estimates from stats (#59755)
Today `GET _nodes/stats/fs` includes `{least,most}_usage_estimate` fields for some nodes. These fields have rather strange semantics. They are only reported on the elected master and on nodes that have been the elected master since they were last restarted; when a node stops being the elected master these stats remain in place but we stop updating them so they may become arbitrarily stale. This means that these statistics are pretty meaningless and impossible to use correctly. Even if they were kept up to date they're never reported for data-only nodes anyway, despite the fact that data nodes are the ones where we care most about disk usage. The information needed to compute the path with the least/most available space is already provided in the rest the stats output, so we can treat the inclusion of these stats as a bug and fix it by simply removing them in this commit. Since these stats were always optional and mostly omitted (for opaque reasons) this is not considered a breaking change.
1 parent 3615c42 commit 7bb748d

File tree

7 files changed

+22
-107
lines changed

7 files changed

+22
-107
lines changed

docs/reference/cluster/nodes-stats.asciidoc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,17 +1687,6 @@ less than `free_in_bytes`. This is the actual amount of free disk
16871687
space the {es} node can utilise.
16881688
=======
16891689
1690-
`least_usage_estimate`::
1691-
(object)
1692-
Contains statistics for the file store with the least estimated usage. See
1693-
<<cluster-nodes-stats-fs-data,`fs.data`>> for a list of child parameters.
1694-
1695-
1696-
`most_usage_estimate`::
1697-
(object)
1698-
Contains statistics for the file store with the most estimated usage. See
1699-
<<cluster-nodes-stats-fs-data,`fs.data`>> for a list of child parameters.
1700-
17011690
[[cluster-nodes-stats-fs-data]]
17021691
`data`::
17031692
(array of objects)
@@ -1713,9 +1702,6 @@ Path to the file store.
17131702
`mount`::
17141703
(string)
17151704
Mount point of the file store (ex: /dev/sda2).
1716-
+
1717-
NOTE: This parameter is not provided for the `least_usage_estimate` or
1718-
`most_usage_estimate` file stores.
17191705

17201706
`type`::
17211707
(string)

server/src/main/java/org/elasticsearch/monitor/MonitorService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.elasticsearch.monitor.os.OsService;
2929
import org.elasticsearch.monitor.process.ProcessService;
3030
import org.elasticsearch.threadpool.ThreadPool;
31-
import org.elasticsearch.cluster.ClusterInfoService;
3231

3332
import java.io.IOException;
3433

@@ -40,13 +39,12 @@ public class MonitorService extends AbstractLifecycleComponent {
4039
private final JvmService jvmService;
4140
private final FsService fsService;
4241

43-
public MonitorService(Settings settings, NodeEnvironment nodeEnvironment, ThreadPool threadPool,
44-
ClusterInfoService clusterInfoService) throws IOException {
42+
public MonitorService(Settings settings, NodeEnvironment nodeEnvironment, ThreadPool threadPool) throws IOException {
4543
this.jvmGcMonitorService = new JvmGcMonitorService(settings, threadPool);
4644
this.osService = new OsService(settings);
4745
this.processService = new ProcessService(settings);
4846
this.jvmService = new JvmService(settings);
49-
this.fsService = new FsService(settings, nodeEnvironment, clusterInfoService);
47+
this.fsService = new FsService(settings, nodeEnvironment);
5048
}
5149

5250
public OsService osService() {

server/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.monitor.fs;
2121

22+
import org.elasticsearch.Version;
2223
import org.elasticsearch.cluster.DiskUsage;
2324
import org.elasticsearch.common.Nullable;
2425
import org.elasticsearch.common.io.stream.StreamInput;
@@ -119,19 +120,6 @@ private long addLong(long current, long other) {
119120
return current + other;
120121
}
121122

122-
private double addDouble(double current, double other) {
123-
if (current == -1 && other == -1) {
124-
return 0;
125-
}
126-
if (other == -1) {
127-
return current;
128-
}
129-
if (current == -1) {
130-
return other;
131-
}
132-
return current + other;
133-
}
134-
135123
public void add(Path path) {
136124
total = FsProbe.adjustForHugeFilesystems(addLong(total, path.total));
137125
free = FsProbe.adjustForHugeFilesystems(addLong(free, path.free));
@@ -428,20 +416,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
428416
private final Path[] paths;
429417
private final IoStats ioStats;
430418
private final Path total;
431-
private final DiskUsage leastDiskEstimate;
432-
private final DiskUsage mostDiskEstimate;
433419

434420
public FsInfo(long timestamp, IoStats ioStats, Path[] paths) {
435-
this(timestamp, ioStats, paths, null, null);
436-
}
437-
438-
public FsInfo(long timestamp, IoStats ioStats, Path[] paths, @Nullable DiskUsage leastUsage, @Nullable DiskUsage mostUsage) {
439421
this.timestamp = timestamp;
440422
this.ioStats = ioStats;
441423
this.paths = paths;
442424
this.total = total();
443-
this.leastDiskEstimate = leastUsage;
444-
this.mostDiskEstimate = mostUsage;
445425
}
446426

447427
/**
@@ -455,8 +435,10 @@ public FsInfo(StreamInput in) throws IOException {
455435
paths[i] = new Path(in);
456436
}
457437
this.total = total();
458-
this.leastDiskEstimate = in.readOptionalWriteable(DiskUsage::new);
459-
this.mostDiskEstimate = in.readOptionalWriteable(DiskUsage::new);
438+
if (in.getVersion().before(Version.V_8_0_0)) {
439+
in.readOptionalWriteable(DiskUsage::new); // previously leastDiskEstimate
440+
in.readOptionalWriteable(DiskUsage::new); // previously mostDiskEstimate
441+
}
460442
}
461443

462444
@Override
@@ -467,24 +449,16 @@ public void writeTo(StreamOutput out) throws IOException {
467449
for (Path path : paths) {
468450
path.writeTo(out);
469451
}
470-
out.writeOptionalWriteable(this.leastDiskEstimate);
471-
out.writeOptionalWriteable(this.mostDiskEstimate);
452+
if (out.getVersion().before(Version.V_8_0_0)) {
453+
out.writeOptionalWriteable(null); // previously leastDiskEstimate
454+
out.writeOptionalWriteable(null); // previously mostDiskEstimate
455+
}
472456
}
473457

474458
public Path getTotal() {
475459
return total;
476460
}
477461

478-
@Nullable
479-
public DiskUsage getLeastDiskEstimate() {
480-
return this.leastDiskEstimate;
481-
}
482-
483-
@Nullable
484-
public DiskUsage getMostDiskEstimate() {
485-
return this.mostDiskEstimate;
486-
}
487-
488462
private Path total() {
489463
Path res = new Path();
490464
Set<String> seenDevices = new HashSet<>(paths.length);
@@ -518,28 +492,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
518492
builder.field(Fields.TIMESTAMP, timestamp);
519493
builder.field(Fields.TOTAL);
520494
total().toXContent(builder, params);
521-
if (leastDiskEstimate != null) {
522-
builder.startObject(Fields.LEAST_ESTIMATE);
523-
{
524-
builder.field(Fields.PATH, leastDiskEstimate.getPath());
525-
builder.humanReadableField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, new ByteSizeValue(leastDiskEstimate.getTotalBytes()));
526-
builder.humanReadableField(Fields.AVAILABLE_IN_BYTES, Fields.AVAILABLE,
527-
new ByteSizeValue(leastDiskEstimate.getFreeBytes()));
528-
builder.field(Fields.USAGE_PERCENTAGE, leastDiskEstimate.getUsedDiskAsPercentage());
529-
}
530-
builder.endObject();
531-
}
532495

533-
if (mostDiskEstimate != null) {
534-
builder.startObject(Fields.MOST_ESTIMATE);
535-
{
536-
builder.field(Fields.PATH, mostDiskEstimate.getPath());
537-
builder.humanReadableField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, new ByteSizeValue(mostDiskEstimate.getTotalBytes()));
538-
builder.humanReadableField(Fields.AVAILABLE_IN_BYTES, Fields.AVAILABLE, new ByteSizeValue(mostDiskEstimate.getFreeBytes()));
539-
builder.field(Fields.USAGE_PERCENTAGE, mostDiskEstimate.getUsedDiskAsPercentage());
540-
}
541-
builder.endObject();
542-
}
543496
builder.startArray(Fields.DATA);
544497
for (Path path : paths) {
545498
path.toXContent(builder, params);
@@ -559,13 +512,6 @@ static final class Fields {
559512
static final String TIMESTAMP = "timestamp";
560513
static final String DATA = "data";
561514
static final String TOTAL = "total";
562-
static final String TOTAL_IN_BYTES = "total_in_bytes";
563515
static final String IO_STATS = "io_stats";
564-
static final String LEAST_ESTIMATE = "least_usage_estimate";
565-
static final String MOST_ESTIMATE = "most_usage_estimate";
566-
static final String USAGE_PERCENTAGE = "used_disk_percent";
567-
static final String AVAILABLE = "available";
568-
static final String AVAILABLE_IN_BYTES = "available_in_bytes";
569-
static final String PATH = "path";
570516
}
571517
}

server/src/main/java/org/elasticsearch/monitor/fs/FsProbe.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
import org.apache.logging.log4j.Logger;
2424
import org.apache.logging.log4j.message.ParameterizedMessage;
2525
import org.apache.lucene.util.Constants;
26-
import org.elasticsearch.cluster.ClusterInfo;
27-
import org.elasticsearch.cluster.DiskUsage;
28-
import org.elasticsearch.common.Nullable;
2926
import org.elasticsearch.common.SuppressForbidden;
3027
import org.elasticsearch.common.collect.Tuple;
3128
import org.elasticsearch.common.io.PathUtils;
@@ -51,7 +48,7 @@ public FsProbe(NodeEnvironment nodeEnv) {
5148
this.nodeEnv = nodeEnv;
5249
}
5350

54-
public FsInfo stats(FsInfo previous, @Nullable ClusterInfo clusterInfo) throws IOException {
51+
public FsInfo stats(FsInfo previous) throws IOException {
5552
if (!nodeEnv.hasNodeFile()) {
5653
return new FsInfo(System.currentTimeMillis(), null, new FsInfo.Path[0]);
5754
}
@@ -70,13 +67,7 @@ public FsInfo stats(FsInfo previous, @Nullable ClusterInfo clusterInfo) throws I
7067
}
7168
ioStats = ioStats(devicesNumbers, previous);
7269
}
73-
DiskUsage leastDiskEstimate = null;
74-
DiskUsage mostDiskEstimate = null;
75-
if (clusterInfo != null) {
76-
leastDiskEstimate = clusterInfo.getNodeLeastAvailableDiskUsages().get(nodeEnv.nodeId());
77-
mostDiskEstimate = clusterInfo.getNodeMostAvailableDiskUsages().get(nodeEnv.nodeId());
78-
}
79-
return new FsInfo(System.currentTimeMillis(), ioStats, paths, leastDiskEstimate, mostDiskEstimate);
70+
return new FsInfo(System.currentTimeMillis(), ioStats, paths);
8071
}
8172

8273
final FsInfo.IoStats ioStats(final Set<Tuple<Integer, Integer>> devicesNumbers, final FsInfo previous) {

server/src/main/java/org/elasticsearch/monitor/fs/FsService.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@
2121

2222
import org.apache.logging.log4j.LogManager;
2323
import org.apache.logging.log4j.Logger;
24-
import org.elasticsearch.cluster.ClusterInfo;
25-
import org.elasticsearch.common.Nullable;
2624
import org.elasticsearch.common.settings.Setting;
2725
import org.elasticsearch.common.settings.Setting.Property;
2826
import org.elasticsearch.common.settings.Settings;
2927
import org.elasticsearch.common.unit.TimeValue;
3028
import org.elasticsearch.common.util.SingleObjectCache;
3129
import org.elasticsearch.env.NodeEnvironment;
32-
import org.elasticsearch.cluster.ClusterInfoService;
3330

3431
import java.io.IOException;
3532

@@ -38,9 +35,7 @@ public class FsService {
3835
private static final Logger logger = LogManager.getLogger(FsService.class);
3936

4037
private final FsProbe probe;
41-
private final TimeValue refreshInterval;
4238
private final SingleObjectCache<FsInfo> cache;
43-
private final ClusterInfoService clusterInfoService;
4439

4540
public static final Setting<TimeValue> REFRESH_INTERVAL_SETTING =
4641
Setting.timeSetting(
@@ -49,23 +44,22 @@ public class FsService {
4944
TimeValue.timeValueSeconds(1),
5045
Property.NodeScope);
5146

52-
public FsService(final Settings settings, final NodeEnvironment nodeEnvironment, ClusterInfoService clusterInfoService) {
47+
public FsService(final Settings settings, final NodeEnvironment nodeEnvironment) {
5348
this.probe = new FsProbe(nodeEnvironment);
54-
this.clusterInfoService = clusterInfoService;
55-
refreshInterval = REFRESH_INTERVAL_SETTING.get(settings);
49+
final TimeValue refreshInterval = REFRESH_INTERVAL_SETTING.get(settings);
5650
logger.debug("using refresh_interval [{}]", refreshInterval);
57-
cache = new FsInfoCache(refreshInterval, stats(probe, null, logger, null));
51+
cache = new FsInfoCache(refreshInterval, stats(probe, null));
5852
}
5953

6054
public FsInfo stats() {
6155
return cache.getOrRefresh();
6256
}
6357

64-
private static FsInfo stats(FsProbe probe, FsInfo initialValue, Logger logger, @Nullable ClusterInfo clusterInfo) {
58+
private static FsInfo stats(FsProbe probe, FsInfo initialValue) {
6559
try {
66-
return probe.stats(initialValue, clusterInfo);
60+
return probe.stats(initialValue);
6761
} catch (IOException e) {
68-
logger.debug("unexpected exception reading filesystem info", e);
62+
FsService.logger.debug("unexpected exception reading filesystem info", e);
6963
return null;
7064
}
7165
}
@@ -81,7 +75,7 @@ private class FsInfoCache extends SingleObjectCache<FsInfo> {
8175

8276
@Override
8377
protected FsInfo refresh() {
84-
return stats(probe, initialValue, logger, clusterInfoService.getClusterInfo());
78+
return stats(probe, initialValue);
8579
}
8680

8781
}

server/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ protected Node(final Environment initialEnvironment,
390390
final UsageService usageService = new UsageService();
391391

392392
ModulesBuilder modules = new ModulesBuilder();
393-
final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool, clusterInfoService);
393+
final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool);
394394
final FsHealthService fsHealthService = new FsHealthService(settings, clusterService.getClusterSettings(), threadPool,
395395
nodeEnvironment);
396396
ClusterModule clusterModule = new ClusterModule(settings, clusterService, clusterPlugins, clusterInfoService);

server/src/test/java/org/elasticsearch/monitor/fs/FsProbeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void testFsInfo() throws IOException {
5353
try (NodeEnvironment env = newNodeEnvironment()) {
5454
FsProbe probe = new FsProbe(env);
5555

56-
FsInfo stats = probe.stats(null, null);
56+
FsInfo stats = probe.stats(null);
5757
assertNotNull(stats);
5858
assertThat(stats.getTimestamp(), greaterThan(0L));
5959

0 commit comments

Comments
 (0)