1313import org .elasticsearch .common .io .stream .StreamInput ;
1414import org .elasticsearch .common .io .stream .StreamOutput ;
1515import org .elasticsearch .common .io .stream .Writeable ;
16+ import org .elasticsearch .common .unit .ByteSizeValue ;
1617import org .elasticsearch .core .TimeValue ;
1718import org .elasticsearch .xcontent .ToXContentFragment ;
1819import org .elasticsearch .xcontent .ToXContentObject ;
2627
2728public class RepositoriesStats implements Writeable , ToXContentFragment {
2829
29- private final Map <String , ThrottlingStats > repositoryThrottlingStats ;
30+ private final Map <String , SnapshotStats > repositoryThrottlingStats ;
3031
3132 public RepositoriesStats (StreamInput in ) throws IOException {
3233 if (in .getTransportVersion ().onOrAfter (TransportVersions .V_8_9_X )) {
33- repositoryThrottlingStats = in .readMap (ThrottlingStats :: new );
34+ repositoryThrottlingStats = in .readMap (SnapshotStats :: readFrom );
3435 } else {
3536 repositoryThrottlingStats = new HashMap <>();
3637 }
3738 }
3839
39- public RepositoriesStats (Map <String , ThrottlingStats > repositoryThrottlingStats ) {
40+ public RepositoriesStats (Map <String , SnapshotStats > repositoryThrottlingStats ) {
4041 this .repositoryThrottlingStats = new HashMap <>(repositoryThrottlingStats );
4142 }
4243
@@ -53,14 +54,44 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
5354 return builder ;
5455 }
5556
56- public Map <String , ThrottlingStats > getRepositoryThrottlingStats () {
57+ public Map <String , SnapshotStats > getRepositoryThrottlingStats () {
5758 return Collections .unmodifiableMap (repositoryThrottlingStats );
5859 }
5960
60- public record ThrottlingStats (long totalReadThrottledNanos , long totalWriteThrottledNanos ) implements ToXContentObject , Writeable {
61+ public record SnapshotStats (
62+ long shardSnapshotsStarted ,
63+ long shardSnapshotsCompleted ,
64+ long shardSnapshotsInProgress ,
65+ long totalReadThrottledNanos ,
66+ long totalWriteThrottledNanos ,
67+ long numberOfBlobsUploaded ,
68+ long numberOfBytesUploaded ,
69+ long totalUploadTimeInNanos ,
70+ long totalUploadReadTimeInNanos
71+ ) implements ToXContentObject , Writeable {
6172
62- ThrottlingStats (StreamInput in ) throws IOException {
63- this (in .readVLong (), in .readVLong ());
73+ public static SnapshotStats readFrom (StreamInput in ) throws IOException {
74+ final long totalReadThrottledNanos = in .readVLong ();
75+ final long totalWriteThrottledNanos = in .readVLong ();
76+ if (in .getTransportVersion ().onOrAfter (TransportVersions .EXTENDED_SNAPSHOT_STATS_IN_NODE_INFO )) {
77+ return new SnapshotStats (
78+ in .readLong (),
79+ in .readLong (),
80+ in .readLong (),
81+ totalReadThrottledNanos ,
82+ totalWriteThrottledNanos ,
83+ in .readLong (),
84+ in .readLong (),
85+ in .readLong (),
86+ in .readLong ()
87+ );
88+ } else {
89+ return new SnapshotStats (totalReadThrottledNanos , totalWriteThrottledNanos );
90+ }
91+ }
92+
93+ public SnapshotStats (long totalReadThrottledNanos , long totalWriteThrottledNanos ) {
94+ this (-1 , -1 , -1 , totalReadThrottledNanos , totalWriteThrottledNanos , -1 , -1 , -1 , -1 );
6495 }
6596
6697 @ Override
@@ -72,6 +103,39 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
72103 }
73104 builder .field ("total_read_throttled_time_nanos" , totalReadThrottledNanos );
74105 builder .field ("total_write_throttled_time_nanos" , totalWriteThrottledNanos );
106+ if (shardSnapshotsStarted != -1 ) {
107+ builder .field ("shard_snapshots_started" , shardSnapshotsStarted );
108+ }
109+ if (shardSnapshotsCompleted != -1 ) {
110+ builder .field ("shard_snapshots_completed" , shardSnapshotsCompleted );
111+ }
112+ if (shardSnapshotsInProgress != -1 ) {
113+ builder .field ("shard_snapshots_in_progress" , shardSnapshotsInProgress );
114+ }
115+ if (numberOfBlobsUploaded != -1 ) {
116+ builder .field ("blobs_uploaded" , numberOfBlobsUploaded );
117+ }
118+ if (numberOfBytesUploaded != -1 ) {
119+ if (builder .humanReadable ()) {
120+ builder .field ("bytes_uploaded" , ByteSizeValue .ofBytes (numberOfBytesUploaded ));
121+ } else {
122+ builder .field ("bytes_uploaded" , numberOfBytesUploaded );
123+ }
124+ }
125+ if (totalUploadTimeInNanos != -1 ) {
126+ if (builder .humanReadable ()) {
127+ builder .field ("total_upload_time" , TimeValue .timeValueNanos (totalUploadTimeInNanos ));
128+ } else {
129+ builder .field ("total_upload_time_in_nanos" , totalUploadTimeInNanos );
130+ }
131+ }
132+ if (totalUploadReadTimeInNanos != -1 ) {
133+ if (builder .humanReadable ()) {
134+ builder .field ("total_read_time" , TimeValue .timeValueNanos (totalUploadReadTimeInNanos ));
135+ } else {
136+ builder .field ("total_read_time_in_nanos" , totalUploadReadTimeInNanos );
137+ }
138+ }
75139 builder .endObject ();
76140 return builder ;
77141 }
@@ -80,6 +144,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
80144 public void writeTo (StreamOutput out ) throws IOException {
81145 out .writeVLong (totalReadThrottledNanos );
82146 out .writeVLong (totalWriteThrottledNanos );
147+ if (out .getTransportVersion ().onOrAfter (TransportVersions .EXTENDED_SNAPSHOT_STATS_IN_NODE_INFO )) {
148+ out .writeLong (shardSnapshotsStarted );
149+ out .writeLong (shardSnapshotsCompleted );
150+ out .writeLong (shardSnapshotsInProgress );
151+ out .writeLong (numberOfBlobsUploaded );
152+ out .writeLong (numberOfBytesUploaded );
153+ out .writeLong (totalUploadTimeInNanos );
154+ out .writeLong (totalUploadReadTimeInNanos );
155+ }
83156 }
84157 }
85158}
0 commit comments