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

Rewrote the interfaces of the Splunk object to follow the hierarchy of the Javascript SplunkSDK #79

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

TyMarc
Copy link
Contributor

@TyMarc TyMarc commented Jan 15, 2025

Based on @aviau 's comment, a wrapper would be better to do better error handling in the future.

Will be used to simplify the creation of a wrapper to generate Promises on top of the JS SDK

@TyMarc TyMarc requested a review from markkasaboski January 15, 2025 18:53
@TyMarc TyMarc self-assigned this Jan 15, 2025
@TyMarc TyMarc force-pushed the mahinse/restart_error_message branch from 9ecb106 to e1da2b7 Compare January 15, 2025 18:55
@@ -58,44 +58,60 @@ function createService(): SplunkService {
return service;
}

function handleHTTPScriptError(error: any): Promise<boolean> {
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to extract this in a SplunkHTTPClient somewhere?

Otherwise we have to copy paste this handler's pointer everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are actually using the Splunk SDK's HTTP Client, that's why I'm adding the error handling in the Promise directly. Also, the script error handling only apply to the four endpoints we defined in the flare_external_requests script file, not the other HTTP request that are done on the Splunk SDK objects

Copy link
Member

@aviau aviau Jan 15, 2025

Choose a reason for hiding this comment

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

So then my suggestion is to wrap the Splunk SDK's client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how I would do that, I'm not working directly with their HTTP client, they already have a wrapper above it to expose their interface, they just append to also have the methods get and post available to do requests with your authentication. The Splunk SDK is injected in the page, it's not a dependency that we have in the project.

Copy link
Member

@aviau aviau Jan 15, 2025

Choose a reason for hiding this comment

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

Similar to this?:

const splunkClient = () => {
    const post = (url, data) => Promise {
        return promisify(service.post)(url, data).catch(handleHTTPServiceError)
    }
    return {
        post,
    };
}();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. It's not a small refactor, I might finish this PR during the cooldown or if I have downtime during the cycle.

@TyMarc TyMarc force-pushed the mahinse/restart_error_message branch 2 times, most recently from 128bd95 to e9e720f Compare January 16, 2025 01:22
@TyMarc TyMarc changed the title Handle the HTTP errors coming from scripts and show a different message if initial configuration Rewrote the interfaces of the Splunk object to follow the hierarchy of the Javascript SplunkSDK Jan 16, 2025
@TyMarc
Copy link
Contributor Author

TyMarc commented Jan 16, 2025

This PR is now a refactor of the Splunk interface typing on top of the JS SplunkSDK. I will create two other PRs on top of this one: one for the wrapper that will promisify the functions and another one that will actually do the error handling

update: (properties: Record<string, string>) => SplunkRequestResponse;
list: () => Array<{ name: string }>;
export interface Resource extends Endpoint {
fetch: () => this;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be redeclared here if it's declared in Endpoint that this interface extends from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right!

Copy link
Collaborator

@markkasaboski markkasaboski left a comment

Choose a reason for hiding this comment

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

Just the one question. Otherwise, LGTM

…f the Javascript SplunkSDK

Will be used to simplify the creation of a wrapper to generate Promises on top of the JS SDK
@TyMarc TyMarc force-pushed the mahinse/restart_error_message branch from e9e720f to ed7ddda Compare January 16, 2025 15:00
@TyMarc TyMarc merged commit 4222186 into main Jan 16, 2025
2 checks passed
@TyMarc TyMarc deleted the mahinse/restart_error_message branch January 16, 2025 15:06
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