Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Thread Context Preservation by gRPC Interceptor ([#19776](https://github.com/opensearch-project/OpenSearch/pull/19776))
- Update NoOpResult constructors in the Engine to be public ([#19950](https://github.com/opensearch-project/OpenSearch/pull/19950))
- Refactor the TranslogStats and RequestCacheStats class to use the Builder pattern instead of constructors ([#19961](https://github.com/opensearch-project/OpenSearch/pull/19961))
- Refactor the IndexPressutreStats, DeviceStats and TransportStats class to use the Builder pattern instead of constructors ([#19991](https://github.com/opensearch-project/OpenSearch/pull/19991))

### Fixed
- Fix Allocation and Rebalance Constraints of WeightFunction are incorrectly reset ([#19012](https://github.com/opensearch-project/OpenSearch/pull/19012))
Expand Down Expand Up @@ -111,6 +112,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Deprecated existing constructors in GetStats, FlushStats and QueryCacheStats in favor of the new Builder ([#19935](https://github.com/opensearch-project/OpenSearch/pull/19935))
- Deprecated existing constructors in FieldDataStats and CompletionStats in favor of the new Builder ([#19936](https://github.com/opensearch-project/OpenSearch/pull/19936))
- Deprecated existing constructors in TranslogStats and RequestCacheStats in favor of the new Builder ([#19961](https://github.com/opensearch-project/OpenSearch/pull/19961))
- Deprecated existing constructors in IndexPressutreStats, DeviceStats and TransportStats in favor of the new Builder ([#19991](https://github.com/opensearch-project/OpenSearch/pull/19991))

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,13 @@ ShardIndexingPressureStats shardStats() {
IndexingPressurePerShardStats shardStats = new IndexingPressurePerShardStats(shardEntry.getValue(), isEnforcedMode);
statsPerShard.put(shardEntry.getKey(), shardStats);
}
return new ShardIndexingPressureStats(
statsPerShard,
memoryManager.getTotalNodeLimitsBreachedRejections(),
memoryManager.getTotalLastSuccessfulRequestLimitsBreachedRejections(),
memoryManager.getTotalThroughputDegradationLimitsBreachedRejections(),
shardIndexingPressureSettings.isShardIndexingPressureEnabled(),
isEnforcedMode
);
return new ShardIndexingPressureStats.Builder().shardIndexingPressureStore(statsPerShard)
.totalNodeLimitsBreachedRejections(memoryManager.getTotalNodeLimitsBreachedRejections())
.totalLastSuccessfulRequestLimitsBreachedRejections(memoryManager.getTotalLastSuccessfulRequestLimitsBreachedRejections())
.totalThroughputDegradationLimitsBreachedRejections(memoryManager.getTotalThroughputDegradationLimitsBreachedRejections())
.shardIndexingPressureEnabled(shardIndexingPressureSettings.isShardIndexingPressureEnabled())
.shardIndexingPressureEnforced(isEnforcedMode)
.build();
}

ShardIndexingPressureStats coldStats() {
Expand All @@ -419,25 +418,23 @@ ShardIndexingPressureStats coldStats() {
IndexingPressurePerShardStats shardStats = new IndexingPressurePerShardStats(shardEntry.getValue(), isEnforcedMode);
statsPerShard.put(shardEntry.getKey(), shardStats);
}
return new ShardIndexingPressureStats(
statsPerShard,
memoryManager.getTotalNodeLimitsBreachedRejections(),
memoryManager.getTotalLastSuccessfulRequestLimitsBreachedRejections(),
memoryManager.getTotalThroughputDegradationLimitsBreachedRejections(),
shardIndexingPressureSettings.isShardIndexingPressureEnabled(),
isEnforcedMode
);
return new ShardIndexingPressureStats.Builder().shardIndexingPressureStore(statsPerShard)
.totalNodeLimitsBreachedRejections(memoryManager.getTotalNodeLimitsBreachedRejections())
.totalLastSuccessfulRequestLimitsBreachedRejections(memoryManager.getTotalLastSuccessfulRequestLimitsBreachedRejections())
.totalThroughputDegradationLimitsBreachedRejections(memoryManager.getTotalThroughputDegradationLimitsBreachedRejections())
.shardIndexingPressureEnabled(shardIndexingPressureSettings.isShardIndexingPressureEnabled())
.shardIndexingPressureEnforced(isEnforcedMode)
.build();
}

ShardIndexingPressureStats topStats() {
return new ShardIndexingPressureStats(
Collections.emptyMap(),
memoryManager.getTotalNodeLimitsBreachedRejections(),
memoryManager.getTotalLastSuccessfulRequestLimitsBreachedRejections(),
memoryManager.getTotalThroughputDegradationLimitsBreachedRejections(),
shardIndexingPressureSettings.isShardIndexingPressureEnabled(),
shardIndexingPressureSettings.isShardIndexingPressureEnforced()
);
return new ShardIndexingPressureStats.Builder().shardIndexingPressureStore(Collections.emptyMap())
.totalNodeLimitsBreachedRejections(memoryManager.getTotalNodeLimitsBreachedRejections())
.totalLastSuccessfulRequestLimitsBreachedRejections(memoryManager.getTotalLastSuccessfulRequestLimitsBreachedRejections())
.totalThroughputDegradationLimitsBreachedRejections(memoryManager.getTotalThroughputDegradationLimitsBreachedRejections())
.shardIndexingPressureEnabled(shardIndexingPressureSettings.isShardIndexingPressureEnabled())
.shardIndexingPressureEnforced(shardIndexingPressureSettings.isShardIndexingPressureEnforced())
.build();
}

ShardIndexingPressureTracker getShardIndexingPressureTracker(ShardId shardId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ public class ShardIndexingPressureStats implements Writeable, ToXContentFragment
private final boolean shardIndexingPressureEnabled;
private final boolean shardIndexingPressureEnforced;

/**
* Private constructor that takes a builder.
* This is the sole entry point for creating a new ShardIndexingPressureStats object.
* @param builder The builder instance containing all the values.
*/
private ShardIndexingPressureStats(Builder builder) {
this.shardIndexingPressureStore = builder.shardIndexingPressureStore;
this.totalNodeLimitsBreachedRejections = builder.totalNodeLimitsBreachedRejections;
this.totalLastSuccessfulRequestLimitsBreachedRejections = builder.totalLastSuccessfulRequestLimitsBreachedRejections;
this.totalThroughputDegradationLimitsBreachedRejections = builder.totalThroughputDegradationLimitsBreachedRejections;
this.shardIndexingPressureEnabled = builder.shardIndexingPressureEnabled;
this.shardIndexingPressureEnforced = builder.shardIndexingPressureEnforced;
}

public ShardIndexingPressureStats(StreamInput in) throws IOException {
int shardEntries = in.readInt();
shardIndexingPressureStore = new HashMap<>();
Expand All @@ -51,6 +65,11 @@ public ShardIndexingPressureStats(StreamInput in) throws IOException {
shardIndexingPressureEnforced = in.readBoolean();
}

/**
* This constructor will be deprecated starting in version 3.4.0.
* Use {@link Builder} instead.
*/
@Deprecated
public ShardIndexingPressureStats(
Map<ShardId, IndexingPressurePerShardStats> shardIndexingPressureStore,
long totalNodeLimitsBreachedRejections,
Expand Down Expand Up @@ -85,6 +104,59 @@ public IndexingPressurePerShardStats getIndexingPressureShardStats(ShardId shard
return shardIndexingPressureStore.get(shardId);
}

/**
* Builder for the {@link ShardIndexingPressureStats} class.
* Provides a fluent API for constructing a ShardIndexingPressureStats object.
*/
public static class Builder {
private Map<ShardId, IndexingPressurePerShardStats> shardIndexingPressureStore = null;
private long totalNodeLimitsBreachedRejections = 0;
private long totalLastSuccessfulRequestLimitsBreachedRejections = 0;
private long totalThroughputDegradationLimitsBreachedRejections = 0;
private boolean shardIndexingPressureEnabled = false;
private boolean shardIndexingPressureEnforced = false;

public Builder() {}

public Builder shardIndexingPressureStore(Map<ShardId, IndexingPressurePerShardStats> shardIndexingPressureStore) {
this.shardIndexingPressureStore = shardIndexingPressureStore;
return this;
}

public Builder totalNodeLimitsBreachedRejections(long total) {
this.totalNodeLimitsBreachedRejections = total;
return this;
}

public Builder totalLastSuccessfulRequestLimitsBreachedRejections(long total) {
this.totalLastSuccessfulRequestLimitsBreachedRejections = total;
return this;
}

public Builder totalThroughputDegradationLimitsBreachedRejections(long total) {
this.totalThroughputDegradationLimitsBreachedRejections = total;
return this;
}

public Builder shardIndexingPressureEnabled(boolean enabled) {
this.shardIndexingPressureEnabled = enabled;
return this;
}

public Builder shardIndexingPressureEnforced(boolean enforced) {
this.shardIndexingPressureEnforced = enforced;
return this;
}

/**
* Creates a {@link ShardIndexingPressureStats} object from the builder's current state.
* @return A new ShardIndexingPressureStats instance.
*/
public ShardIndexingPressureStats build() {
return new ShardIndexingPressureStats(this);
}
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject("shard_indexing_pressure");
Expand Down
140 changes: 140 additions & 0 deletions server/src/main/java/org/opensearch/monitor/fs/FsInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,38 @@ public static class DeviceStats implements Writeable, ToXContentFragment {
final long currentIOTime;
final long previousIOTime;

/**
* Private constructor that takes a builder.
* This is the sole entry point for creating a new DeviceStats object.
* @param builder The builder instance containing all the values.
*/
private DeviceStats(Builder builder) {
this.majorDeviceNumber = builder.majorDeviceNumber;
this.minorDeviceNumber = builder.minorDeviceNumber;
this.deviceName = builder.deviceName;
this.currentReadsCompleted = builder.currentReadsCompleted;
this.previousReadsCompleted = builder.previousReadsCompleted;
this.currentSectorsRead = builder.currentSectorsRead;
this.previousSectorsRead = builder.previousSectorsRead;
this.currentWritesCompleted = builder.currentWritesCompleted;
this.previousWritesCompleted = builder.previousWritesCompleted;
this.currentSectorsWritten = builder.currentSectorsWritten;
this.previousSectorsWritten = builder.previousSectorsWritten;
this.currentReadTime = builder.currentReadTime;
this.previousReadTime = builder.previousReadTime;
this.currentWriteTime = builder.currentWriteTime;
this.previousWriteTime = builder.previousWriteTime;
this.currentQueueSize = builder.currentQueueSize;
this.previousQueueSize = builder.previousQueueSize;
this.currentIOTime = builder.currentIOTime;
this.previousIOTime = builder.previousIOTime;
}

/**
* This constructor will be deprecated starting in version 3.4.0.
* Use {@link Builder} instead.
*/
@Deprecated
public DeviceStats(
final int majorDeviceNumber,
final int minorDeviceNumber,
Expand Down Expand Up @@ -285,6 +317,11 @@ public DeviceStats(
);
}

/**
* This constructor will be deprecated starting in version 3.4.0.
* Use {@link Builder} instead.
*/
@Deprecated
private DeviceStats(
final int majorDeviceNumber,
final int minorDeviceNumber,
Expand Down Expand Up @@ -452,6 +489,109 @@ public String getDeviceName() {
return deviceName;
}

/**
* Builder for the {@link DeviceStats} class.
* Provides a fluent API for constructing a DeviceStats object.
*/
public static class Builder {
private int majorDeviceNumber = 0;
private int minorDeviceNumber = 0;
private String deviceName = "";
private long currentReadsCompleted = 0;
private long previousReadsCompleted = 0;
private long currentSectorsWritten = 0;
private long previousSectorsWritten = 0;
private long currentSectorsRead = 0;
private long previousSectorsRead = 0;
private long currentWritesCompleted = 0;
private long previousWritesCompleted = 0;
private long currentReadTime = 0;
private long previousReadTime = 0;
private long currentWriteTime = 0;
private long previousWriteTime = 0;
private long currentQueueSize = 0;
private long previousQueueSize = 0;
private long currentIOTime = 0;
private long previousIOTime = 0;

public Builder() {}

public Builder majorDeviceNumber(int number) {
this.majorDeviceNumber = number;
return this;
}

public Builder minorDeviceNumber(int number) {
this.minorDeviceNumber = number;
return this;
}

public Builder deviceName(String name) {
this.deviceName = name;
return this;
}

public Builder currentReadsCompleted(long completed) {
this.currentReadsCompleted = completed;
return this;
}

public Builder currentSectorsRead(long read) {
this.currentSectorsRead = read;
return this;
}

public Builder currentWritesCompleted(long completed) {
this.currentWritesCompleted = completed;
return this;
}

public Builder currentSectorsWritten(long written) {
this.currentSectorsWritten = written;
return this;
}

public Builder currentReadTime(long time) {
this.currentReadTime = time;
return this;
}

public Builder currentWriteTime(long time) {
this.currentWriteTime = time;
return this;
}

public Builder currentQueueSize(long size) {
this.currentQueueSize = size;
return this;
}

public Builder currentIOTime(long time) {
this.currentIOTime = time;
return this;
}

public Builder previousDeviceStats(DeviceStats deviceStats) {
this.previousReadsCompleted = (deviceStats != null) ? deviceStats.currentReadsCompleted : -1;
this.previousWritesCompleted = (deviceStats != null) ? deviceStats.currentWritesCompleted : -1;
this.previousSectorsRead = (deviceStats != null) ? deviceStats.currentSectorsRead : -1;
this.previousSectorsWritten = (deviceStats != null) ? deviceStats.currentSectorsWritten : -1;
this.previousReadTime = (deviceStats != null) ? deviceStats.currentReadTime : -1;
this.previousWriteTime = (deviceStats != null) ? deviceStats.currentWriteTime : -1;
this.previousQueueSize = (deviceStats != null) ? deviceStats.currentQueueSize : -1;
this.previousIOTime = (deviceStats != null) ? deviceStats.currentIOTime : -1;
return this;
}

/**
* Creates a {@link DeviceStats} object from the builder's current state.
* @return A new DeviceStats instance.
*/
public DeviceStats build() {
return new DeviceStats(this);
}
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("device_name", getDeviceName());
Expand Down
27 changes: 13 additions & 14 deletions server/src/main/java/org/opensearch/monitor/fs/FsProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,19 @@ final FsInfo.IoStats ioStats(final Set<Tuple<Integer, Integer>> devicesNumbers,
final long writeTime = Long.parseLong(fields[10]);
final long ioTime = fields.length > 12 ? Long.parseLong(fields[12]) : 0;
final long queueSize = fields.length > 13 ? Long.parseLong(fields[13]) : 0;
final FsInfo.DeviceStats deviceStats = new FsInfo.DeviceStats(
majorDeviceNumber,
minorDeviceNumber,
deviceName,
readsCompleted,
sectorsRead,
writesCompleted,
sectorsWritten,
readTime,
writeTime,
queueSize,
ioTime,
deviceMap.get(Tuple.tuple(majorDeviceNumber, minorDeviceNumber))
);
final FsInfo.DeviceStats deviceStats = new FsInfo.DeviceStats.Builder().majorDeviceNumber(majorDeviceNumber)
.minorDeviceNumber(minorDeviceNumber)
.deviceName(deviceName)
.currentReadsCompleted(readsCompleted)
.currentSectorsRead(sectorsRead)
.currentWritesCompleted(writesCompleted)
.currentSectorsWritten(sectorsWritten)
.currentReadTime(readTime)
.currentWriteTime(writeTime)
.currentQueueSize(queueSize)
.currentIOTime(ioTime)
.previousDeviceStats(deviceMap.get(Tuple.tuple(majorDeviceNumber, minorDeviceNumber)))
.build();
devicesStats.add(deviceStats);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,14 +970,13 @@ public final TransportStats getStats() {
final long messagesSent = statsTracker.getMessagesSent();
final long messagesReceived = statsTracker.getMessagesReceived();
final long bytesRead = statsTracker.getBytesRead();
return new TransportStats(
acceptedChannels.size(),
outboundConnectionCount.get(),
messagesReceived,
bytesRead,
messagesSent,
bytesWritten
);
return new TransportStats.Builder().serverOpen(acceptedChannels.size())
.totalOutboundConnections(outboundConnectionCount.get())
.rxCount(messagesReceived)
.rxSize(bytesRead)
.txCount(messagesSent)
.txSize(bytesWritten)
.build();
}

/**
Expand Down
Loading
Loading