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

JS-493 Add 'get-telemetry' endpoint on bridge-server #5011

Merged
merged 9 commits into from
Dec 12, 2024
Merged

Conversation

zglicz
Copy link
Contributor

@zglicz zglicz commented Dec 10, 2024

JS-493

Added a new endpoint 'get-telemetry'. This is assumed to be called after an analysis has occurred and the dependency cache is filled.

Tested in 2 ways:

  1. with postman and verified that after a) initialize-linter and b) analyze-file, a request to 'get-telemetry' returned results
  2. Added a simple unit-test, with a custom rule implementation, that verified that a simple package.json was picked up.

@zglicz zglicz requested a review from vdiez December 10, 2024 10:32
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Add 'get-telemetry' endpoint on bridge-server JS-493 Add 'get-telemetry' endpoint on bridge-server Dec 10, 2024
@vdiez vdiez requested review from a team and removed request for vdiez December 10, 2024 16:32
create(context) {
return {
CallExpression(node) {
// Necessarily call 'getDependencies' to populate the cache of dependencies
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that we would not receive any dependencies in the telemetry in case the analysis never populated the cache?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a good chance that this happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we will only have dependencies once the analysis populates it. Chance is low. I guess one would have to remove all of the rules that call the package-jsons.ts cache. In that case, we wouldn't populate anything for them. That's a tradeoff. This way, this call is very cheap and doesn't incur an extra time-cost.

Copy link
Contributor

Choose a reason for hiding this comment

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

and could you document this behavior somewhere, preferably in the code base like in the JS doc of the getDependencies() function:

Returns the dependencies of the root package.json file collected in the cache.

As the cache is populated lazily, it could be null in case no rule execution has touched it.

zglicz and others added 2 commits December 12, 2024 14:08

export function getAllDependencies(): NamedDependency[] {
const dependencies = [...cache.values()]
.flatMap(dependencies => [...dependencies])
Copy link
Contributor

Choose a reason for hiding this comment

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

if we have duplicates, would it simply overwrite and keep the last one?

Comment on lines +54 to +62
return Object.values(
dependencies.reduce(
(result, dependency) => ({
...result,
[dependency.name]: dependency,
}),
{},
),
);
Copy link
Contributor

@kebetsi kebetsi Dec 12, 2024

Choose a reason for hiding this comment

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

what is this step doing? Since we already have a NemdDependency[] at the previous step.

@@ -46,9 +73,9 @@ export function getDependencies(filename: string, cwd: string) {
const dirname = Path.dirname(toUnixPath(filename));
const cached = cache.get(dirname);
if (cached) {
return cached;
return new Set([...cached].map(item => item.name));
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this doing? Just a clone or something more?

Copy link
Contributor

@kebetsi kebetsi left a comment

Choose a reason for hiding this comment

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

See my few nitpicking comments about documenting in JS doc some things, otherwise, good job!

@zglicz zglicz merged commit 3a5d10a into master Dec 12, 2024
17 of 18 checks passed
@zglicz zglicz deleted the telemetry branch December 12, 2024 14:08
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