Configure the new RegisteredServiceProvider

:leaves: LEAF version: 3.12

:jigsaw: LEAF component(s): React app

Issue/Question:
I am migrating to the 3.12 Kubernetes-backed Service Discovery and would like some help wiring it up. In the LEAF documentation the component below is shown.

<RegisteredServiceProvider
      interval={null}
      serviceRegistryPath={serviceRegistryPath}
      user={user}
      defaultService={k8sDefaultService}
      preRequest={preRequest}
      configuredServices={configuredK8sServices}
      requireSelectedService
    >

Can I get a brief description of these configs and a simple example, or just point me to the documentation describing them. I how I haven’t missed something in my search for documentation.

Thank you.
sg

Here are some of the issues I have encountered so far.

  1. The documentation says to install

yarn add @leaf-platform/service-discovery

presumably, for the import line to work. My IDE tells me the component is not in the service-discovery package. Here’s the dependency from my package.json.

ā€œ@leaf-platform/service-discoveryā€: ā€œ3.12.1ā€,

My IDE’s intellisense complaint.

So I am doing something wrong.

  1. What’s the defaultService?

  2. Is this the expected preRequest,

const DEFAULT_USER = {
  username: 'AnonymousSystemUser',
  authorizationProp: 'LEAF_SYSTEM_USER',
};

const preRequest = (endpoint) => {
  // eslint-disable-next-line no-param-reassign
  endpoint.headers.user = JSON.stringify(DEFAULT_USER);
  return endpoint;
};

but then why would I need the ā€œuserā€ entry?

  1. Can I wrap the old with the new , kind of like…
    <AppFrame useDarkFrame>
      <ThemeProvider defaultDarkTheme>
        <ThemeWrapper>
          <CssBaseline />

          <LogoProvider
            appHeaderLogo={appHeaderLogo}
            appSpinnerLogo={appSpinnerLogo}
            appName="OC2ELOT"
            appTitle={appTitle}
            appDescription={<AppDescription />}
          >
            <RegisteredServiceProvider
              interval={null}
              serviceRegistryPath={dataServices.get('service-registry').restUrl}
              user={DEFAULT_USER}
              defaultService={k8sDefaultService}
              preRequest={preRequest}
              configuredServices={dataServices}
              requireSelectedService
            >
              <ServiceDiscoveryProvider
                user={DEFAULT_USER}
                registryPath={dataServices.get('service-registry').restUrl}
                socketPath={wsUrl}
              >
                 ...

Hi, Steve! Just confirming that this is the issue about which Terry was working with you offline on Friday and that you got all your questions answered.

Hi Jenna, it sure is and Terry was a great help. I am testing this right now on a cluster and if it all works I will update this ticket with my results.

2 Likes

Results:

There is a typo in the leaf docs that has been partially fixed here: this is how to add the component to a react-app.

yarn add @leaf-platform/service-discovery-provider

It worked. I used the answers provided by Terry to configure the new kubernetes-backed service-registry with two functional services. In both services I answered ā€˜yes’ to the yeoman question: ā€œshould this service be discoverableā€ which has the effect of making the service capable of being a service registry. I then pointed my react-app at a randomly chosen service.

A particularly nice piece of functionality is the use of the JS parameter ā€˜configuredServices’ on the RegisteredServiceProvider component. This let’s you register older data services that used the REST based SR.

            <RegisteredServiceProvider
              interval={null}
              serviceRegistryPath="state-vector-staging-fs/rest"
              user={DEFAULT_USER}
              defaultService="ui-support-service"
              preRequest={preRequest}
              configuredServices={k8services}
              requireSelectedService
            >

Where k8Services is set like

const k8services = window.ENV?.CONFIGURED_SERVERS || {};

And defined in my environment.js like

  'tspi-ds.launch-to-orbit': {
    annotations: {
      'data-service.leidos-leaf.com/event-service-uri':
        'ws://websocket-service/web-socket/event-query',
      'leaf-tools.leidos-leaf.com/live-metadata-editing': 'true',
      'leaf-tools.leidos-leaf.com/non-live-metadata-editing': 'false',
      'leaf-tools.leidos-leaf.com/rule-editing': 'false',
      'leaf-tools.leidos-leaf.com/rule-viewing': 'false',
      'service.leidos-leaf.com/base-uri': 'http://localhost/tspi-ds/rest',
    },
    available: true,
    capabilities: ['Data Store'],
    endpoints: {
      oasEndpointJson: '/app/openapi.json',
      oasEndpointYaml: '/app/openapi.yaml',
    },
    name: 'tspi-ds',
    namespace: 'launch-to-orbit',
    serviceKey: 'tspi-ds.launch-to-orbit',
  },

Findings

  • It seems you can run both REST/Kubernetes service registries simultaneously, but each will have a different view of what is, and is not available.
  • I receive CORS errors when the service acting as service registry is not in the same namespace as the react-app. This could be a configuration issue, but I don’t recall having this issue with the old REST based one.

Attachments

Here is the conversation I had in Slack with Terry,


2 Likes