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

fix: move from event-source-polyfill to fetch-event-source #24861

Merged
merged 11 commits into from
Jun 3, 2024

Conversation

alexef
Copy link
Contributor

@alexef alexef commented May 22, 2024

Hey, I just made a Pull Request!

Replace event-source-polyfill with @microsoft/fetch-event-source so we can pass our fetchApi implementation.

See @Rugvip comment: #23015 (comment)

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@github-actions github-actions bot added the area:techdocs Related to the TechDocs Project Area label May 22, 2024
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented May 22, 2024

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/plugin-scaffolder plugins/scaffolder patch v1.20.2-next.1
@backstage/plugin-techdocs plugins/techdocs patch v1.10.6-next.0

@alexef
Copy link
Contributor Author

alexef commented May 22, 2024

Actually it seems to work fine (using yarn dev in the root, I can see logs fetched via event source), and I can also confirm that fetchApi is being used.

Screenshot 2024-05-22 at 11 52 09

@github-actions github-actions bot added the area:scaffolder Everything and all things related to the scaffolder project area label May 22, 2024
@alexef alexef marked this pull request as ready for review May 22, 2024 12:50
@alexef alexef requested review from a team and backstage-service as code owners May 22, 2024 12:50
@alexef alexef changed the title Try to switch away from polyfill Move from event-source-polyfill to fetch-event-source May 22, 2024
@alexef
Copy link
Contributor Author

alexef commented May 22, 2024

Also tested the scaffolder, and events stream just like before:

Screenshot 2024-05-22 at 14 57 34

Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
@alexef alexef force-pushed the new-events-implementation branch from 2799245 to cbebad1 Compare May 22, 2024 13:01
@alexef alexef changed the title Move from event-source-polyfill to fetch-event-source fix: move from event-source-polyfill to fetch-event-source May 22, 2024
Copy link
Contributor

@aramissennyeydd aramissennyeydd left a comment

Choose a reason for hiding this comment

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

Nice!

.changeset/empty-avocados-tease.md Outdated Show resolved Hide resolved
plugins/techdocs/src/client.ts Show resolved Hide resolved
Co-authored-by: Aramis Sennyey <159921952+aramissennyeydd@users.noreply.github.com>
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
});
eventSource.addEventListener('error', event => {
subscriber.error(event);
fetchEventSource(url, {
Copy link
Member

Choose a reason for hiding this comment

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

Does this automatically cleanup? We seem to missing the eventSource.close from before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume it does. It has an onclose hook, but no explicit call to close in the documentation: https://github.com/Azure/fetch-event-source?tab=readme-ov-file#usage

Copy link
Member

Choose a reason for hiding this comment

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

It uses a signal instead, which is the more modern API. We should implement it using that 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.

updated

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should have the option of passing in an AbortController, and default to creating one if one is not provided? Maybe can save that for a followup though..

plugins/scaffolder/src/api.ts Outdated Show resolved Hide resolved
Copy link
Member

@benjdlambert benjdlambert left a comment

Choose a reason for hiding this comment

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

Hey 👋 thanks for this, just a few small things! 🙏

@@ -465,7 +464,6 @@ export class TechDocsStorageClient implements TechDocsStorageApi_2 {
constructor(options: {
configApi: Config;
discoveryApi: DiscoveryApi;
identityApi: IdentityApi;
Copy link
Member

Choose a reason for hiding this comment

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

Thinking that we should mark this as @deprecated and make it optional and just skip using it rather than breaking change. It would only affect people who provide a custom factory to the app for creating a techdocsApiRef but it's still technically breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not 100% sure the way I marked it as deprecated is fine (couldn't find a similar example). Can you check?

Copy link
Member

Choose a reason for hiding this comment

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

It needs to use a doc comment, i.e. /** @deprecated ... */. Let's keep the IdentityApi type as well, instead of any

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did the comment, but somehow I can't make it show up in the generated api-report.md.

any hints are welcome

plugins/techdocs/src/client.ts Outdated Show resolved Hide resolved
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
@alexef alexef requested a review from benjdlambert May 27, 2024 14:39
Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

Sweet, thank you! 👍

Just a couple of small fixes

});
eventSource.addEventListener('error', event => {
subscriber.error(event);
fetchEventSource(url, {
Copy link
Member

Choose a reason for hiding this comment

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

It uses a signal instead, which is the more modern API. We should implement it using that instead.

@@ -465,7 +464,6 @@ export class TechDocsStorageClient implements TechDocsStorageApi_2 {
constructor(options: {
configApi: Config;
discoveryApi: DiscoveryApi;
identityApi: IdentityApi;
Copy link
Member

Choose a reason for hiding this comment

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

It needs to use a doc comment, i.e. /** @deprecated ... */. Let's keep the IdentityApi type as well, instead of any

plugins/techdocs/src/plugin.ts Outdated Show resolved Hide resolved
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
@alexef alexef requested a review from Rugvip May 28, 2024 16:50
Copy link
Contributor

github-actions bot commented May 28, 2024

Uffizzi Ephemeral Environment - Virtual Cluster

Your cluster pr-24861 was successfully created. Learn more about Uffizzi virtual clusters
To connect to this cluster, follow these steps:

  1. Download and install the Uffizzi CLI from https://docs.uffizzi.com/install
  2. Login to Uffizzi, then select the backstage account and project:
uffizzi login
Select an account: 
  ‣ backstage
    jdoe

Select a project or create a new project: 
  ‣ backstage-6783521
  1. Update your kubeconfig: uffizzi cluster update-kubeconfig pr-24861 --kubeconfig=[PATH_TO_KUBECONFIG]
    After updating your kubeconfig, you can manage your cluster with kubectl, kustomize, helm, and other tools that use kubeconfig files: kubectl get namespace --kubeconfig [PATH_TO_KUBECONFIG]

Access the backstage endpoint at https://backstage-default-pr-24861-c5600.uclusters.app.uffizzi.com

Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
@alexef
Copy link
Contributor Author

alexef commented May 28, 2024

seems like e2e is broken now. I tried merging master onto my branch, no success to fix them. I doubt the failure relates to the code, will try to reproduce it locally

Copy link
Member

@vinzscam vinzscam left a comment

Choose a reason for hiding this comment

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

this is amazing, thanks for cleaning it up 🙏

.changeset/empty-avocados-tease.md Outdated Show resolved Hide resolved
Co-authored-by: Vincenzo Scamporlino <vincenzos@spotify.com>
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
@alexef alexef requested a review from vinzscam May 30, 2024 00:25
Signed-off-by: Alex Eftimie <alex.eftimie@getyourguide.com>
@alexef
Copy link
Contributor Author

alexef commented Jun 3, 2024

@Rugvip / @benjdlambert can you have another look?

Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

Nice, thank you! 👍 🎉

@Rugvip Rugvip merged commit 42f1865 into backstage:master Jun 3, 2024
38 checks passed
Copy link
Contributor

github-actions bot commented Jun 3, 2024

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.28.0 release, scheduled for Tue, 18 Jun 2024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:scaffolder Everything and all things related to the scaffolder project area area:techdocs Related to the TechDocs Project Area
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants