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

Adding cancellation reason diagnostics #77

Merged
merged 3 commits into from
Sep 13, 2023

Conversation

kierrrrra
Copy link
Collaborator

@kierrrrra kierrrrra commented Aug 29, 2023

Why

We want to log the reason why TTVC measurement was cancelled. The most accurate way would be to implement that functionality in the library itself, especially considering that we will add more diagnostic information down the line.

What

This implements a simple interface to add listeners to diagnostic events.

Testing

  1. Good way to test this would be to build the package, launch the express server and run interaction1 e2e test case, performing a click/keydown/tab switch while the page is still loading. Diagnostic with the reason for measurement cancellation will be logged as a warning to the console.

Copy link
Member

@ajhyndman ajhyndman left a comment

Choose a reason for hiding this comment

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

A couple initial thoughts:

FIrst, I just want to make sure you saw my prior attempt at this here? #67

Second, I did notice that you ended up gravitating to a very similar solution: two sets of subscribers, one for measurements and another for cancellations. That said, I was annoyed that my solution required breaking away from the standard observable interface. If we can come up with anything that better matches this, I'd be a lot happier.

Third, assuming we do go with two separate subscriptions, I really like that your solution is a lot simpler! It makes total sense that you can just report the cancellation immediately instead of storing it in state somewhere like I was trying to do. 👍

And finally, I'd like to introduce some test coverage and documentation for a change like this. You might be able to copy-paste what I have in the first diff as a starting point! Whoops, I just noticed you already have this planned in your initial comment!

@kierrrrra kierrrrra force-pushed the kada/debug-cancellation-reason branch 2 times, most recently from d88eab1 to 4f56feb Compare September 8, 2023 12:05
@kierrrrra kierrrrra changed the title WIP - Adding cancellation reason diagnostics Adding cancellation reason diagnostics Sep 8, 2023
Copy link
Member

@ajhyndman ajhyndman left a comment

Choose a reason for hiding this comment

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

Overall, I am really liking this! Indulging in some perfectionism, I left a few comments anyway though.

src/visuallyCompleteCalculator.ts Show resolved Hide resolved
test/util/entries.ts Show resolved Hide resolved
Comment on lines 33 to 48
export type Metric = CommonMetadata & {
// value of "TTVC"
duration: number;
};

// currently, the only source of error is cancellation
export type CancellationError = CommonMetadata & {
// reason for cancellation
cancellationReason: CancellationReason;

// Optional type of event that triggered cancellation
eventType?: string;

// Optional target of event that triggered cancellation
eventTarget?: EventTarget;
};
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, what do you think about trying to make the CancellationError type also conform to the PerformanceMeasure specification?

I think the main change would be ensuring that all metadata (including cancellationReason goes into the detail bucket.

Nit: I would also just as soon not try to share a CommonMetadata interface for these two results. Personally, I think it's a little more awkward to read and doesn't save that many characters. 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't see a reason to align that to PerformanceMeasure, but if you feel strongly about it, I can move the data into detail to make it conform.

As for CommonMetadata - I actually find it easier to read that way. When I scan the code, I can quickly see CommonMetadata shared between the types and it saves me the mental cycles on thinking whether the two are actually alike or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I put some more thought into it, and I think it might be awkward to try to conform to PerformanceMeasure for something that is not a measure of time, but a record of occurrence. I would like to keep it the way it is - or have a deeper conversation about where we see value in having error state conform to PerformanceMeasure.

Copy link
Member

@ajhyndman ajhyndman Sep 8, 2023

Choose a reason for hiding this comment

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

Okay, I'm pretty convinced by your rationale for the cancellation type diverging from PerformanceMeasure schema! 👍

However, I think that makes me want to push a little further on the awkwardness of CommonMetadata. I would like it to be clearer that Metric is a data type that is designed to look similar to PerformanceMeasure and CancellationError is not.

Maybe we could change the structure so that no fields are nested in detail in CancellationError? Another small bonus of that change would be that didNetworkTimeOut?: boolean; can be explicit again; it's always present in a Metric and only sometimes present in a CancellationError.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Of course - that sounds good to me! I refactored the types to be distinctly separate, and added a note on Metric's alignment with PerformanceMeasure for future reference. Thank you Andrew!

src/visuallyCompleteCalculator.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
Comment on lines 261 to 263
detail: {
// ... identical to `detail` property of Metric type ...
};
Copy link
Member

Choose a reason for hiding this comment

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

Last nit: It looks like this section in the README is stale now.

@kierrrrra kierrrrra merged commit 782b7fb into main Sep 13, 2023
4 checks passed
@ajhyndman ajhyndman mentioned this pull request Apr 2, 2024
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