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

[NR-347440] CFN template validate lambda integration logs #17

Open
wants to merge 44 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a32827d
created events for cloudwatch, s3 and validating logs are present in …
ahegdeNR Jan 15, 2025
2248acd
fixes
ahegdeNR Jan 17, 2025
7924022
fixes
ahegdeNR Jan 17, 2025
3df901e
fixes
ahegdeNR Jan 17, 2025
e14079c
fixes
ahegdeNR Jan 17, 2025
fd2eb85
fixes
ahegdeNR Jan 17, 2025
c9d7f6f
fixes
ahegdeNR Jan 17, 2025
b119f50
fixes
ahegdeNR Jan 17, 2025
5fc970f
fixes
ahegdeNR Jan 19, 2025
ce2b778
fixes
ahegdeNR Jan 19, 2025
244d0c1
fixes
ahegdeNR Jan 19, 2025
062ccfe
fixes
ahegdeNR Jan 20, 2025
363b1f2
fixes
ahegdeNR Jan 20, 2025
b9d8401
fixes
ahegdeNR Jan 21, 2025
96d9333
fixes
ahegdeNR Jan 21, 2025
0521e7d
fixes
ahegdeNR Jan 21, 2025
8c7f08f
fixes
ahegdeNR Jan 21, 2025
39d0ee1
fixes
ahegdeNR Jan 21, 2025
108ca4c
Merge branch 'develop' into NR-347440-e2e-event-creation
ahegdeNR Jan 22, 2025
a473916
fixes
ahegdeNR Jan 22, 2025
dfb4583
fixes
ahegdeNR Jan 29, 2025
73b80e6
fixes
ahegdeNR Feb 3, 2025
2a18eae
testing on pull request
ahegdeNR Feb 4, 2025
3511b81
testing on pull request
ahegdeNR Feb 4, 2025
7b99c52
fixes
ahegdeNR Feb 4, 2025
c0b5c07
fixes
ahegdeNR Feb 4, 2025
f070394
fixes
ahegdeNR Feb 4, 2025
7a8244d
fixes
ahegdeNR Feb 4, 2025
cf9ee11
fixes
ahegdeNR Feb 4, 2025
83d8ee0
fixes
ahegdeNR Feb 5, 2025
2820a28
fixes
ahegdeNR Feb 10, 2025
fa17d67
fixes
ahegdeNR Feb 10, 2025
99ab363
parallelised template build and made it run once only for the tests
ahegdeNR Feb 11, 2025
7faddac
fixes
ahegdeNR Feb 11, 2025
b72039f
send slack notification on failure
ahegdeNR Feb 11, 2025
262157c
fixes
ahegdeNR Feb 11, 2025
2150b04
fixes
ahegdeNR Feb 11, 2025
3612720
fixes
ahegdeNR Feb 11, 2025
eefc09c
fixes
ahegdeNR Feb 11, 2025
6ed1c9c
fixes
ahegdeNR Feb 11, 2025
ae7b378
fixes
ahegdeNR Feb 11, 2025
e1ece89
fixes
ahegdeNR Feb 11, 2025
6e4ed72
fixes
ahegdeNR Feb 11, 2025
5f9e08f
added e2e tests to run once every month as cron job
ahegdeNR Feb 11, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
go tool cover -html=coverage/coverage.out -o coverage/coverage.html

- name: Upload Coverage Report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: src/coverage/coverage.html
4 changes: 2 additions & 2 deletions .github/workflows/release-lambda-code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
cd ..

- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: log-forwarder-zip
path: |
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:

steps:
- name: Download Artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: log-forwarder-zip
path: ./build-artifacts
Expand Down
175 changes: 153 additions & 22 deletions .github/workflows/run-e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,81 @@
name: E2E Test Workflow

on:
pull_request:
branches:
- develop
- main
pull_request_review:
types:
- submitted
schedule:
- cron: '0 0 1 * *'

jobs:
run-e2e-tests:
build-templates:
if: github.event.review.state == 'approved'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
strategy:
matrix:
TEMPLATE_FILE: [lambda-template]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Install AWS SAM CLI
run: |
pip install aws-sam-cli

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ secrets.AWS_E2E_ROLE }}
aws-region: us-east-1

- name: Build SAM Application
env:
S3_BUCKET: unified-lambda-e2e-test-templates
run: |
sam build -u --template-file "${{ matrix.TEMPLATE_FILE }}.yaml" --build-dir ".aws-sam/build/${{ matrix.TEMPLATE_FILE }}"
sam package --s3-bucket "$S3_BUCKET" --template-file ".aws-sam/build/${{ matrix.TEMPLATE_FILE }}/template.yaml" --output-template-file ".aws-sam/build/${{ matrix.TEMPLATE_FILE }}/${{ matrix.TEMPLATE_FILE }}.yaml"

- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.TEMPLATE_FILE }}.yaml
path: .aws-sam/build/${{ matrix.TEMPLATE_FILE }}/${{ matrix.TEMPLATE_FILE }}.yaml

- name: Send failure notification to Slack
if: always()
uses: ravsamhq/notify-slack-action@v1
with:
status: ${{ job.status }}
notify_when: 'failure'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

run-e2e-tests-cloudwatch:
ahegdeNR marked this conversation as resolved.
Show resolved Hide resolved
needs: [build-templates]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
strategy:
matrix:
test-case: [test_logs_with_filter_pattern, test_logs_for_secret_manager, test_logs_for_invalid_log_group]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download Artifact
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try deploying using s3 reference instead of downloading it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried sam deploy -h command and checked the usage, --s3-bucket option is used to upload artifacts rather than referencing the file. So I think there's no other direct way that uploading and getting build templates to different jobs

uses: actions/download-artifact@v4
with:
path: build-artifacts

- name: Setup Go
uses: actions/setup-go@v5
with:
Expand All @@ -32,29 +91,101 @@ jobs:
role-to-assume: ${{ secrets.AWS_E2E_ROLE }}
aws-region: us-east-1

- name: Run e2e tests
- name: Run e2e tests for cloudwatch
env:
NEW_RELIC_USER_KEY: ${{ secrets.NEW_RELIC_USER_KEY }}
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
S3_BUCKET: unified-lambda-e2e-test-templates
run: |
cd e2e-tests/
./build-templates.sh

echo "Running s3 and cloudwatch trigger tests parallely"
./lambda-cloudwatch-trigger.sh &
pid1=$!
echo "Testing setting up cloudwatch trigger with PID: $pid1"

./lambda-s3-trigger.sh &
pid2=$!
echo "Testing setting up s3 trigger with PID: $pid2"

wait $pid1
wait $pid2
cd e2e-tests
./lambda-cloudwatch-trigger.sh ${{ matrix.test-case }}

- name: Send failure notification to Slack
if: always()
uses: ravsamhq/notify-slack-action@v1
with:
status: ${{ job.status }}
notify_when: 'failure'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

run-e2e-tests-s3:
needs: [build-templates]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
strategy:
matrix:
test-case: [test_logs_for_prefix, test_logs_for_secret_manager, test_logs_for_invalid_bucket_name]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download Artifact
uses: actions/download-artifact@v4
with:
path: build-artifacts

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Install AWS SAM CLI
run: |
pip install aws-sam-cli

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ secrets.AWS_E2E_ROLE }}
aws-region: us-east-1

- name: Run e2e tests for s3
env:
NEW_RELIC_USER_KEY: ${{ secrets.NEW_RELIC_USER_KEY }}
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
run: |
cd e2e-tests
./lambda-s3-trigger.sh ${{ matrix.test-case }}

- name: Send failure notification to Slack
if: always()
uses: ravsamhq/notify-slack-action@v1
with:
status: ${{ job.status }}
notify_when: 'failure'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

clean-up:
ahegdeNR marked this conversation as resolved.
Show resolved Hide resolved
needs: [run-e2e-tests-cloudwatch, run-e2e-tests-s3]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- name: Install AWS SAM CLI
run: |
pip install aws-sam-cli

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ secrets.AWS_E2E_ROLE }}
aws-region: us-east-1

- name: Delete Resources
env:
S3_BUCKET: unified-lambda-e2e-test-templates
run:
aws s3 rm "s3://$S3_BUCKET" --recursive
aws s3 rm "s3://$S3_BUCKET" --recursive

- name: Send failure notification to Slack
if: always()
uses: ravsamhq/notify-slack-action@v1
with:
status: ${{ job.status }}
notify_when: 'failure'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
17 changes: 0 additions & 17 deletions e2e-tests/build-templates.sh

This file was deleted.

4 changes: 4 additions & 0 deletions e2e-tests/common-scripts/entity_synthesis_param.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Entity synthesis Parameters , aws related params are dropped in pipeline.
instrumentation_provider=aws
instrumentation_name=lambda
instrumentation_version=1.0.0
110 changes: 110 additions & 0 deletions e2e-tests/common-scripts/logs-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

source test-configs.cfg
source entity_synthesis_param.cfg
source stack-scripts.sh

validate_logs_in_new_relic() {
user_key=$1
account_id=$2
attribute_key=$3
attribute_value=$4
log_message=$5

sleep_time=$SLEEP_TIME
attempt=1

while [[ $attempt -lt $MAX_RETRIES ]]; do
echo "Fetching logs from new relic for $attribute_key: $attribute_value"
sleep "$sleep_time"
response=$(fetch_new_relic_logs_api "$user_key" "$account_id" "$attribute_key" "$attribute_value")

if echo "$response" | grep -q "$log_message"; then
echo "Log event successfully found in New Relic."
validate_logs_meta_data "$response"
return 0
fi

if (( sleep_time < MAX_SLEEP_TIME )); then
sleep_time=$(( sleep_time * 2 ))
fi
echo "Log event not found in New Relic. Retrying in $sleep_time seconds..."
attempt=$((attempt + 1))
done

exit_with_error "Log event with $attribute_key: $attribute_value not found in New Relic. Error Received: $response"
}

validate_logs_not_present() {
ahegdeNR marked this conversation as resolved.
Show resolved Hide resolved
user_key=$1
account_id=$2
attribute_key=$3
attribute_value=$4
log_message=$5

sleep_time=$SLEEP_TIME
attempt=1

while [[ $attempt -lt $MAX_RETRIES ]]; do
echo "Fetching logs from new relic for $attribute_key: $attribute_value"
sleep "$sleep_time"
response=$(fetch_new_relic_logs_api "$user_key" "$account_id" "$attribute_key" "$attribute_value")

if echo "$response" | grep -q "$log_message"; then
exit_with_error "Log event found in New Relic. Validation failed"
fi

echo "Log event not found in New Relic. Retrying in $sleep_time seconds..."
attempt=$((attempt + 1))
done

echo "Log event with $attribute_key: $attribute_value not found in New Relic. Validation succeeded"
}

fetch_new_relic_logs_api() {
user_key=$1
account_id=$2
attribute_key=$3
attribute_value=$4

nrql_query="SELECT * FROM Log WHERE $attribute_key LIKE '%$attribute_value%' SINCE $TIME_RANGE ago"
query='{"query":"query($id: Int!, $nrql: Nrql!) { actor { account(id: $id) { nrql(query: $nrql) { results } } } }","variables":{"id":'$account_id',"nrql":"'$nrql_query'"}}'

response=$(curl -s -X POST \
-H "Content-Type: application/json" \
-H "API-Key: $user_key" \
-d "$query" \
https://api.newrelic.com/graphql)

echo "$response"
}

create_log_message() {
log_message=$1
filter_pattern=$2

UUID=$(uuidgen)
echo "RequestId: $UUID, message: $log_message, filter: $filter_pattern"
}

validate_logs_meta_data (){
response=$1

# Validate custom attributes
if ! echo "$response" | grep -q "\"$CUSTOM_ATTRIBUTE_KEY\":\"$CUSTOM_ATTRIBUTE_VALUE\""; then
exit_with_error "Custom attribute $CUSTOM_ATTRIBUTE_KEY with value $CUSTOM_ATTRIBUTE_VALUE not found in New Relic logs."
fi
echo "Custom attributes {attributeKey: $CUSTOM_ATTRIBUTE_KEY, attributeValue: $CUSTOM_ATTRIBUTE_VALUE} validated successfully."

# Validate common attributes
while IFS='=' read -r key value; do
if [[ $key == instrumentation_* ]]; then
new_key=$(echo "$key" | sed 's/_/./g')
if ! echo "$response" | grep -q "\"$new_key\":\"$value\""; then
exit_with_error "Entity synthesis attribute $new_key with value $value not found in New Relic logs."
fi
fi
done < entity_synthesis_param.cfg

echo "Entity synthesis attributes validated successfully."
}
Loading
Loading