Skip to content
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

Move dynamic bindings (resource-timing) to requests.js #18275

Merged
merged 3 commits into from Sep 27, 2018

Conversation

lannka
Copy link
Contributor

@lannka lannka commented Sep 22, 2018

This is another preparation PR to unblock #6031

const analyticsVar = 'resourceTiming';
dynamicBindings[binding] =
serializeResourceTiming(this.win, resourceTimingSpec);
expansionOptions.vars[analyticsVar] = binding;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method has a side effect in this line which mutates the param.
removed and moved to the mapping to vendors.js.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

* We stop reporting after 1 minute.
* @private @const {number}
*/
this.maxResourceTimingReportingTime_ = Date.now() + (60 * 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work. It's each analytics instance has single reportingTime. the getMacroBindings only gets called before sending request so we can't start the timer with the getMacroBindings as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. moved to requests.js to ensure start time is aligned with the start of amp-analytics element

const analyticsVar = 'resourceTiming';
dynamicBindings[binding] =
serializeResourceTiming(this.win, resourceTimingSpec);
expansionOptions.vars[analyticsVar] = binding;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@lannka lannka changed the title Move dynamic bindings (resource-timing) to variable service Move dynamic bindings (resource-timing) to requests.js Sep 25, 2018
@lannka
Copy link
Contributor Author

lannka commented Sep 25, 2018

Comments addressed. PTAL

if (resourceTimingSpec) {
// Check if we're done reporting resource timing metrics before binding
// before binding the resource timing variable.
if (!resourceTimingSpec['done'] &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the general I like the change and think it's OK. But we should be aware that this leads to a behavior change on using RESOURCE_TIMING. It resolves to RESOURCE_TIMING before, but resolves to an empty string now once done is set to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. it was too arbitrary that sometimes return empty string and sometimes it keeps the RESOURCE_TIMING, we'd better to unify the behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

*/
export function getResourceTiming(win, spec, startTime) {
// Only allow collecting timing within 1s
if (spec && (Date.now() < (startTime + 60 * 1000))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is it better to save startTime + 60 * 1000 instead so that we don't need to calculate on every request? Or you think the save is too minor and we should focus on the naming instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, it does not make too much sense to store that time in requests.js

[], newConfig(), 'https://ping.example.com/endpoint?rt=');
});

it('should capture multiple matching resources', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the actual test be moved to test-resource-timing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already a test case in test-resource-timing. see L177

expect(trigger['resourceTimingSpec']['responseAfter']).to.be.above(0);
});

it('should url encode variables', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same to this test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, see L349

@lannka lannka merged commit 888afac into ampproject:master Sep 27, 2018
@lannka lannka deleted the move-dynamic-bindings branch September 27, 2018 01:42
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Oct 10, 2018
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants