Skip to content

Commit

Permalink
Additional refactoring based on PR review
Browse files Browse the repository at this point in the history
Signed-off-by: Bhumika Saini <[email protected]>
  • Loading branch information
Bhumika Saini committed Sep 6, 2023
1 parent c848c5b commit c633871
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static final class RoutingFields {
/**
* Fields for remote store stats response
*/
static final class UploadStatsFields {
public static final class UploadStatsFields {
/**
* Lag in terms of bytes b/w local and remote store
*/
Expand Down Expand Up @@ -294,12 +294,12 @@ static final class UploadStatsFields {
/**
* Count of files uploaded to remote store
*/
static final String TOTAL_UPLOADS = "total_uploads";
public static final String TOTAL_UPLOADS = "total_uploads";

/**
* Represents the total uploads to remote store in bytes
*/
static final String TOTAL_UPLOAD_SIZE = "total_upload_size";
public static final String TOTAL_UPLOAD_SIZE = "total_upload_size";

/**
* Total time spent on remote store uploads
Expand Down Expand Up @@ -367,17 +367,17 @@ static final class DownloadStatsFields {
/**
* Reusable sub fields for {@link UploadStatsFields} and {@link DownloadStatsFields}
*/
static final class SubFields {
static final String STARTED = "started";
static final String SUCCEEDED = "succeeded";
static final String FAILED = "failed";
public static final class SubFields {
public static final String STARTED = "started";
public static final String SUCCEEDED = "succeeded";
public static final String FAILED = "failed";

static final String STARTED_BYTES = "started_bytes";
static final String SUCCEEDED_BYTES = "succeeded_bytes";
static final String FAILED_BYTES = "failed_bytes";
public static final String STARTED_BYTES = "started_bytes";
public static final String SUCCEEDED_BYTES = "succeeded_bytes";
public static final String FAILED_BYTES = "failed_bytes";

static final String DOWNLOAD = "download";
static final String UPLOAD = "upload";
public static final String UPLOAD = "upload";

/**
* Moving avg over last N values stat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.index.translog;

import org.opensearch.action.admin.cluster.remotestore.stats.RemoteStoreStats;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
Expand Down Expand Up @@ -57,22 +58,6 @@ public class RemoteTranslogStats implements ToXContentFragment, Writeable {

static final String REMOTE_STORE = "remote_store";

static final String UPLOAD = "upload";

static final class SubFields {
static final String STARTED = "started";
static final String STARTED_BYTES = "started_bytes";
static final String FAILED = "failed";
static final String FAILED_BYTES = "failed_bytes";
static final String SUCCEEDED = "succeeded";
static final String SUCCEEDED_BYTES = "succeeded_bytes";
}

static final class Fields {
static final String TOTAL_UPLOADS = "total_uploads";
static final String TOTAL_UPLOAD_SIZE = "total_upload_size";
}

public RemoteTranslogStats() {}

public RemoteTranslogStats(StreamInput in) throws IOException {
Expand Down Expand Up @@ -133,7 +118,7 @@ public int hashCode() {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(REMOTE_STORE);

builder.startObject(UPLOAD);
builder.startObject(RemoteStoreStats.SubFields.UPLOAD);
addRemoteTranslogUploadStatsXContent(builder);
builder.endObject(); // translog.remote_store.upload

Expand Down Expand Up @@ -180,16 +165,28 @@ public void add(RemoteTranslogStats other) {
}

void addRemoteTranslogUploadStatsXContent(XContentBuilder builder) throws IOException {
builder.startObject(Fields.TOTAL_UPLOADS);
builder.field(SubFields.STARTED, totalUploadsStarted)
.field(SubFields.FAILED, totalUploadsFailed)
.field(SubFields.SUCCEEDED, totalUploadsSucceeded);
builder.startObject(RemoteStoreStats.UploadStatsFields.TOTAL_UPLOADS);
builder.field(RemoteStoreStats.SubFields.STARTED, totalUploadsStarted)
.field(RemoteStoreStats.SubFields.FAILED, totalUploadsFailed)
.field(RemoteStoreStats.SubFields.SUCCEEDED, totalUploadsSucceeded);
builder.endObject();

builder.startObject(Fields.TOTAL_UPLOAD_SIZE);
builder.humanReadableField(SubFields.STARTED_BYTES, SubFields.STARTED, new ByteSizeValue(uploadBytesStarted));
builder.humanReadableField(SubFields.FAILED_BYTES, SubFields.FAILED, new ByteSizeValue(uploadBytesFailed));
builder.humanReadableField(SubFields.SUCCEEDED_BYTES, SubFields.SUCCEEDED, new ByteSizeValue(uploadBytesSucceeded));
builder.startObject(RemoteStoreStats.UploadStatsFields.TOTAL_UPLOAD_SIZE);
builder.humanReadableField(
RemoteStoreStats.SubFields.STARTED_BYTES,
RemoteStoreStats.SubFields.STARTED,
new ByteSizeValue(uploadBytesStarted)
);
builder.humanReadableField(
RemoteStoreStats.SubFields.FAILED_BYTES,
RemoteStoreStats.SubFields.FAILED,
new ByteSizeValue(uploadBytesFailed)
);
builder.humanReadableField(
RemoteStoreStats.SubFields.SUCCEEDED_BYTES,
RemoteStoreStats.SubFields.SUCCEEDED,
new ByteSizeValue(uploadBytesSucceeded)
);
builder.endObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,19 @@ public void testStats() throws IOException {
builder.startObject();
copy.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
String expectedLocalTranslogStats = "{\"translog\":{\"operations\":4,\"size_in_bytes\":"
+ 326
+ ",\"uncommitted_operations\":4,\"uncommitted_size_in_bytes\":"
+ 271
+ ",\"earliest_last_modified_age\":"
+ stats.getEarliestLastModifiedAge();
String defaultRemoteStoreStats = ",\"remote_store\":{\"upload\":{"
+ "\"total_uploads\":{\"started\":0,\"failed\":0,\"succeeded\":0},"
+ "\"total_upload_size\":{\"started_bytes\":0,\"failed_bytes\":0,\"succeeded_bytes\":0}"
+ "}}";
assertEquals(expectedLocalTranslogStats + defaultRemoteStoreStats + "}}", builder.toString());
assertEquals(
"{\"translog\":{\"operations\":4,\"size_in_bytes\":"
+ 326
+ ",\"uncommitted_operations\":4,\"uncommitted_size_in_bytes\":"
+ 271
+ ",\"earliest_last_modified_age\":"
+ stats.getEarliestLastModifiedAge()
+ ",\"remote_store\":{\"upload\":{"
+ "\"total_uploads\":{\"started\":0,\"failed\":0,\"succeeded\":0},"
+ "\"total_upload_size\":{\"started_bytes\":0,\"failed_bytes\":0,\"succeeded_bytes\":0}"
+ "}}}}",
builder.toString()
);
}
}
translog.getDeletionPolicy().setLocalCheckpointOfSafeCommit(randomLongBetween(3, Long.MAX_VALUE));
Expand Down

0 comments on commit c633871

Please sign in to comment.