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

sdk-ts : Support multiple stacks per network #3078

Closed
Tracked by #1565 ...
xmonader opened this issue Jul 3, 2024 · 23 comments
Closed
Tracked by #1565 ...

sdk-ts : Support multiple stacks per network #3078

xmonader opened this issue Jul 3, 2024 · 23 comments
Assignees
Milestone

Comments

@xmonader
Copy link
Contributor

xmonader commented Jul 3, 2024

threefoldtech/home#1550

@xmonader xmonader transferred this issue from threefoldtech/home Jul 3, 2024
@AhmedHanafy725 AhmedHanafy725 moved this to Accepted in 3.15.x Jul 4, 2024
@AhmedHanafy725 AhmedHanafy725 added this to the 2.6.0 milestone Jul 4, 2024
@0oM4R 0oM4R moved this from Accepted to In Progress in 3.15.x Jul 7, 2024
@0oM4R
Copy link
Contributor

0oM4R commented Jul 7, 2024

Issue update :
started to implement the logic but can't use the monitor package
image

@0oM4R
Copy link
Contributor

0oM4R commented Jul 7, 2024

also current mentor services logs the aliveness of the services but do not return any values,i think it need some refactor adding new methods

@0oM4R
Copy link
Contributor

0oM4R commented Jul 8, 2024

WIP: creating the logic to pick the first available stack per service add this init class to the alivenessCheck in monitoring

export class serviceStackPicker {
  private result: ServicesUrls = {};
  constructor(public options: StackPickerOptions) {}

  private async pingService(service: ILivenessChecker) {
    const status = await service.isAlive();
    if ("disconnect" in service) {
      await (service as IDisconnectHandler).disconnect();
    }
    return status;
  }
  async GetAvailableServices(): Promise<ServicesUrls> {
    if ("tfChain" in this.options)
      this.result.tfChain = await this.getAvailableServiceStack(
        this.options.tfChain.slice(1),
        new TFChainMonitor(this.options.tfChain[0]),
      );
    if ("gridProxy" in this.options)
      this.result.GirdProxy = await this.getAvailableServiceStack(
        this.options.GirdProxy.slice(1),
        new GridProxyMonitor(this.options.GirdProxy[0]),
      );


    return this.result;
  }
  async getAvailableServiceStack(urls: string[], service: ILivenessChecker) {
    let index = 0;
    do {
      const status = await this.pingService(service);
      if (status.alive) return service.serviceUrl();
      console.log(`${service.serviceName()}: failed to ping ${service.serviceUrl()}, due to ${status.error}`);
      service.setServiceURl(urls[index++]);
    } while (index < urls.length);
  }
}

and should be called anywhere with

 const test = new serviceStackPicker({
    tfChain: ["faf", "wss://tfchain.dev.grid.tf/ws", "wsss://tfchain.dev.grid.tf/ws"],
    GirdProxy: ["hahah", "https://gridproxy.dev.grid.tf"],
  });
  console.log(await test.GetAvailableServices());

also we had to add setServicesUrl method to IServiceBase and add some changes to update the effected props

this snips is the initial phase of coding, feel free to suggest any refactors

@0oM4R 0oM4R changed the title sdk-ts sdk-ts : Support multiple stacks per network Jul 9, 2024
@0oM4R
Copy link
Contributor

0oM4R commented Jul 9, 2024

Issue Update:
monitoring part is almost ready, will support accessing the pick function directly and make the #3105 ready for review.

@0oM4R
Copy link
Contributor

0oM4R commented Jul 10, 2024

Issue update:
was investigating how to read and pars array form user, but i can't reach anything;

WIP: creating a script to read from user the stacks for each service and then will convert it to string and export it
current behavior
image

@AhmedHanafy725
Copy link
Contributor

it shouldn't be interactive. you can export them with comma-separate then split them in the script

@0oM4R
Copy link
Contributor

0oM4R commented Jul 14, 2024

it shouldn't be interactive. you can export them with comma-separate then split them in the script

done export target stacks separated with comma will work fine
image

@amiraabouhadid amiraabouhadid moved this from In Progress to Pending Review in 3.15.x Jul 14, 2024
@amiraabouhadid amiraabouhadid moved this from Pending Review to In Progress in 3.15.x Jul 14, 2024
@0oM4R
Copy link
Contributor

0oM4R commented Jul 15, 2024

Issue update:
#3105 got some changes:

  • add stats and activation services
  • fix build for browser
  • replace fetch with axios
  • refactor sendRequest to adapt graphQl requests
  • add options to allow validating tfchain while validating rmb, or take the provided tfchain url as it is

@0oM4R
Copy link
Contributor

0oM4R commented Jul 16, 2024

Issue update:
#3105 had some refactors
WIP: finding a way to integrate this logic with playground

@0oM4R
Copy link
Contributor

0oM4R commented Jul 17, 2024

Issue update: applied pr comments and introduce new features

@0oM4R
Copy link
Contributor

0oM4R commented Jul 18, 2024

New monitoring pr is ready : #3134

@0oM4R
Copy link
Contributor

0oM4R commented Jul 21, 2024

All review comments applied on #3134

@0oM4R
Copy link
Contributor

0oM4R commented Jul 23, 2024

Issue update:
fixed some issues in monitroring while integrating it in UI,

Blocker:

import TFGridGqlClient from "@threefold/graphql_client";
import GridProxyClient from "@threefold/gridproxy_client";
import { QueryClient } from "@threefold/tfchain_client";
const gqlClient = new TFGridGqlClient(window.env.GRAPHQL_URL);
const gridProxyClient = new GridProxyClient(window.env.GRIDPROXY_URL);
const queryClient = new QueryClient(window.env.SUBSTRATE_URL);
export { gqlClient, gridProxyClient, queryClient };
export * from "./indexedDB";

those clients got loaded before initializing the envs and got undifined urls, suggest moving those clients to grid store

@0oM4R
Copy link
Contributor

0oM4R commented Jul 24, 2024

Issue Update:
Monitoring integrated in playground
Blocker: Not sure yet should we provide fake mnemonic for RMB monitor or what

Screenshot from 2024-07-24 19-14-39

@0oM4R
Copy link
Contributor

0oM4R commented Jul 28, 2024

all requested changes applied, and ui is ready as well.

@0oM4R 0oM4R moved this from In Progress to Pending Review in 3.15.x Jul 28, 2024
@0oM4R 0oM4R moved this from Pending Review to In Progress in 3.15.x Jul 28, 2024
@0oM4R
Copy link
Contributor

0oM4R commented Jul 29, 2024

As we discussed with @sameh-farouk, we can use chain /health endpoint to verify node rpc status,
if it responds with 200 OK, then it is alive and we can rely on it

@0oM4R
Copy link
Contributor

0oM4R commented Jul 29, 2024

Issue update

  • now all services are monitored via fetch requests
  • applied some review comments

Blocker
while pinging all urls in parallel, by passing url to the alive method, all urls give an error even if one of them is reachable
work on testing branch

@0oM4R
Copy link
Contributor

0oM4R commented Jul 30, 2024

Issue update:
I added the required fallback mechanism, but I'm facing a very wired issue, when we have more than one invalid url in the stack, the whole requested urls for all services got effected and gives Timeout error
Screenshot from 2024-07-30 18-43-53

but if we remove one of the invalid/unreachable urls from the array it works fine.

const gridproxy = ["http://www.nonexistentgridProxy.com", "http://www.gooogleTF.com", "https://gridproxy.dev.grid.tf/"];

details of the new applied mechanism:

Concerns:
this approach takes a lot of time, as Promise.allSattled waits for all stacks to resolve
so if i have 2 urls first one has a response on the first try, and the second is unreachable
i have to wait for the second one to exhausts all its retries, for our case, with base timeout 2 it will take about 12 seconds to response with the first url that already replied within the first 2 seconds
image

@0oM4R
Copy link
Contributor

0oM4R commented Jul 31, 2024

Issue update :
resolved the issue of fetch by providing valid or existing urls
work completed:
support url monitor in gridclient, code needs some cleanup and test then the pr will be ready

@0oM4R
Copy link
Contributor

0oM4R commented Aug 1, 2024

I faced an issue while testing playground integration: getDefaultUrls had braking changes as it used in playground and tests so will create new function that contain the new added logic

@0oM4R
Copy link
Contributor

0oM4R commented Aug 1, 2024

@0oM4R 0oM4R moved this from In Progress to Pending Review in 3.15.x Aug 1, 2024
@0oM4R 0oM4R moved this from Pending Review to In Verification in 3.15.x Aug 19, 2024
@A-Harby
Copy link
Contributor

A-Harby commented Sep 10, 2024

Verified, Devnet.

The stack is working fine, checking all the URLs at once with 3 retries and picking the working one in the same order as they were written.

For one failing but the other working.
image

For all of them to fail.
image

For Grid client.
image

Created an issue for the Grid Client to work as config in playground: #3399.

New test Case: TC2825 - Run locally with multiple stack

@A-Harby A-Harby moved this from In Verification to Done in 3.15.x Sep 10, 2024
@ramezsaeed ramezsaeed moved this from Done to In Verification in 3.15.x Sep 22, 2024
@khaledyoussef24
Copy link
Contributor

khaledyoussef24 commented Sep 30, 2024

verified
used Harby's test case and it is working fine

changed the stacks in the file of tfgrid-sdk-ts/packages/playground/public/config.js
Screenshot 2024-09-30 at 3 13 18 PM

and also tried to implement wrong urls in the file to check the behaviour
Screenshot 2024-09-30 at 3 18 21 PM
if many stalk are there it would switch automatically to another one
as here : (left the same wrong urls but added also the valid ones)
and the dashboard worked (but left some errors for the wrong urls

Screenshot 2024-09-30 at 3 20 27 PM

@khaledyoussef24 khaledyoussef24 moved this from In Verification to Done in 3.15.x Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

6 participants