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

Introduce support for Ruby #214

Merged
merged 29 commits into from
May 9, 2024
Merged

Introduce support for Ruby #214

merged 29 commits into from
May 9, 2024

Conversation

fallwith
Copy link
Contributor

Add content for building and publishing layers for Ruby based Lambda functions. See ruby/README.md for more detailed information.

Add content for building and publishing layers for Ruby based Lambda
functions. See `ruby/README.md` for more detailed information.
README.md Show resolved Hide resolved
fallwith added 2 commits March 1, 2024 01:59
* typo fix 'subdir' -> 'sub_dir' variable
* include special packaging logic to support sourcing the agent from
  GitHub instead of RubyGems.org
- Conform to the AWS .zip file format
- Use named keyword args for all handoffs between AWS -> wrapper script
  -> agent -> customer function
@fallwith
Copy link
Contributor Author

fallwith commented Mar 2, 2024

I'm ready to share a layer with a customer for beta testing! Thanks again, @mrickard!

Screenshot 2024-03-01 at 7 19 22 PM

- Make `bin/setup` a bit more idempotent by having it call `bin/clean` first
- Rework the wrapper script
  - Place everything except the 'handler' method in a class to avoid potential
    customer method name collisions
  - Always gaurantee the `AWS_LAMBDA_FUNCTION_NAME` env var is set, as its
    presence will auto-enable serverless mode in the Ruby APM agent
  - Rework the handler string (`'<path>.<method>'`) parsing logic to support
    Ruby module and/or class namespaces while retaining support for bare
    (toplevel) method names
  - Introduce memoization of the parsed customer method namespace and method
    name so that the parse only happens once and not once per invocation of the
    customer handler method
  - Activate the new memoization at `load` time, rather than at handler
    invocation time so that the cache warming takes place when the wrapper
    script is first loaded by AWS. This could possibly be helpful with
    generating warnings regarding bad configuration earlier in the setup process
    that the customer follows.
  - Add a new Minitest test class to verify all of the different handler
    string format possibilities
- Update the test function that gets wrapped during unit tests and the
  corresponding `serverless.yml` config file to use a module and class
  namespaced handler method
- Remove unused 'json' from the test function that gets wrapped during unit
  testing
- Add additional source code comments
these changes aren't needed for building, but are needed for publishing
Optionally, the build and publish process can build a fresh extension
via a local extension git clone's `make` process
@mrickard
Copy link
Member

We'll want to make sure the automation is wired up for this.

For running automated tests on push/PR, we currently have GitHub Actions at https://github.com/newrelic/newrelic-lambda-layers/tree/master/.github/workflows ...though this could be made a little more responsive. For example, right now you're getting a lot of unreported status messages, because the changes aren't in the Node repo, and Node tests are skipped. (As they should be for that scenario...but here it presents as incomplete tests.)

Currently the layer publishing jobs are defined in https://github.com/newrelic/newrelic-lambda-layers/tree/master/.circleci/config.yml ...which I'm currently porting to GHA.

The build jobs may need a Dockerfile for Ruby. (If not, great! But Java and Node currently use them.) If so, those are defined in https://github.com/newrelic/newrelic-lambda-layers/tree/master/dockerfiles

I don't expect you'd need to change the makefile, but you may want to take a look there.

@fallwith
Copy link
Contributor Author

The build jobs may need a Dockerfile for Ruby. (If not, great! But Java and Node currently use them.) If so, those are defined in https://github.com/newrelic/newrelic-lambda-layers/tree/master/dockerfiles

I'm curious about the approach Python takes, as I don't see Dockerfiles for the supported Python runtimes.

For building the Ruby layers, I have made the build script fairly fault tolerant to a Ruby version that doesn't match the supported AWS Ruby Lambda runtime(s) (only Ruby v3.2 at this time), but it would be great to build things using the same Ruby version that we are targetting. If Docker helps with that, I welcome it.

Added Dockerfile files for all supported Ruby runtimes (AWS only
supports Ruby v3.2 at this time)
@fallwith
Copy link
Contributor Author

For building the Ruby layers, I have made the build script fairly fault tolerant to a Ruby version that doesn't match the supported AWS Ruby Lambda runtime(s) (only Ruby v3.2 at this time), but it would be great to build things using the same Ruby version that we are targetting. If Docker helps with that, I welcome it.

Ok, @mrickard. I've added a Ruby Dockerfile (only one because only one Lambda runtime exists) with
be426c6.

fallwith added 2 commits April 4, 2024 20:45
Updates to support Ruby v3.3, while retaining support for Ruby v3.2
- updated `Makefile`
- added GHA workflows
@mrickard
Copy link
Member

@fallwith This is looking good to me! This coming week I should be able to check in a fork, and we can verify built-layer behavior.

fallwith added 13 commits May 6, 2024 11:05
Tell pip3 how to operate for this context
Fixes for Ruby CI workflow
Better align with other languages
- reformat YAML
- 3.2 and 3.3 are identical from what our CI and linter will give us
use the latest Ruby versions
GHA testing
Ruby GHA testing
outputs.value
use set-output to set the step's output
Ruby GHA:

- fix linter working dir
- fix 3.3 -> 33 helper
fallwith added 7 commits May 6, 2024 17:10
satisfy all outstanding RuboCop issues
silence the cop for the warning about unused named method args, as '_'
renaming them will impact testing
Given that we perform both `docker run` and `docker build` on the same
Dockerfile files, we need to have a `CMD` based operation instead of
only having `RUN` ones.
copy/paste typo fix
Dynamically adjust $LOAD_PATH prior to performing a `require` on New
Relic Ruby gem(s) to account for the possibility of the instrumented
Lambda function pointing to a gem path that does not match the path
expected by the New Relic layer.
The Ruby gem path needs the tiny version of 0
@chaudharysaket chaudharysaket merged commit 331c2ff into newrelic:master May 9, 2024
3 checks passed
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