This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Add download entire period bundle feature #176
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,24 +68,42 @@ func (s *retrieveServlet) retrieve(w http.ResponseWriter, r *http.Request) resul | |
return s.fail(log(ctx, nil).WithField("method", r.Method), w, "method not allowed", "", http.StatusMethodNotAllowed) | ||
} | ||
|
||
dateNumber64, err := strconv.ParseUint(vars["day"], 10, 32) | ||
if err != nil { | ||
return s.fail(log(ctx, err), w, "invalid day parameter", "", http.StatusBadRequest) | ||
} | ||
dateNumber := uint32(dateNumber64) | ||
var startTimestamp time.Time | ||
var endTimestamp time.Time | ||
var dateNumber uint32 | ||
|
||
if config.AppConstants.EnableEntirePeriodBundle == true && vars["day"] == "00000" { | ||
|
||
endDate := timemath.CurrentDateNumber() - 1 | ||
startDate := endDate - numberOfDaysToServe | ||
|
||
dateNumber = endDate | ||
|
||
startTimestamp = time.Unix(int64(startDate*86400), 0) | ||
endTimestamp = time.Unix(int64((endDate+1)*86400), 0) | ||
|
||
startTimestamp := time.Unix(int64(dateNumber*86400), 0) | ||
endTimestamp := time.Unix(int64((dateNumber+1)*86400), 0) | ||
} else { | ||
|
||
dateNumber64, err := strconv.ParseUint(vars["day"], 10, 32) | ||
if err != nil { | ||
return s.fail(log(ctx, err), w, "invalid day parameter", "", http.StatusBadRequest) | ||
} | ||
dateNumber = uint32(dateNumber64) | ||
|
||
startTimestamp = time.Unix(int64(dateNumber*86400), 0) | ||
endTimestamp = time.Unix(int64((dateNumber+1)*86400), 0) | ||
|
||
} | ||
|
||
currentRSIN := pb.CurrentRollingStartIntervalNumber() | ||
currentDateNumber := timemath.CurrentDateNumber() | ||
|
||
if config.AppConstants.DisableCurrentDateCheckFeatureFlag == false && dateNumber == currentDateNumber { | ||
return s.fail(log(ctx, err), w, "request for current date", "cannot serve data for current period for privacy reasons", http.StatusNotFound) | ||
return s.fail(log(ctx, nil), w, "request for current date", "cannot serve data for current period for privacy reasons", http.StatusNotFound) | ||
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. Got it, we're checking it here, so we do need both to be true for it to work. 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. 👍 |
||
} else if dateNumber > currentDateNumber { | ||
return s.fail(log(ctx, err), w, "request for future data", "cannot request future data", http.StatusNotFound) | ||
return s.fail(log(ctx, nil), w, "request for future data", "cannot request future data", http.StatusNotFound) | ||
} else if dateNumber < (currentDateNumber - numberOfDaysToServe) { | ||
return s.fail(log(ctx, err), w, "request for too-old data", "requested data no longer valid", http.StatusGone) | ||
return s.fail(log(ctx, nil), w, "request for too-old data", "requested data no longer valid", http.StatusGone) | ||
} | ||
|
||
// TODO: Maybe implement multi-pack linked-list scheme depending on what we hear back from G/A | ||
|
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 |
---|---|---|
|
@@ -87,6 +87,50 @@ def test_retrieve_stuff | |
assert_keys(export, keys, region: 'CA', date_number: dn) | ||
end | ||
|
||
def test_all_keys | ||
active_at = time_in_date('10:00', today_utc.prev_day(8)) | ||
two_days_ago = yesterday_utc.prev_day(1) | ||
fourteen_days_ago = yesterday_utc.prev_day(13) | ||
fiveteen_days_ago = yesterday_utc.prev_day(14) | ||
|
||
# Our retrieve endpoint returns keys SUBMITTED within the given period. | ||
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. Should we check the bounds? Like 14 days ago and today as well? 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. Added! |
||
add_key(active_at: active_at, submitted_at: time_in_date("23:59:59", fiveteen_days_ago), data: '1' * 16) | ||
add_key(active_at: active_at, submitted_at: time_in_date("00:00", fourteen_days_ago), data: '2' * 16) | ||
add_key(active_at: active_at, submitted_at: time_in_date("01:59:59", yesterday_utc), data: '3' * 16) | ||
add_key(active_at: active_at, submitted_at: time_in_date("02:00", yesterday_utc), data: '4' * 16) | ||
add_key(active_at: active_at, submitted_at: time_in_date("02:00", yesterday_utc), data: '5' * 16) | ||
add_key(active_at: active_at, submitted_at: time_in_date("02:00", today_utc), data: '6' * 16) | ||
|
||
rsin = rolling_start_interval_number(active_at) | ||
|
||
resp = get_date("00000") | ||
|
||
config = get_app_config() | ||
|
||
if config["enableEntirePeriodBundle"] | ||
export = assert_happy_zip_response(resp) | ||
keys = [tek( | ||
rolling_start_interval_number: rsin, | ||
transmission_risk_level: 8, | ||
data: "2222222222222222", | ||
), tek( | ||
rolling_start_interval_number: rsin, | ||
transmission_risk_level: 8, | ||
data: "3333333333333333", | ||
), tek( | ||
rolling_start_interval_number: rsin, | ||
transmission_risk_level: 8, | ||
data: "4444444444444444", | ||
), tek( | ||
rolling_start_interval_number: rsin, | ||
transmission_risk_level: 8, | ||
data: "5555555555555555", | ||
)] | ||
else | ||
assert_response(resp, 410, 'text/plain; charset=utf-8', body: "requested data no longer valid\n") | ||
end | ||
end | ||
|
||
def test_period_bounds | ||
active_at = time_in_date('10:00', today_utc.prev_day(8)) | ||
two_days_ago = yesterday_utc.prev_day(1) | ||
|
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.
Maybe I'm reading this wrong, but it seems like we're doing "yesterday" on L77, then taking numberOfDaysToServe in the past, and then on L83 we're adding back the day we removed so we're back to "today"
This seems to imply that we're also serving today as part of the bundle, is there ever a use case where we'd want DisableCurrentDateCheckFeatureFlag to be false and EnableEntirePeriodBundle to be true? It seems like we're assuming that EnableEntirePeriodBundle means DisableCurrentDateCheckFeatureFlag is also true.
It's also entirely possible that my timeMath is just bad.
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.
endTimestamp is just the outer bound of the period, so you go up to the end days midnight. We need to ensure that yesterdays day is used in
startDate
anddateNumber
and that the correct endTimestamp is then calculated.