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

Add support for Lambda #76

Merged
merged 1 commit into from
Nov 17, 2023
Merged

Add support for Lambda #76

merged 1 commit into from
Nov 17, 2023

Conversation

nickcaballero
Copy link
Contributor

@nickcaballero nickcaballero commented Nov 1, 2023

This PR adds support for invoking Lambda functions.

@nickcaballero nickcaballero requested review from a team as code owners November 1, 2023 20:38
@nickcaballero nickcaballero requested review from codebien, joanlopez, allansson and 2Steaks and removed request for a team November 1, 2023 20:38
Comment on lines +58 to +65
} catch (error) {
if (error.name !== 'AssertionError') {
console.error(`FAIL [${description}]`, error.stack);
check(error, {[description]: () => false})
} else {
console.error(`FAIL [${description}]`, error.message);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this bit to provide better error messages. While testing I noticed that we weren't really adding a failed check when the test failed without any failed assertions.

Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with this addition, albeit we might want to improve that generally eventually 👍🏻

Indeed asyncDescribe is pretty much a workaround (to not say hack) at the moment, as using k6-chaijs in an async context is currently impacted by k6#2728, and group not working correctly in an async context.

src/internal/error.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

Hey @nickcaballero,
thanks for this new contribution! 🙇

We already have a similar PR #71 in the pipeline regarding the Lambda service. Our plan would be to merge #71 before then it would be great to have this PR rebased on top of it.
I see you have added additional details and a different proposal for the invoke API that we would like to include in the project.

Does it sound like a reasonable plan for you?

@nickcaballero
Copy link
Contributor Author

Hey @nickcaballero, thanks for this new contribution! 🙇

We already have a similar PR #71 in the pipeline regarding the Lambda service. Our plan would be to merge #71 before then it would be great to have this PR rebased on top of it. I see you have added additional details and a different proposal for the invoke API that we would like to include in the project.

Does it sound like a reasonable plan for you?

Sounds good! Apologies, I didn't see the other PR 🤦.

@codebien
Copy link
Contributor

codebien commented Nov 2, 2023

Hey @nickcaballero, we merged #71. You can now rebase on top of it. Thanks for the effort 🙇

Comment on lines +42 to +45
const error = response.json() as any;
const message = error.Message || error.message || error.__type || 'An error occurred on the server side';
const code = response.headers['X-Amzn-Errortype'] || error.__type
return new AWSError(message, code)
Copy link
Contributor Author

@nickcaballero nickcaballero Nov 2, 2023

Choose a reason for hiding this comment

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

Pulled some of the error handling logic that @jakub-qg added into here to make it more reusable.

Copy link
Member

Choose a reason for hiding this comment

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

This is really neat 🙇🏻

@nickcaballero
Copy link
Contributor Author

Hey @nickcaballero, we merged #71. You can now rebase on top of it. Thanks for the effort 🙇

Done!

@allansson allansson requested a review from codebien November 7, 2023 12:03
Consult the `LambdaClient` [dedicated k6 documentation page](https://k6.io/docs/javascript-api/jslib/aws/lambdaclient) for more details on its methods and how to use it.

```javascript
import { AWSConfig, LambdaClient } from 'https://jslib.k6.io/aws/0.11.0/lambda.js'
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
import { AWSConfig, LambdaClient } from 'https://jslib.k6.io/aws/0.11.0/lambda.js'
import { AWSConfig, LambdaClient } from 'https://jslib.k6.io/aws/0.12.0/lambda.js'

I expect we need to bump, right @oleiade?

Copy link
Member

Choose a reason for hiding this comment

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

@codebien So far bumping version numbering has been part of our release process, and we haven't done it in feature PRs.

Although I realize we haven't added it to our CONTRIBUTING guidelines yet, will do so 👍🏻

Comment on lines +3 to +10
testdata_folder="/etc/localstack/init/testdata/lambda"
zip_dir=/tmp/lambda
mkdir -p "$zip_dir"

# Create a dummy lambda function responding with a static string "Hello World!"
cat >index.js <<EOF
exports.handler = async function(event, context) {
return "Hello World!";
}
EOF
for file in "$testdata_folder"/*; do
function_name=$(basename "$file")
function_zip="$zip_dir/$function_name.zip"
(cd "$file" || exit; zip "$function_zip" ./*)
Copy link
Contributor

Choose a reason for hiding this comment

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

@nickcaballero do we need to have them nested in folders? Could we have direct a list of files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The file structure matches how the zips are created. We can flatten the folders, but it'll make the script a bit more complicated.

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to have a simpler script, rather than a simpler folder structure 👍🏻

@codebien codebien requested a review from oleiade November 15, 2023 13:40
@2Steaks 2Steaks removed their request for review November 15, 2023 15:42
@allansson allansson removed their request for review November 15, 2023 20:33
Copy link
Member

@oleiade oleiade left a comment

Choose a reason for hiding this comment

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

LGTM 👏🏻 🚀

Thank you for your contribution @nickcaballero, as always much appreciated 🙇🏻

Comment on lines +58 to +65
} catch (error) {
if (error.name !== 'AssertionError') {
console.error(`FAIL [${description}]`, error.stack);
check(error, {[description]: () => false})
} else {
console.error(`FAIL [${description}]`, error.message);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with this addition, albeit we might want to improve that generally eventually 👍🏻

Indeed asyncDescribe is pretty much a workaround (to not say hack) at the moment, as using k6-chaijs in an async context is currently impacted by k6#2728, and group not working correctly in an async context.

Comment on lines +42 to +45
const error = response.json() as any;
const message = error.Message || error.message || error.__type || 'An error occurred on the server side';
const code = response.headers['X-Amzn-Errortype'] || error.__type
return new AWSError(message, code)
Copy link
Member

Choose a reason for hiding this comment

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

This is really neat 🙇🏻

Consult the `LambdaClient` [dedicated k6 documentation page](https://k6.io/docs/javascript-api/jslib/aws/lambdaclient) for more details on its methods and how to use it.

```javascript
import { AWSConfig, LambdaClient } from 'https://jslib.k6.io/aws/0.11.0/lambda.js'
Copy link
Member

Choose a reason for hiding this comment

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

@codebien So far bumping version numbering has been part of our release process, and we haven't done it in feature PRs.

Although I realize we haven't added it to our CONTRIBUTING guidelines yet, will do so 👍🏻

@oleiade oleiade merged commit 6bf3253 into grafana:main Nov 17, 2023
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