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

Do not throw an error when browsertime provides null timestamps incorrectly #4399

Merged
merged 5 commits into from
Jan 6, 2023

Conversation

canova
Copy link
Member

@canova canova commented Jan 4, 2023

It looks like browsertime sometimes provides null timestamps for the visual metrics due to sitespeedio/browsertime#1746. We should be more careful and do not throw any errors in case of this. This PR fixes that.

Example profile

@canova canova requested a review from julienw January 4, 2023 09:46
@codecov
Copy link

codecov bot commented Jan 4, 2023

Codecov Report

Base: 88.55% // Head: 88.56% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (7fb305d) compared to base (fb9ff03).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4399   +/-   ##
=======================================
  Coverage   88.55%   88.56%           
=======================================
  Files         282      282           
  Lines       25476    25484    +8     
  Branches     6854     6860    +6     
=======================================
+ Hits        22561    22569    +8     
  Misses       2708     2708           
  Partials      207      207           
Impacted Files Coverage Δ
...rc/components/timeline/TrackVisualProgressGraph.js 97.02% <100.00%> (+0.12%) ⬆️
src/profile-logic/process-profile.js 91.00% <100.00%> (+0.05%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@julienw julienw left a comment

Choose a reason for hiding this comment

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

Thanks,
I made a couple suggestions, tell me what you think!

Comment on lines 762 to 763
// Flow doesn't like null because it thinks that the timestamp can't be null.
// But this is a bug on browsertime.
Copy link
Contributor

Choose a reason for hiding this comment

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

If this can happen in the real life, I think we should actually change the type to account for this, so that our code doesn't break in unexpected ways. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm yeah. I didn't want to change the type initially because it's not the real data we expect but it's better to change it if the one we have right now can be nullable.
This change required a bunch of changes in the view progress graph though. Tested and it's not breaking the UI but it's still broken (the graph is 100% all the time without any data point). We should ideally not add these tracks if we don't have any timestamp but I prefer to do these in another PR.

@@ -679,7 +685,12 @@ describe('visualMetrics processing', function () {
const metricProgressMarker = thread.markers.name.find(
(name) => name === metricProgressMarkerIndex
);
expect(metricProgressMarker).toBeTruthy();

if (changeMarkerLength > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be a hack: you're using a property that's about change markers to change the behavior for progress markers.
Instead you should probably introduce a progressMarkerLength and use the same mechanism as for the change markers (filtering + use the toHaveLength matcher); or a simpler boolean hasProgressMarker possibly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well I initially didn't want to do a lot of changes in the original function since it's just a test but added a hasProgressMarker now.

src/test/unit/process-profile.test.js Outdated Show resolved Hide resolved
@@ -1798,6 +1804,11 @@ export function processVisualMetrics(

const changeMarkerName = `${metricName} Change`;
for (const { timestamp, percent } of metric) {
if (timestamp === null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have the same check for the Progress markers above?

optional alternate change: put the check directly in addMetricMarker (and rename it possiblyAddMetricMarker) and remove from the loops.

Then I'd also remove the first condition if (metric.every((m) => m.timestamp === null)), indeed this will possibly loop over all metrics again in the case of the bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't sure about adding the null checks to every addition at first because usually when the bug happens every timestamp becomes null, so I thought adding this check should fix it. But then couldn't help myself and added this just to be safe too :) But you're right, moving this to addMetricMarker is probably a safer option. Changed it.

@canova canova force-pushed the browsertime-null-timestamps branch from 062497a to cccff0b Compare January 5, 2023 11:05
@julienw julienw self-requested a review January 5, 2023 11:07
Copy link
Contributor

@julienw julienw left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

@@ -102,7 +102,7 @@ class TrackVisualProgressCanvas extends React.PureComponent<CanvasProps> {
// Create a path for the top of the chart. This is the line that will have
// a stroke applied to it.
x =
(deviceWidth * (progressGraphData[i].timestamp - rangeStart)) /
(deviceWidth * ((progressGraphData[i].timestamp ?? 0) - rangeStart)) /
Copy link
Contributor

Choose a reason for hiding this comment

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

probably the right way would be to keep the previous value and use it, instead of 0. (and of course use 0 as the initial previous value).
Or maybe we could preprocess it, so that we know that in this component everything is non-null.

But this is very theorical for the case where one timestamp is missing. We don't need this at the moment, so I believe this is good enough for now.

@canova canova force-pushed the browsertime-null-timestamps branch from cccff0b to 7fb305d Compare January 6, 2023 09:48
@canova canova merged commit 2f7dd0d into firefox-devtools:main Jan 6, 2023
@julienw julienw mentioned this pull request Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants