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

feat(service-discovery): Align service discovery with API service #2459

Merged
merged 5 commits into from
Sep 16, 2024

Conversation

odinr
Copy link
Collaborator

@odinr odinr commented Sep 13, 2024

The Service Discovery module has been totally revamped to provide a more flexible and robust solution for service discovery in the Fusion Framework.
The module now relies on the Fusion Service Discovery API to fetch services and their configurations, which allows for more dynamic and real-time service discovery.

The module now follows the "best practices" for configuration and usage, and it is now easier to configure and use the Service Discovery module in your applications. But this also means that the module has breaking changes that may require updates to existing implementations.

Note

This module can still be configured to resolve custom services, as long as the client implements the IServiceDiscoveryClient interface.

Documentation Updates

  • The README file has been updated to reflect the new configuration options and usage patterns for the Service Discovery module.
  • Added sections for simple and advanced configurations, including examples of how to override the default HTTP client key and set a custom service discovery client.

Code Changes:

  • 🔨 package.json: Added zod as a new dependency for schema validation.
  • 💫 api-schema.ts: Added schema for the expected response from the ServiceProviderClient
  • 💫 client.ts: Created serviceResponseSelector for parsing and validating client respons.
  • 🔨 client.ts: Updated IServiceDiscoveryClient interface to include methods for resolving services and fetching services from the API.
  • 🔨 client.ts: Updated ServiceDiscoveryClient to use the new serviceResponseSelector
  • 💫 configurator.ts: Introduced new methods for setting and configuring the service discovery client.
  • 🔨 configurator.ts: Updated ServiceDiscoveryConfigurator to extend the BaseConfigBuilder
  • 🔨 configurator.ts: Added error handling and validation for required configurations.

BREAKING CHANGES:

  • The type Service has deprecated the defaultScopes property in favor of scopes.
  • The IServiceDiscoveryClient interface has been updated, which may require changes in implementations that use this interface.
  • The ServiceDiscoveryConfigurator now extends BaseConfigBuilder, which will affect existing configurations.
  • The ServiceDiscoveryProvider.resolveServices method now returns Service[] (previously Environment).

Note

Only the ServiceDiscoveryProvider.resolveServices should affect end-users,
as it changes the return type of the method.
The other changes are internal and should not affect existing implementations.

Consumer Migration Guide:

defaultScopes has been replaced with scopes in the Service type. Update your code to use the new property.

If you are using the ServiceDiscoveryProvider.resolveServices method, update your code to expect an array of Service objects instead of an Environment object.

// Before
const { services } = await serviceDiscoveryProvider.resolveServices('my-service');
// After
const services = await serviceDiscoveryProvider.resolveServices('my-service');

Warning

The preious Environment object had a clientId property, which is now removed, since every service can have its own client id, hence the scopes property in the Service object.

Configuration Migration Guide:

If you are consuming the @equinor/fusion-framework and only configuring the http client, no changes are required.

If you are manually enabling the Service Discovery module, update your configuration to use the new methods provided by ServiceDiscoveryConfigurator.
Refer to the updated README for detailed configuration examples and usage patterns.

Warning

The ServiceDiscoveryConfigurator now extends BaseConfigBuilder, which means that the configuration methods have changed.

Copy link

changeset-bot bot commented Sep 13, 2024

🦋 Changeset detected

Latest commit: 4a6affc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@equinor/fusion-framework-widget Patch
@equinor/fusion-framework-legacy-interopt Major
@equinor/fusion-framework-cli Minor
@equinor/fusion-framework-module-signalr Major
@equinor/fusion-framework-module-service-discovery Major
@equinor/fusion-framework-react-widget Patch
@equinor/fusion-framework-cookbook-app-react-context-custom-error Patch
@equinor/fusion-framework-cookbook-app-react-context Patch
@equinor/fusion-framework-cookbook-app-react-feature-flag Patch
@equinor/fusion-framework-react-module-signalr Patch
@equinor/fusion-framework Patch
@equinor/fusion-framework-module-widget Major
@equinor/fusion-framework-react-app Patch
@equinor/fusion-framework-react Patch
@equinor/fusion-framework-app Patch
@equinor/fusion-framework-react-components-bookmark Patch
@equinor/fusion-framework-react-components-people-provider Patch
@equinor/fusion-framework-react-module-bookmark Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added 👾 React 💾 CLI fusion framework CLI 📚 documentation Improvements or additions to documentation 🚀 feature New feature or request 🧬 Modules labels Sep 13, 2024
- adjust interfaces for api service
- replace configurator to extends BaseConfigBuilder
- update api client

BREAKING CHANGES:
- new configuration methods
- services resolves to `Services` and not `Environment`
- read changelog
…ice discovery module

- add fallback for clientId
- fix return handling of `resolveServices`

BREAKING CHANGES:

now requires `@equinor/fusion-framework-module-service-discovery^8`
- Update the baseUri in the service discovery client configuration to use the current URL with the '/_discovery/environments/current' path.
- Update the defaultScopes in the service discovery client configuration to include the '5a842df8-3238-415d-b168-9f16a6a6031b/.default' scope.
- Refactor the createDevProxy function in dev-proxy.ts to modify the response services.
- Set the environmentName to 'DEVELOPMENT' in the response object.
- Filter out the 'app' service from the response services.
- Add a new service object for the 'app' service with the uri set to the current URL and the scopes set to the clientId + '/.default'.
@odinr odinr force-pushed the feat/module-service-discovery/rewrite-to-new-api branch 2 times, most recently from 2da73ef to 4a6affc Compare September 13, 2024 10:28
@odinr odinr marked this pull request as ready for review September 13, 2024 10:31
@odinr odinr requested a review from a team as a code owner September 13, 2024 10:31
@odinr odinr self-assigned this Sep 13, 2024
Copy link
Contributor

github-actions bot commented Sep 13, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 0.39% 1633 / 410706
🔵 Statements 0.39% 1633 / 410706
🔵 Functions 23.58% 209 / 886
🔵 Branches 36.66% 374 / 1020
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/cli/src/bin/dev-proxy.ts 0% 0% 0% 0% 1, 7, 12-13, 36-61, 63-66, 68-94, 96, 98, 100-102, 104-120, 122-125, 127-134, 136-142, 144-150, 152-153, 155
packages/cli/src/bin/dev-portal/config.ts 0% 0% 0% 0% 1-3, 5-7, 11, 13-14, 16-21, 23-30, 32, 34, 36, 38-44, 46-63, 65-67, 69-73, 75
packages/modules/service-discovery/src/api-schema.ts 0% 0% 0% 0% 1, 3, 5-28, 30, 39-42
packages/modules/service-discovery/src/client.ts 0% 0% 0% 0% 1-2, 6-8, 32, 34, 39-45, 47-48, 56-58, 60-69, 71-74, 76-83
packages/modules/service-discovery/src/configurator.ts 0% 0% 0% 0% 1, 7, 11, 18-21, 23-25, 27-31, 33-35, 37, 44-47, 49-53, 55, 61-63, 65-69, 71, 78-80, 82-93, 95, 107-117
packages/modules/service-discovery/src/index.ts 0% 0% 0% 0% 1, 4, 6
packages/modules/service-discovery/src/module.ts 0% 0% 0% 0% 1-2, 11, 20, 38-43, 45-46, 53-54, 56-57, 59-62, 64, 80-86, 88, 108-114, 122
packages/modules/service-discovery/src/provider.ts 0% 0% 0% 0% 1, 72-76, 78-80, 82-84, 86-88, 90-99, 101-103, 105-111
packages/modules/service-discovery/src/types.ts 100% 100% 100% 100%
packages/modules/signalr/src/lib/utils/configure-from-framework.ts 0% 0% 0% 0% 1, 6-33
packages/react/legacy-interopt/src/create-service-resolver.ts 0% 0% 0% 0% 1, 4-47, 49
packages/widget/src/WidgetConfigurator.ts 0% 0% 0% 0% 1, 7, 9-11, 75, 79, 82-85, 87-89, 91-93, 95-109, 111-113, 116
Generated in workflow #7600

@odinr
Copy link
Collaborator Author

odinr commented Sep 13, 2024

@Noggling i do not think you need to do anything, but in case, see readme

@odinr
Copy link
Collaborator Author

odinr commented Sep 13, 2024

@terjebra could you check api-schema

i know that allot of the properties are not optional in the api model, but i only need key, uri and scopes for now

@odinr
Copy link
Collaborator Author

odinr commented Sep 13, 2024

@eikeland This PR is required in main and rebased into #2450 to be able to resolve the new application service.

@github-actions github-actions bot marked this pull request as draft September 13, 2024 11:41
@odinr odinr requested a review from eikeland September 13, 2024 12:48
@odinr odinr marked this pull request as ready for review September 16, 2024 05:11
@odinr odinr enabled auto-merge (squash) September 16, 2024 05:13
@odinr odinr merged commit 15152e4 into main Sep 16, 2024
23 of 24 checks passed
@odinr odinr deleted the feat/module-service-discovery/rewrite-to-new-api branch September 16, 2024 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💾 CLI fusion framework CLI 📚 documentation Improvements or additions to documentation 🚀 feature New feature or request 🧬 Modules 👾 React
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants