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

Monitoring: add logic to pick the available stack for a service #3105

Closed
wants to merge 49 commits into from

Conversation

0oM4R
Copy link
Contributor

@0oM4R 0oM4R commented Jul 9, 2024

Changes

  • support updateurl in monitor classes
  • add ServiceUrlManager
  • fix main and type paths in package.json

Related Issues

Documentation PR

For UI changes, Please provide the Documetation PR on info_grid

Checklist

  • Tests included
  • Build pass
  • Documentation
  • Code format and docstrings
  • Screenshots/Video attached (needed for UI changes)

@0oM4R 0oM4R marked this pull request as ready for review July 15, 2024 14:14
Comment on lines 114 to 115
private rmbValidatesChain = false;
private rmbTFchainUrls: string[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we group all related rmb options into one object

rmb: {
urls: string[],
chainUrls?: string[],
validateChainUrl = false,
}

"red",
);
}
throw new Error(` Failed to reach ${service.serviceName()} on all provided stacks`);
Copy link
Member

Choose a reason for hiding this comment

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

Allow option silent to return null instead of error

Copy link
Member

Choose a reason for hiding this comment

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

by default silent: false

- add silent prop, to allow returing null.
- move RMB code to seperated function
Comment on lines 199 to 210
if (this[ServiceName.GraphQl]) {
if (this[ServiceName.GraphQl]?.length == 0)
result[ServiceName.GraphQl] = this.handleSilent(
"Can't validate GraphQL stacks; There is GraphQL urls provided",
);
else {
result[ServiceName.GraphQl] = this.getAvailableServiceStack(
this[ServiceName.GraphQl],
new GraphQLMonitor(this[ServiceName.GraphQl][0]),
);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should I extract this logic to a separated function like RMB?

* @throws {Error} - Throws an error if no reachable service URL is found after checking all URLs.
*
*/
async getAvailableServiceStack(urls: string[], service: ILivenessChecker): Promise<ServiceUrl<N>> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we should pass service instance, i don't like it but this will reduce code redundancy and handle all types of ILivenessChecker

Comment on lines +1 to +4
const gridproxy = ["test", "hello", "https://gridproxy.dev.grid.tf/"];
const rmb = ["wsefews://tfin.dev.grid.tf/ws", "wss://relay.dev.grid.tf"];
const graphql = ["https://graphql.dev.grid.tf/graphql"];
const tfChain = ["wss://tfchain.dev.grid.tf/ws", "wsss://tfchain.dev.grid.tf/ws"];
Copy link
Contributor

Choose a reason for hiding this comment

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

that don't look like valid urls, you should use a valid url but not reachable

Comment on lines 10 to 18
serviceName() {
return this.name;
}
serviceUrl() {
return this.url;
}
updateUrl(url: string) {
this.url = url;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what about using setters and getters here instead?

it would look better service.url instead of service.serviceUrl and so on...

async getAvailableServiceStack(urls: string[], service: ILivenessChecker): Promise<ServiceUrl<N>> {
let error: Error | string = "";
for (let i = 0; i < urls.length; i++) {
if (i != 0) await service.updateUrl(urls[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (i != 0) await service.updateUrl(urls[i]);
if (i != 0) service.updateUrl(urls[i]);

@0oM4R 0oM4R marked this pull request as draft July 17, 2024 10:48
constructor(activationServiceUrl?: string) {
if (activationServiceUrl) this.url = activationServiceUrl;
}
public get Name() {
Copy link
Contributor

Choose a reason for hiding this comment

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

the private property should start with _ and the getter should be lowercase

Comment on lines 14 to 15
if (!this.url) throw new Error("Can't access before initialization");
return this.url;
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to check if it's defined or not here. just return whatever the value

this.URL = param.url;
}
async isAlive(): Promise<ServiceStatus> {
return resolveServiceStatus(sendRequest(this.url, { method: "Get" }));
Copy link
Contributor

Choose a reason for hiding this comment

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

you need here to make sure the URL is defined or not

- change naming
- remove error on get url and return empty string in case the url is not set yet
- add errror handling in isAlive, will throw in case the service url is not set
@0oM4R
Copy link
Contributor Author

0oM4R commented Jul 21, 2024

#3134 all changes applied on

@0oM4R 0oM4R closed this Jul 21, 2024
@0oM4R 0oM4R deleted the development_support_multiple_stacks branch July 21, 2024 13:20
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.

3 participants