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

[Client] adding nodejs cac and experimentation client wrapper #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

namitgoel
Copy link
Contributor

Problem

Describe the problem you are trying to solve here

Solution

Provide a brief summary of your solution so that reviewers can understand your code

Environment variable changes

What ENVs need to be added or changed

Pre-deployment activity

Things needed to be done before deploying this change (if any)

Post-deployment activity

Things needed to be done after deploying this change (if any)

API changes

Endpoint Method Request body Response Body
API GET/POST, etc request response

Possible Issues in the future

Describe any possible issues that could occur because of this change

@namitgoel namitgoel requested a review from a team as a code owner July 15, 2024 14:53
@Datron
Copy link
Collaborator

Datron commented Jul 24, 2024

@namitgoel Can you add a README file that documents how to add the nodeJS clients to a project, and also how to build and run them?


let file =
platform == "darwin" ?
'../../../target/debug/libcac_client.dylib' :
Copy link
Collaborator

Choose a reason for hiding this comment

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

@namitgoel lets avoid relative paths

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Collaborator

@Datron Datron left a comment

Choose a reason for hiding this comment

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

Documentation needed + relative paths pointing to the binaries is an issue

this.cacHostName = cacHostName;
}

public getCACLastErrorMessage(): string | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we return just 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.

@Datron we cannot just return string as the response type that ref-napi libraray is providing has return type string | null

this.rustLib.cac_start_polling_update(this.tenant)
}

public getCACConfig(filterQuery: string, filterPrefix: string): string | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
public getCACConfig(filterQuery: string, filterPrefix: string): string | null {
public getCACConfig(filterQuery: string, filterPrefix: string): string | Error {


let file =
platform == "darwin" ?
'../../../target/debug/libcac_client.dylib' :
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure that file will be present at this path in case of release build too (its specifically pointing to debug directory)?

return this.rustLib.cac_get_last_modified(this.getCACClient());
}

public getResolvedConfig(query: string, filterKeys: string, mergeStrategy: string): string | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why return type for all functions is string, I am assuming its a JSON string?
Can we define types for these and de-serialize and send an actual object back?

@namitgoel namitgoel force-pushed the nodejs-cac-client branch 2 times, most recently from e14669d to 5364c56 Compare August 4, 2024 14:01
@namitgoel namitgoel force-pushed the nodejs-cac-client branch 2 times, most recently from 8e1f007 to 382aba6 Compare August 25, 2024 15:46
Copy link
Collaborator

@ayushjain17 ayushjain17 left a comment

Choose a reason for hiding this comment

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

most comments apply to both experimentation and cac file, have not repeated few comments

});

constructor(tenantName: string, pollingFrequency: number, cacHostName: string) {
if (tenantName == "" || cacHostName == "") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets separate the if checks, its returning tenantName cannot be null or empty error when either tenantName or cacHostName is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return this.rustLib.cac_get_last_modified(this.getCACClient());
}

public getResolvedConfig(query: Object, filterKeys: string[] | null, mergeStrategy: string): string | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

mergeStrategy is an enum: MERGE, REPLACE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return this.rustLib.cac_last_error_message();
}

public getCACLastErrorLength(): number {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we avoid repeating CAC in every function name, these functions are all scoped to the object of CacClient, so adding CAC again in the function name, makes it somewhat redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return this.rustLib.cac_get_client(this.tenant);
}

public createNewCACClient(): number {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the logic for this should ideally be inside the constructor itself, in haskell we needed a separate function, because that's that does not have any constructor, here since there is a constructor, this logic should be inside that itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return this.rustLib.expt_last_error_message();
}

public createNewExperimentaionClient(): number {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as CacClient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


public getResolvedConfig(query: Object, filterKeys: string[] | null, mergeStrategy: string): string | null {
let strQuery = JSON.stringify(query);
let strFilterKeys = filterKeys == null ? ref.NULL : ref.allocCString(filterKeys.join(this.delimeter));
Copy link
Collaborator

Choose a reason for hiding this comment

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

currently the delimiter being used for this function is "|"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return this.rustLib.expt_get_running_experiments(clientPtr);
}

public freeString(str: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not needed as an exposed function

return this.rustLib.expt_last_error_length()
}

public freeExprementationClient() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not needed as an exposed function

this.getCACClient(), strQuery, strFilterKeys, mergeStrategy
)
}
public getDefaultConfig(filterKeys: string[] | null): string | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the output of the functions are null, then you should check for the error and then return the error caused during the function call (for all functions returning null | some_value)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

this.rustLib.expt_free_client(this.getExperimentationClient());
}

public getFilteredSatisfiedExperiments(context: Object, filterPrefix: string[] | null): string | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

places which take input of the form: some_type | null, should ideally take some_type | undefined type data

@ayushjain17
Copy link
Collaborator

Also, make sure to deallocate the data allocated via after it has been used

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.

4 participants