-
Notifications
You must be signed in to change notification settings - Fork 290
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
Target listing review comments #3848
Merged
johanbrandhorst
merged 5 commits into
llb-list-pagination
from
jbrandhorst-targets-review-comments
Oct 17, 2023
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ee38b0
refreshtoken: handle database buffer
johanbrandhorst ac4429f
internal/target: unexport ListTargets
johanbrandhorst fb6af37
internal/target: rename external test files
johanbrandhorst 19040be
internal/refreshtoken: remove Postgres timeout reference
johanbrandhorst c49473f
Reword buffer comment
johanbrandhorst 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 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 |
---|---|---|
|
@@ -17,6 +17,11 @@ import ( | |
"github.com/hashicorp/boundary/internal/types/resource" | ||
) | ||
|
||
// UpdatedTimeBuffer is used to automatically adjust the updated | ||
// time of a refresh token to account for delays between database | ||
// transactions. | ||
const UpdatedTimeBuffer = 30 * time.Second | ||
|
||
// A Token is returned in list endpoints for the purposes of pagination | ||
type Token struct { | ||
CreatedTime time.Time | ||
|
@@ -63,7 +68,7 @@ func New(ctx context.Context, createdTime time.Time, updatedTime time.Time, typ | |
}, nil | ||
} | ||
|
||
// FromResource creates a new refresh token from a resource and grants hash | ||
// FromResource creates a new refresh token from a resource and grants hash. | ||
func FromResource(res boundary.Resource, grantsHash []byte) *Token { | ||
t := time.Now() | ||
return &Token{ | ||
|
@@ -76,17 +81,26 @@ func FromResource(res boundary.Resource, grantsHash []byte) *Token { | |
} | ||
} | ||
|
||
// Refresh refreshes a token's updated time | ||
// Refresh refreshes a token's updated time. It accounts for database | ||
// transaction inaccuracies by subtracting UpdatedTimeBuffer from the | ||
// provided timestamp while ensuring that the updated time is never | ||
// before the created time of the token. | ||
func (rt *Token) Refresh(updatedTime time.Time) *Token { | ||
rt.UpdatedTime = updatedTime | ||
rt.UpdatedTime = updatedTime.Add(-UpdatedTimeBuffer) | ||
if rt.UpdatedTime.Before(rt.CreatedTime) { | ||
rt.UpdatedTime = rt.CreatedTime | ||
} | ||
return rt | ||
} | ||
|
||
// RefreshLastItem refreshes a token's updated time and last item | ||
// RefreshLastItem refreshes a token's updated time and last item. | ||
// It accounts for database transaction inaccuracies by subtracting | ||
// UpdatedTimeBuffer from the provided timestamp while ensuring that | ||
// the updated time is never before the created time of the token. | ||
func (rt *Token) RefreshLastItem(res boundary.Resource, updatedTime time.Time) *Token { | ||
rt.UpdatedTime = updatedTime | ||
rt.LastItemId = res.GetPublicId() | ||
rt.LastItemUpdatedTime = res.GetUpdateTime().AsTime() | ||
rt = rt.Refresh(updatedTime) | ||
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. Now that Refresh does more than a trivial amount of work, we call it from here instead of copying the logic |
||
return rt | ||
} | ||
|
||
|
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -7,4 +7,7 @@ package target | |
var ( | ||
AllocTargetView = allocTargetView | ||
TargetsViewDefaultTable = targetsViewDefaultTable | ||
ListDeletedIds = (*Repository).listDeletedIds | ||
EstimatedCount = (*Repository).estimatedCount | ||
ListTargets = (*Repository).listTargets | ||
Comment on lines
+10
to
+12
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. 👨🏻🍳 💋 |
||
) |
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
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 don't think "inaccuracies" is the right word here. It is the nature of a MVCC. There may have been items that have an older update time than
updatedTime
that where not visible at the timeupdatedTime
was returned.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.
Reworded this slightly, please take a look.