Skip to content

Commit

Permalink
Use milliseconds since unix epoch for report_time/replace_time in the
Browse files Browse the repository at this point in the history
simulator output

Bug: 1318118
Change-Id: I6bdf9c56885d59b70f4a6c5478b211706c276576
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3621684
Commit-Queue: Nan Lin <linnan@chromium.org>
Reviewed-by: Andrew Paseltiner <apaseltiner@chromium.org>
Cr-Commit-Position: refs/heads/main@{#998884}
  • Loading branch information
linnan-github authored and Chromium LUCI CQ committed May 3, 2022
1 parent e838686 commit c8abc6e
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 42 deletions.
6 changes: 3 additions & 3 deletions content/public/test/attribution_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Value;
namespace content {

enum class AttributionReportTimeFormat {
// Times are an integer number of seconds since the Unix epoch.
kSecondsSinceUnixEpoch,
// Times are an integer number of milliseconds since the Unix epoch.
kMillisecondsSinceUnixEpoch,
// Times are strings in the ISO 8601 format.
kISO8601,
};
Expand Down Expand Up @@ -47,7 +47,7 @@ struct AttributionSimulationOptions {
bool remove_report_ids = false;

AttributionReportTimeFormat report_time_format =
AttributionReportTimeFormat::kSecondsSinceUnixEpoch;
AttributionReportTimeFormat::kMillisecondsSinceUnixEpoch;

// If true, removes the `shared_info`, `aggregation_service_payloads` and
// `source_registration_time` fields from aggregatable reports before output.
Expand Down
5 changes: 3 additions & 2 deletions content/test/attribution_simulator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
Expand Down Expand Up @@ -137,8 +138,8 @@ struct AttributionReportJsonConverter {

base::TimeDelta time_delta = base::Time::Now() - time_origin;
switch (report_time_format) {
case AttributionReportTimeFormat::kSecondsSinceUnixEpoch:
value.Set(time_key, base::checked_cast<int>(time_delta.InSeconds()));
case AttributionReportTimeFormat::kMillisecondsSinceUnixEpoch:
value.Set(time_key, base::NumberToString(time_delta.InMilliseconds()));
break;
case AttributionReportTimeFormat::kISO8601:
value.Set(time_key,
Expand Down
7 changes: 4 additions & 3 deletions content/test/attribution_simulator_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ void ParseOptions(const base::Value& dict,
if (*report_time_format == "iso8601") {
options.report_time_format = AttributionReportTimeFormat::kISO8601;
} else {
ASSERT_EQ(*report_time_format, "seconds_since_unix_epoch")
ASSERT_EQ(*report_time_format, "milliseconds_since_unix_epoch")
<< "unknown report time format: " << *report_time_format;
options.report_time_format =
AttributionReportTimeFormat::kSecondsSinceUnixEpoch;
AttributionReportTimeFormat::kMillisecondsSinceUnixEpoch;
}
}

Expand All @@ -123,7 +123,8 @@ TEST_P(AttributionSimulatorImplTest, HasExpectedOutput) {
.noise_mode = AttributionNoiseMode::kNone,
.delay_mode = AttributionDelayMode::kDefault,
.remove_report_ids = true,
.report_time_format = AttributionReportTimeFormat::kSecondsSinceUnixEpoch,
.report_time_format =
AttributionReportTimeFormat::kMillisecondsSinceUnixEpoch,
.remove_assembled_report = true,
};

Expand Down
21 changes: 11 additions & 10 deletions content/test/data/attribution_reporting/simulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ JSON schema for the input of the simulator.

JSON schema for the output of the simulator.

```json
```jsonc
{
// List of zero or more event-level reports.
// List of event-level reports. Omitted if empty.
"event_level_reports": [
{
// Time at which the report would have been sent in seconds since the
// UNIX epoch.
"report_time": 123,
// Time at which the report would have been sent in milliseconds since
// the UNIX epoch formatted as a base-10 string.
"report_time": "123",

// URL to which the report would have been sent.
"report_url": "https://reporting.example/.well-known/attribution-reporting/report-event-attribution",
Expand All @@ -220,9 +220,9 @@ JSON schema for the output of the simulator.
// List of aggregatable reports. Omitted if empty.
"aggregatable_reports": [
{
// Time at which the report would have been sent in seconds since the
// UNIX epoch.
"report_time": 123,
// Time at which the report would have been sent in milliseconds since
// the UNIX epoch formatted as a base-10 string.
"report_time": "123",

// URL to which the report would have been sent.
"report_url": "https://reporting.example/.well-known/attribution-reporting/report-aggregate-attribution",
Expand Down Expand Up @@ -276,8 +276,9 @@ JSON schema for the output of the simulator.
// These reports were never sent, but were replaced by higher-priority ones.
"replaced_event_level_reports": [
{
// Time at which the report was replaced in seconds since the UNIX epoch.
"replacement_time": 123,
// Time at which the report was replaced in milliseconds since the UNIX
// epoch formatted as a base-10 string.
"replacement_time": "123",

// The report id that the report was replaced by. Omitted if
// `remove_report_ids` option is true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source_type": "navigation",
"trigger_data": "7"
},
"report_time": 1643408373,
"report_time": "1643408373123",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"attribution_destination": "https://d.test",
"source_site": "https://s.test"
},
"report_time": 1643239174,
"report_time": "1643239174123",
"report_url": "https://r.test/.well-known/attribution-reporting/report-aggregate-attribution",
"test_info": {
"histograms": [
Expand All @@ -26,7 +26,7 @@
"source_type": "navigation",
"trigger_data": "7"
},
"report_time": 1643408373,
"report_time": "1643408373123",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source_type": "navigation",
"trigger_data": "7"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"trigger_data": "7",
"trigger_debug_key": "333"
},
"report_time": 1643235574,
"report_time": "1643235574000",
"report_url": "https://r.test/.well-known/attribution-reporting/debug/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand All @@ -28,7 +28,7 @@
"trigger_data": "7",
"trigger_debug_key": "333"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand All @@ -43,7 +43,7 @@
"source_type": "navigation",
"trigger_data": "6"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"trigger_data": "7",
"trigger_debug_key": "333"
},
"report_time": 1643235574,
"report_time": "1643235574000",
"report_url": "https://r.test/.well-known/attribution-reporting/debug/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand All @@ -28,7 +28,7 @@
"trigger_data": "7",
"trigger_debug_key": "333"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source_type": "navigation",
"trigger_data": "7"
},
"report_time": 1643235574,
"report_time": "1643235574000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source_type": "navigation",
"trigger_data": "5"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": true
Expand All @@ -22,7 +22,7 @@
"source_type": "navigation",
"trigger_data": "1"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": true
Expand All @@ -36,7 +36,7 @@
"source_type": "navigation",
"trigger_data": "3"
},
"report_time": 1645831173,
"report_time": "1645831173000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"source_type": "navigation",
"trigger_data": "2"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand All @@ -74,7 +74,7 @@
"source_type": "navigation",
"trigger_data": "4"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand All @@ -88,7 +88,7 @@
"source_type": "navigation",
"trigger_data": "5"
},
"report_time": 1643408373,
"report_time": "1643408373000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source_type": "event",
"trigger_data": "1"
},
"report_time": 1645831173,
"report_time": "1645831173000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand All @@ -24,7 +24,7 @@
"source_type": "event",
"trigger_data": "0"
},
"replacement_time": 1643235575,
"replacement_time": "1643235575000",
"report_url": "https://r.test/.well-known/attribution-reporting/report-event-attribution",
"test_info": {
"randomized_trigger": false
Expand Down
12 changes: 6 additions & 6 deletions tools/attribution_reporting/simulator_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ Learn about the meaning of the input and output fields at
output more deterministic.
--report_time_format=<format>
- Optional. Either `seconds_since_unix_epoch`
- Optional. Either `milliseconds_since_unix_epoch`
(default) or `iso8601`. Controls the report time
output format.
`seconds_since_unix_epoch`: Report times are
integer seconds since the Unix epoch, e.g.
1643408373.
`milliseconds_since_unix_epoch`: Report times are
integer milliseconds since the Unix epoch, e.g.
1643408373000.
`iso8601`: Report times are ISO 8601 strings,
e.g. "2022-01-28T22:19:33.000Z".
Expand Down Expand Up @@ -337,13 +337,13 @@ int main(int argc, char* argv[]) {
}

auto report_time_format =
content::AttributionReportTimeFormat::kSecondsSinceUnixEpoch;
content::AttributionReportTimeFormat::kMillisecondsSinceUnixEpoch;
if (command_line.HasSwitch(kSwitchReportTimeFormat)) {
std::string str = command_line.GetSwitchValueASCII(kSwitchReportTimeFormat);

if (str == "iso8601") {
report_time_format = content::AttributionReportTimeFormat::kISO8601;
} else if (str != "seconds_since_unix_epoch") {
} else if (str != "milliseconds_since_unix_epoch") {
std::cerr << "unknown report time format: " << str << std::endl;
return 1;
}
Expand Down

0 comments on commit c8abc6e

Please sign in to comment.