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

NH-82144 and NH-81061: multi-runtime lambda layer #131

Merged
merged 9 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions .github/workflows/build_publish_lambda_layer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,28 @@ jobs:
- arm64
runs-on: ${{ matrix.arch == 'arm64' && fromJSON(needs.start_arm64_runner.outputs.matrix)['ubuntu:22.04'].label || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Install additional package for self runner
- name: Install additional package for ${{ matrix.arch }}
if: ${{ matrix.arch == 'arm64'}}
run: |
sudo apt-get update
echo y | sudo apt-get upgrade
echo y | sudo apt-get install python3.10-venv

- uses: aws-actions/setup-sam@v2

# Build inside Docker containers
# -u in sam build will automatically set LAMBDA_TASK_ROOT (see: https://github.com/aws/aws-sam-cli/issues/3407)
- name: build lambda layer
- name: Build ruby lambda layer
run: |
uname -a
cd lambda/
sam build -u -t template.yml -e BUNDLE_RUBYGEMS__PKG__GITHUB__COM=$GITHUB_RUBY_TOKEN --parameter-overrides LayerArchitecture=${{ matrix.arch }}
./zip_layer.sh -n ruby-layer-${{ matrix.arch }}
./build.sh
shell: bash
working-directory: lambda/
env:
GITHUB_RUBY_TOKEN: ${{ secrets.PACKAGE_GITHUB_TOKEN }}
MATRIX_ARCH: ${{ matrix.arch }}

- name: Show directory contents
run: |
ls -al
working-directory: lambda/

- name: Upload to artifact
uses: actions/upload-artifact@v4
with:
name: ruby-layer-${{ matrix.arch }}.zip
path: lambda
path: lambda/build/ruby-layer-${{ matrix.arch }}.zip

# extract the built layer from artifacts, then publish it based on region
publish_layer:
Expand All @@ -100,6 +94,8 @@ jobs:
- x86_64
- arm64
steps:
- uses: actions/checkout@v4

- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.LAMBDA_PUBLISHER_ARN }}
Expand All @@ -113,26 +109,26 @@ jobs:

- name: extract current solarwinds_apm version
run: |
APM_VERSION=$(grep "gem 'solarwinds_apm'" lambda/layer/Gemfile | awk -F"'" '{print $4}')
APM_VERSION=$(grep "gem 'solarwinds_apm'" lambda/otel/layer/Gemfile | awk -F"'" '{print $4}')
APM_VERSION="${APM_VERSION//./_}"
echo "SOLARWINDS_APM_VERSION=$APM_VERSION" >> $GITHUB_ENV

- name: publish lambda layer
run: |
cd lambda/
aws lambda publish-layer-version \
--layer-name solarwinds-apm-ruby-${{ matrix.arch }}-$SOLARWINDS_APM_VERSION \
--layer-name solarwinds-apm-ruby-${{ matrix.arch }}-${{ env.SOLARWINDS_APM_VERSION }} \
--license-info "Apache 2.0" \
--compatible-architectures ${{ matrix.arch }} \
--compatible-runtimes ruby3.2 \
--compatible-runtimes ruby3.2 ruby3.3 \
--zip-file fileb://ruby-layer-${{ matrix.arch }}.zip \
--query 'LayerVersionArn' \
--compatible-architectures ${{ matrix.arch }} \
--output text

- name: grant permissions to public for the published layer
run: |
layer_name=solarwinds-apm-ruby-${{ matrix.arch }}-$SOLARWINDS_APM_VERSION
layer_name=solarwinds-apm-ruby-${{ matrix.arch }}-${{ env.SOLARWINDS_APM_VERSION }}
latest_version=$(aws lambda list-layer-versions --layer-name $layer_name | jq -r '.LayerVersions | max_by(.Version) | .Version')
aws lambda add-layer-version-permission \
--layer-name $layer_name \
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ vendor/
*.DS_Store
apm.collector.st-ssp.solarwinds.com
appoptics.com
*Makefile
test/clib/Makefile
*.so
*.o

Expand Down Expand Up @@ -77,3 +77,4 @@ act.secrets
lambda/.aws-sam/*
lambda/*.zip
*.zip
lambda/build/*
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ https://github.com/solarwinds/apm-ruby/releases

Dates in this file are in the format MM/DD/YYYY.

# solarwinds_apm 6.0.1 (06/20/2024)

This release includes the following features:

* Documentation update.
* Reduce the length pf rubocop config file.
* Oboe version update to 15.0.1.

# solarwinds_apm 6.0.0 (04/11/2024)

This release includes the following features:
Expand Down
2 changes: 1 addition & 1 deletion lambda/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SolarWinds Lambda Ruby Layer

## Building Lambda Ruby Layer With OpenTelemetry Ruby Dependencies
## Building Lambda Ruby Layer With OpenTelemetry Ruby Dependencies Using SAM

Build
```bash
Expand Down
24 changes: 24 additions & 0 deletions lambda/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
set -e

mkdir -p build

docker build --build-arg BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${GITHUB_RUBY_TOKEN} \
--progress plain \
-f otel/Dockerfile_3_2 \
-t sw-lambda-ruby-layer-3-2 otel

docker run --rm -v "$(pwd)/build:/out" sw-lambda-ruby-layer-3-2

docker build --build-arg BUNDLE_RUBYGEMS__PKG__GITHUB__COM=${GITHUB_RUBY_TOKEN} \
--progress plain \
-f otel/Dockerfile_3_3 \
-t sw-lambda-ruby-layer-3-3 otel

docker run --rm -v "$(pwd)/build:/out" sw-lambda-ruby-layer-3-3

cd build/
mkdir solarwinds-apm && mkdir ruby && mkdir ruby/gems
unzip gems-3.2.0.zip -d ruby/gems/ && unzip gems-3.3.0.zip -d ruby/gems/
cp ../otel/layer/otel_wrapper.rb . && cp ../otel/layer/wrapper solarwinds-apm/
zip -r ruby-layer-$MATRIX_ARCH.zip ruby/ solarwinds-apm/ otel_wrapper.rb
16 changes: 16 additions & 0 deletions lambda/otel/Dockerfile_3_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM public.ecr.aws/sam/build-ruby3.2:latest

ARG BUNDLE_RUBYGEMS__PKG__GITHUB__COM
ENV LAMBDA_TASK_ROOT=/fake_lambda_task_root/

RUN mkdir /build
COPY . /build

WORKDIR /build/layer
RUN bundle config set --local path 'ruby'
RUN bundle update

WORKDIR /build/layer/ruby/ruby
RUN zip -r gems-3.2.0.zip 3.2.0/

CMD cp /build/layer/ruby/ruby/gems-3.2.0.zip /out/gems-3.2.0.zip
16 changes: 16 additions & 0 deletions lambda/otel/Dockerfile_3_3
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM public.ecr.aws/sam/build-ruby3.3:latest

ARG BUNDLE_RUBYGEMS__PKG__GITHUB__COM
ENV LAMBDA_TASK_ROOT=/fake_lambda_task_root/

RUN mkdir /build
COPY . /build

WORKDIR /build/layer
RUN bundle config set --local path 'ruby'
RUN bundle update

WORKDIR /build/layer/ruby/ruby
RUN zip -r gems-3.3.0.zip 3.3.0/

CMD cp /build/layer/ruby/ruby/gems-3.3.0.zip /out/gems-3.3.0.zip
8 changes: 2 additions & 6 deletions lambda/layer/Gemfile → lambda/otel/layer/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

source 'https://rubygems.org'

gem 'opentelemetry-instrumentation-aws_lambda', '~> 0.1.0'

source 'https://rubygems.pkg.github.com/xuan-cao-swi' do
gem 'solarwinds_apm', '6.0.0.prev7'
end

source 'https://rubygems.pkg.github.com/solarwinds' do
gem 'opentelemetry-exporter-otlp', '0.26.1'
gem 'opentelemetry-metrics-api', '0.0.1'
gem 'opentelemetry-metrics-sdk', '0.0.1'
end

gem 'solarwinds_apm', '6.0.1'
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'opentelemetry-metrics-api'
require 'opentelemetry-metrics-sdk'
require 'opentelemetry-exporter-otlp'
require 'opentelemetry-instrumentation-aws_lambda'
require 'solarwinds_apm'

def otel_wrapper(event:, context:)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lambda/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Resources:
Properties:
LayerName: !Ref LayerName
Description: Opentelemetry Ruby layer
ContentUri: ./layer
ContentUri: ./otel/layer
CompatibleRuntimes:
- ruby3.2
Metadata:
Expand Down