-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add last refresh times and unwritten changes state to RefreshStats #111220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
limotova
wants to merge
2
commits into
elastic:main
Choose a base branch
from
limotova:add-last-refreshed-time
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -34,6 +34,12 @@ public class RefreshStats implements Writeable, ToXContentFragment { | |
*/ | ||
private int listeners; | ||
|
||
private long lastRefreshTime; | ||
|
||
private long lastExternalRefreshTime; | ||
|
||
private boolean hasUnwrittenChanges; | ||
|
||
public RefreshStats() {} | ||
|
||
public RefreshStats(StreamInput in) throws IOException { | ||
|
@@ -44,6 +50,11 @@ public RefreshStats(StreamInput in) throws IOException { | |
externalTotalTimeInMillis = in.readVLong(); | ||
} | ||
listeners = in.readVInt(); | ||
if (in.getTransportVersion().onOrAfter(TransportVersions.LAST_REFRESH_TIME_STATS)) { | ||
lastRefreshTime = in.readVLong(); | ||
lastExternalRefreshTime = in.readVLong(); | ||
hasUnwrittenChanges = in.readBoolean(); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -55,14 +66,31 @@ public void writeTo(StreamOutput out) throws IOException { | |
out.writeVLong(externalTotalTimeInMillis); | ||
} | ||
out.writeVInt(listeners); | ||
if (out.getTransportVersion().onOrAfter(TransportVersions.LAST_REFRESH_TIME_STATS)) { | ||
out.writeVLong(lastRefreshTime); | ||
out.writeVLong(lastExternalRefreshTime); | ||
out.writeBoolean(hasUnwrittenChanges); | ||
} | ||
} | ||
|
||
public RefreshStats(long total, long totalTimeInMillis, long externalTotal, long externalTotalTimeInMillis, int listeners) { | ||
public RefreshStats( | ||
long total, | ||
long totalTimeInMillis, | ||
long externalTotal, | ||
long externalTotalTimeInMillis, | ||
int listeners, | ||
long lastRefreshTime, | ||
long lastExternalRefreshTime, | ||
boolean hasUnwrittenChanges | ||
) { | ||
this.total = total; | ||
this.totalTimeInMillis = totalTimeInMillis; | ||
this.externalTotal = externalTotal; | ||
this.externalTotalTimeInMillis = externalTotalTimeInMillis; | ||
this.listeners = listeners; | ||
this.lastRefreshTime = lastRefreshTime; | ||
this.lastExternalRefreshTime = lastExternalRefreshTime; | ||
this.hasUnwrittenChanges = hasUnwrittenChanges; | ||
} | ||
|
||
public void add(RefreshStats refreshStats) { | ||
|
@@ -78,6 +106,9 @@ public void addTotals(RefreshStats refreshStats) { | |
this.externalTotal += refreshStats.externalTotal; | ||
this.externalTotalTimeInMillis += refreshStats.externalTotalTimeInMillis; | ||
this.listeners += refreshStats.listeners; | ||
this.lastRefreshTime = Math.max(this.lastRefreshTime, refreshStats.lastRefreshTime); | ||
this.lastExternalRefreshTime = Math.max(this.lastExternalRefreshTime, refreshStats.lastExternalRefreshTime); | ||
this.hasUnwrittenChanges |= refreshStats.hasUnwrittenChanges; | ||
} | ||
|
||
/** | ||
|
@@ -129,6 +160,27 @@ public int getListeners() { | |
return listeners; | ||
} | ||
|
||
/** | ||
* Timestamp of the last refresh. | ||
*/ | ||
public long getLastRefreshTime() { | ||
return lastRefreshTime; | ||
} | ||
|
||
/** | ||
* Timestamp of the last external refresh. | ||
*/ | ||
public long getLastExternalRefreshTime() { | ||
return lastExternalRefreshTime; | ||
} | ||
|
||
/** | ||
* Whether there are changes that need to be written to disk or not. | ||
*/ | ||
public boolean getHasUnwrittenChanges() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went back and forth between |
||
return hasUnwrittenChanges; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject("refresh"); | ||
|
@@ -137,6 +189,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
builder.field("external_total", externalTotal); | ||
builder.humanReadableField("external_total_time_in_millis", "external_total_time", getExternalTotalTime()); | ||
builder.field("listeners", listeners); | ||
builder.field("last_refresh_timestamp", lastRefreshTime); | ||
builder.field("last_external_refresh_timestamp", lastExternalRefreshTime); | ||
builder.field("has_unwritten_changes", hasUnwrittenChanges); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
@@ -151,11 +206,23 @@ public boolean equals(Object obj) { | |
&& totalTimeInMillis == rhs.totalTimeInMillis | ||
&& externalTotal == rhs.externalTotal | ||
&& externalTotalTimeInMillis == rhs.externalTotalTimeInMillis | ||
&& listeners == rhs.listeners; | ||
&& listeners == rhs.listeners | ||
&& lastRefreshTime == rhs.lastRefreshTime | ||
&& lastExternalRefreshTime == rhs.lastExternalRefreshTime | ||
&& hasUnwrittenChanges == rhs.hasUnwrittenChanges; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(total, totalTimeInMillis, externalTotal, externalTotalTimeInMillis, listeners); | ||
return Objects.hash( | ||
total, | ||
totalTimeInMillis, | ||
externalTotal, | ||
externalTotalTimeInMillis, | ||
listeners, | ||
lastRefreshTime, | ||
lastExternalRefreshTime, | ||
hasUnwrittenChanges | ||
); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to make these values timestamps rather than a duration (like
timeSinceLastRefresh
) because from what I could tell timestamps are more widely used in the stats, but also because it was proving it be very difficult to write solid tests when the stat grows with time.