-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add cluster state update stats along with remote upload stats around success/ failure, latency metric Signed-off-by: Aman Khare <[email protected]>
- Loading branch information
Showing
18 changed files
with
511 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
server/src/main/java/org/opensearch/cluster/coordination/PersistedStateStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.coordination; | ||
|
||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* Persisted cluster state related stats. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class PersistedStateStats implements Writeable, ToXContentObject { | ||
private String statsName; | ||
private AtomicLong totalTimeInMillis = new AtomicLong(0); | ||
private AtomicLong failedCount = new AtomicLong(0); | ||
private AtomicLong successCount = new AtomicLong(0); | ||
private Map<String, AtomicLong> extendedFields = new HashMap<>(); // keeping minimal extensibility | ||
|
||
public PersistedStateStats(String statsName) { | ||
this.statsName = statsName; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVLong(successCount.get()); | ||
out.writeVLong(failedCount.get()); | ||
out.writeVLong(totalTimeInMillis.get()); | ||
if (extendedFields.size() > 0) { | ||
out.writeBoolean(true); | ||
out.writeVInt(extendedFields.size()); | ||
for (Map.Entry<String, AtomicLong> extendedField : extendedFields.entrySet()) { | ||
out.writeString(extendedField.getKey()); | ||
out.writeVLong(extendedField.getValue().get()); | ||
} | ||
} else { | ||
out.writeBoolean(false); | ||
} | ||
} | ||
|
||
public PersistedStateStats(StreamInput in) throws IOException { | ||
this.successCount = new AtomicLong(in.readVLong()); | ||
this.failedCount = new AtomicLong(in.readVLong()); | ||
this.totalTimeInMillis = new AtomicLong(in.readVLong()); | ||
if (in.readBoolean()) { | ||
int extendedFieldsSize = in.readVInt(); | ||
this.extendedFields = new HashMap<>(); | ||
for (int fieldNumber = 0; fieldNumber < extendedFieldsSize; fieldNumber++) { | ||
extendedFields.put(in.readString(), new AtomicLong(in.readVLong())); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(statsName); | ||
builder.field(Fields.SUCCESS_COUNT, getSuccessCount()); | ||
builder.field(Fields.FAILED_COUNT, getFailedCount()); | ||
builder.field(Fields.TOTAL_TIME_IN_MILLIS, getTotalTimeInMillis()); | ||
if (extendedFields.size() > 0) { | ||
for (Map.Entry<String, AtomicLong> extendedField : extendedFields.entrySet()) { | ||
builder.field(extendedField.getKey(), extendedField.getValue().get()); | ||
} | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public void stateFailed() { | ||
failedCount.incrementAndGet(); | ||
} | ||
|
||
public void stateSucceeded() { | ||
successCount.incrementAndGet(); | ||
} | ||
|
||
/** | ||
* Expects user to send time taken in milliseconds. | ||
* | ||
* @param timeTakenInUpload time taken in uploading the cluster state to remote | ||
*/ | ||
public void stateTook(long timeTakenInUpload) { | ||
totalTimeInMillis.addAndGet(timeTakenInUpload); | ||
} | ||
|
||
public long getTotalTimeInMillis() { | ||
return totalTimeInMillis.get(); | ||
} | ||
|
||
public long getFailedCount() { | ||
return failedCount.get(); | ||
} | ||
|
||
public long getSuccessCount() { | ||
return successCount.get(); | ||
} | ||
|
||
protected void addToExtendedFields(String extendedField, AtomicLong extendedFieldValue) { | ||
this.extendedFields.put(extendedField, extendedFieldValue); | ||
} | ||
|
||
/** | ||
* Fields for parsing and toXContent | ||
* | ||
* @opensearch.internal | ||
*/ | ||
static final class Fields { | ||
static final String SUCCESS_COUNT = "success_count"; | ||
static final String TOTAL_TIME_IN_MILLIS = "total_time_in_millis"; | ||
static final String FAILED_COUNT = "failed_count"; | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
server/src/main/java/org/opensearch/cluster/service/ClusterStateStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cluster.service; | ||
|
||
import org.opensearch.cluster.coordination.PersistedStateStats; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* Cluster state related stats. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class ClusterStateStats implements Writeable, ToXContentObject { | ||
|
||
private AtomicLong updateSuccess = new AtomicLong(0); | ||
private AtomicLong updateTotalTimeInMillis = new AtomicLong(0); | ||
private AtomicLong updateFailed = new AtomicLong(0); | ||
private List<PersistedStateStats> persistenceStats = new ArrayList<>(); | ||
|
||
public ClusterStateStats() {} | ||
|
||
public long getUpdateSuccess() { | ||
return updateSuccess.get(); | ||
} | ||
|
||
public long getUpdateTotalTimeInMillis() { | ||
return updateTotalTimeInMillis.get(); | ||
} | ||
|
||
public long getUpdateFailed() { | ||
return updateFailed.get(); | ||
} | ||
|
||
public List<PersistedStateStats> getPersistenceStats() { | ||
return persistenceStats; | ||
} | ||
|
||
public void stateUpdated() { | ||
updateSuccess.incrementAndGet(); | ||
} | ||
|
||
public void stateUpdateFailed() { | ||
updateFailed.incrementAndGet(); | ||
} | ||
|
||
public void stateUpdateTook(long stateUpdateTime) { | ||
updateTotalTimeInMillis.addAndGet(stateUpdateTime); | ||
} | ||
|
||
public ClusterStateStats setPersistenceStats(List<PersistedStateStats> persistenceStats) { | ||
this.persistenceStats = persistenceStats; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeVLong(updateSuccess.get()); | ||
out.writeVLong(updateTotalTimeInMillis.get()); | ||
out.writeVLong(updateFailed.get()); | ||
out.writeVInt(persistenceStats.size()); | ||
for (PersistedStateStats stats : persistenceStats) { | ||
stats.writeTo(out); | ||
} | ||
} | ||
|
||
public ClusterStateStats(StreamInput in) throws IOException { | ||
this.updateSuccess = new AtomicLong(in.readVLong()); | ||
this.updateTotalTimeInMillis = new AtomicLong(in.readVLong()); | ||
this.updateFailed = new AtomicLong(in.readVLong()); | ||
int persistedStatsSize = in.readVInt(); | ||
this.persistenceStats = new ArrayList<>(); | ||
for (int statsNumber = 0; statsNumber < persistedStatsSize; statsNumber++) { | ||
PersistedStateStats stats = new PersistedStateStats(in); | ||
this.persistenceStats.add(stats); | ||
} | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(Fields.CLUSTER_STATE_STATS); | ||
builder.startObject(Fields.OVERALL); | ||
builder.field(Fields.UPDATE_COUNT, getUpdateSuccess()); | ||
builder.field(Fields.TOTAL_TIME_IN_MILLIS, getUpdateTotalTimeInMillis()); | ||
builder.field(Fields.FAILED_COUNT, getUpdateFailed()); | ||
builder.endObject(); | ||
for (PersistedStateStats stats : persistenceStats) { | ||
stats.toXContent(builder, params); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
/** | ||
* Fields for parsing and toXContent | ||
* | ||
* @opensearch.internal | ||
*/ | ||
static final class Fields { | ||
static final String CLUSTER_STATE_STATS = "cluster_state_stats"; | ||
static final String OVERALL = "overall"; | ||
static final String UPDATE_COUNT = "update_count"; | ||
static final String TOTAL_TIME_IN_MILLIS = "total_time_in_millis"; | ||
static final String FAILED_COUNT = "failed_count"; | ||
} | ||
} |
Oops, something went wrong.