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

refactor: correlation rule #85

Merged
merged 16 commits into from
Aug 6, 2024
Merged

refactor: correlation rule #85

merged 16 commits into from
Aug 6, 2024

Conversation

Llandy3d
Copy link
Member

@Llandy3d Llandy3d commented Aug 4, 2024

Closes https://github.com/grafana/k6-cloud/issues/2550

Adds new specific types removing a lot of unneeded checks and add tests.

correlationExtractionSnippet: correlationExtractionSnippet,
generatedUniqueId: uniqueId,
}
}

// @ts-expect-error we have commonjs set as module option
if (import.meta.vitest) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I've used in-source tests as they were useful to test things without exporting while refactoring, we might not want to use them since it's not standard but let's discuss it!

src/types/rules.ts Outdated Show resolved Hide resolved
@Llandy3d Llandy3d force-pushed the correlation_refactor branch from c433183 to a945e60 Compare August 5, 2024 15:18
Copy link
Collaborator

@going-confetti going-confetti left a comment

Choose a reason for hiding this comment

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

I'll take a closer look tomorrow, but wanted to add some comments first. In general, it looks really good!

src/rules/shared.ts Show resolved Hide resolved
src/rules/utils.ts Outdated Show resolved Hide resolved
) => {
// TODO: replace regex with findBetween from k6-utils once we have imports
return `
regex = new RegExp('${rule.extractor.selector.begin}(.*?)${rule.extractor.selector.end}')
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if we hard-code the import and then add a prettier plugin that removes unused imports for cases when it's not used?

Copy link
Member Author

Choose a reason for hiding this comment

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

I still think it might be better to figure out imports first because we could also have situations where the import might not be reachable via network. (closed down environments)

Also most likely we are going to need to implement our own version of findBetween that supports not specifying an end. 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

I still think it might be better to figure out imports first because we could also have situations where the import might not be reachable via network. (closed down environments)

We won't be able to use jslib in such cases unless we ship local copies of those libraries along with k6 studio - is this something we want to do?

Copy link
Member Author

Choose a reason for hiding this comment

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

not yet decided but is something that we will need to consider, talking with Tom in closed down environments making a local copy of the libraries is the only option (and what was done so far)

Copy link
Collaborator

Choose a reason for hiding this comment

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

That task is getting more and more involved with each passing day it seems :D

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, we should probably try to split it into multiple parts 🤔

src/types/rules.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@e-fisher e-fisher left a comment

Choose a reason for hiding this comment

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

I've created a PR to remove type casts: #88
The reason you needed type casts was switching on nested property but passing the whole rule object, while only selector was used

Also, would you mind moving extraction functions into separate files? I think it would be so much easier to review and maintain if one file consisted of only the function tested and tests that belong to it.

@Llandy3d
Copy link
Member Author

Llandy3d commented Aug 6, 2024

I've created a PR to remove type casts: #88 The reason you needed type casts was switching on nested property but passing the whole rule object, while only selector was used

Also, would you mind moving extraction functions into separate files? I think it would be so much easier to review and maintain if one file consisted of only the function tested and tests that belong to it.

I actually used that approach for Replacers and it's extremely great here, nice suggestion! 🙌 🚀

For removing extraction functions into separate files that's a yes but not in this PR since there is another one depending on it and I was already thinking of doing that while implementing verification. Basically I'm approaching the refactor bit by bit on actual use case if it makes sense 🤔

Copy link
Collaborator

@e-fisher e-fisher left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Copy link
Collaborator

@going-confetti going-confetti left a comment

Choose a reason for hiding this comment

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

LGTM

@Llandy3d Llandy3d merged commit f370ad6 into main Aug 6, 2024
1 check passed
@Llandy3d Llandy3d deleted the correlation_refactor branch August 6, 2024 14:14
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