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

refactor: using subscription lifecycle or take(1) where necessary #2495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anandtiwary
Copy link
Contributor

@anandtiwary anandtiwary commented Nov 1, 2023

Description

Please include a summary of the change, motivation and context.

Testing

Please describe the tests that you ran to verify your changes. Please summarize what did you test and what needs to be tested e.g. deployed and tested helm chart locally.

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

Documentation

Make sure that you have documented corresponding changes in this repository or hypertrace docs repo if required.

@anandtiwary anandtiwary marked this pull request as ready for review November 1, 2023 18:54
@anandtiwary anandtiwary requested a review from a team as a code owner November 1, 2023 18:54
Copy link

codecov bot commented Nov 1, 2023

Codecov Report

Merging #2495 (ecfadf0) into main (d2dd2b4) will increase coverage by 0.00%.
Report is 5 commits behind head on main.
The diff coverage is 97.77%.

@@           Coverage Diff           @@
##             main    #2495   +/-   ##
=======================================
  Coverage   83.06%   83.06%           
=======================================
  Files         925      925           
  Lines       20610    20622   +12     
  Branches     3254     3254           
=======================================
+ Hits        17119    17130   +11     
- Misses       3372     3373    +1     
  Partials      119      119           
Files Coverage Δ
...nents/src/download-file/download-file.component.ts 100.00% <100.00%> (ø)
...ts/components/src/select/select-group.component.ts 100.00% <100.00%> (ø)
...mponents/src/table/table-csv-downloader.service.ts 89.47% <100.00%> (ø)
projects/components/src/table/table.component.ts 79.95% <100.00%> (+0.04%) ⬆️
...ore-query-editor/explore-query-editor.component.ts 97.82% <100.00%> (+0.15%) ⬆️
...roup-by/explore-query-group-by-editor.component.ts 97.82% <100.00%> (+0.09%) ⬆️
...timeline-card-list/timeline-card-list.component.ts 100.00% <100.00%> (ø)
...d-wrapper/application-aware-dashboard.component.ts 82.85% <100.00%> (+0.50%) ⬆️
projects/dashboards/src/widgets/widget-renderer.ts 85.71% <75.00%> (-2.53%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link

github-actions bot commented Nov 1, 2023

Unit Test Results

       4 files     316 suites   49m 23s ⏱️
1 131 tests 1 131 ✔️ 0 💤 0 ❌
1 141 runs  1 141 ✔️ 0 💤 0 ❌

Results for commit ecfadf0.

});
this.fileDownloadService
.downloadAsText(metadata)
.pipe(take(1))
Copy link
Contributor

Choose a reason for hiding this comment

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

Finite observable; upstream emits once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you want me to revert this or any other similar change in this PR if it is not breaking anything?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to capture what I was saying offline - I think the readability is key. Making double sure a subscription is cleaned up is fine as long as we're not making the code significantly harder to follow. I'd put take in the former camp, but subscription lifecycle (in its current form) in the latter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just my 2c though, up to you guys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. let me update

.pipe(observeOn(asyncScheduler))
.subscribe(list => this.setPositions(list));
this.subscriptionLifecycle.add(
queryListAndChanges$(this.selectChildren)
Copy link
Contributor

Choose a reason for hiding this comment

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

query list is an angular component-local component. I would assume it already completes on component destroy.

@@ -67,7 +67,8 @@ export class TableCsvDownloaderService {
fileName: fileName,
dataSource: of(content)
});
})
}),
take(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

this one's good. We have no guarantees about what our caller will give us.

)
.subscribe(sort => this.updateSort(sort));
this.subscriptionLifecycle.add(
combineLatest([this.activatedRoute.queryParamMap, this.columnConfigs$])
Copy link
Contributor

Choose a reason for hiding this comment

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

two finite observables will produce a finite observable.

this.tableService.updateFilterValues(this.columnConfigsSubject.value, this.dataSource!); // Mutation! Ew!
});
this.subscriptionLifecycle.add(
this.dataSource?.loadingStateChange$.subscribe(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

also finite. The data source's disconnect method completes this (however this is questionable; that means it cannot be connect'ed again).

this.visualizationRequestChange.emit(query);
});
this.subscriptionLifecycle.add(
this.visualizationRequest$.subscribe(query => {
Copy link
Contributor

Choose a reason for hiding this comment

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

viz request is already tied to lifecycle

)
.subscribe(this.groupByExpressionChange);
this.subscriptionLifecycle.add(
this.groupByExpressionsToEmit
Copy link
Contributor

Choose a reason for hiding this comment

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

This one's good, it's a bug. But rather than wrapping this subscription in a lifecycle, can we complete the subject instead?

this.buildItems(allCards);
});
this.subscriptionLifecycle.add(
queryListAndChanges$(this.cards)
Copy link
Contributor

Choose a reason for hiding this comment

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

query list should be ok

.getTimeRangeAndChanges()
.pipe(takeUntil(this.destroyDashboard$))
.subscribe(timeRange => dashboard.setTimeRange(timeRange));
this.subscriptionLifecycle.add(
Copy link
Contributor

Choose a reason for hiding this comment

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

the takeuntil already accomplishes this

this.api.dataRefresh$.subscribe(() => this.onDashboardRefresh());
this.api.change$.subscribe(() => this.onModelChange());
this.api.timeRangeChanged$.subscribe(timeRange => this.onTimeRangeChange(timeRange));
this.api.dataRefresh$.pipe(takeUntil(this.destroyed$)).subscribe(() => this.onDashboardRefresh());
Copy link
Contributor

Choose a reason for hiding this comment

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

the api observables are all tied to lifecycle already.

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.

None yet

3 participants