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

E2E test cases for firehose #16

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1acdee6
E2E test cases for firehose
hrai-nr Jan 4, 2025
b1c3c87
Code fixes for aws sam installation
hrai-nr Jan 4, 2025
cdef57c
adding permission
hrai-nr Jan 4, 2025
4fd02e7
debugging
hrai-nr Jan 4, 2025
9391d40
debugging
hrai-nr Jan 4, 2025
d25d2be
changing code to add logic to validate logs
hrai-nr Jan 5, 2025
3b7afc8
code refactor and added more testcases
hrai-nr Jan 13, 2025
929052b
fixing typo
hrai-nr Jan 13, 2025
e118b08
bug fix
hrai-nr Jan 13, 2025
3e94e4b
separating the temporary json
hrai-nr Jan 13, 2025
2ba39a6
added logic for error handling
hrai-nr Jan 13, 2025
6692cdd
making tests parallel using strategy matrix
hrai-nr Jan 14, 2025
dfb4688
adding develop branch
hrai-nr Jan 14, 2025
e7258a6
adding develop to workflow
hrai-nr Jan 14, 2025
92066ad
code changes based on review comment more refactoring
hrai-nr Jan 16, 2025
7d27aa0
fixing small bugs
hrai-nr Jan 16, 2025
a192385
changed to push
hrai-nr Jan 16, 2025
3b8077b
code refactor based on review
hrai-nr Jan 19, 2025
ab360e0
fixing bug
hrai-nr Jan 19, 2025
5dfdfdc
monir bug fix
hrai-nr Jan 19, 2025
d36583d
changing it to push
hrai-nr Jan 19, 2025
36e1eaf
comment for aws related params
hrai-nr Jan 20, 2025
ee38e13
refactored code
hrai-nr Jan 21, 2025
aa05455
refactored code
hrai-nr Jan 21, 2025
14a6819
refactored code for filter
hrai-nr Jan 21, 2025
22eab8c
simplified the timestamp
hrai-nr Jan 21, 2025
a047924
chaniging pull_request to push
hrai-nr Jan 21, 2025
21e9e29
separating build process
hrai-nr Jan 21, 2025
338b48a
adding permission
hrai-nr Jan 21, 2025
b381032
adding bucket name and template name
hrai-nr Jan 21, 2025
455001e
bug fix
hrai-nr Jan 21, 2025
a2fd393
changing to push
hrai-nr Jan 21, 2025
58a39f3
e2e tests run on pr approval, on failure send notification to log-int…
ahegdeNR Feb 11, 2025
3c7f764
added e2e tests to run once every month as cron job
ahegdeNR Feb 11, 2025
b950551
Merge pull request #21 from newrelic/e2e-tests-workflow-modification
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
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- develop

jobs:
validate-template-code:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/run-e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: E2E Test Workflow For Firehose

on:
push:
branches:
- main
- develop

jobs:
deploy-and-test:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write

strategy:
matrix:
test-case: [test-without-filter, test-with-filter, test-with-invalid-log-group, test-with-secret-manager-false]

steps:
- name: Checkout code
uses: actions/checkout@v4

- 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_TEST_ROLE }}
hrai-nr marked this conversation as resolved.
Show resolved Hide resolved
aws-region: us-east-2

- name: Run end to end tests for Firehose
env:
NEW_RELIC_USER_KEY: ${{ secrets.NEW_RELIC_USER_KEY }}
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
run: |
cd e2e_tests/
./firehose_e2e_tests.sh ${{ matrix.test-case }}
hrai-nr marked this conversation as resolved.
Show resolved Hide resolved

141 changes: 141 additions & 0 deletions e2e_tests/common-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/bash

source config-file.cfg

log() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1"
}

deploy_firehose_stack() {
local template_file=$1
hrai-nr marked this conversation as resolved.
Show resolved Hide resolved
local stack_name=$2
local license_key=$3
local new_relic_region=$4
local new_relic_account_id=$5
local store_secret_in_secret_manager=$6
local log_group_config=$7
local common_attributes=$8

log "Deploying Firehose stack: $stack_name"
sam deploy \
--template-file "$template_file" \
--stack-name "$stack_name" \
--parameter-overrides \
LicenseKey="$license_key" \
NewRelicRegion="$new_relic_region" \
NewRelicAccountId="$new_relic_account_id" \
StoreNRLicenseKeyInSecretManager="$store_secret_in_secret_manager" \
LogGroupConfig="$log_group_config" \
CommonAttributes="$common_attributes" \
--capabilities CAPABILITY_NAMED_IAM
}

validate_stack_deployment_status() {
local stack_name=$1

log "Validating stack deployment status for the stack : $stack_name"
local stack_status=$(aws cloudformation describe-stacks --stack-name "$stack_name" --query "Stacks[0].StackStatus" --output text)
if [[ "$stack_status" == "ROLLBACK_COMPLETE" || "$stack_status" == "ROLLBACK_FAILED" || "$stack_status" == "CREATE_FAILED" || "$stack_status" == "UPDATE_FAILED" ]]; then
log "Stack $stack_name failed to be created and rolled back."
local failure_reason=$(aws cloudformation describe-stack-events --stack-name "$stack_name" --query "StackEvents[?ResourceStatus==\`$stack_status\`].ResourceStatusReason" --output text)
exit_with_error "Stack $stack_name failed to be created. Failure reason: $failure_reason"
else
log "Stack $stack_name was created successfully."
fi
}

delete_stack() {
stack_name=$1

log "Initiating deletion of stack: $stack_name"
aws cloudformation delete-stack --stack-name "$stack_name"

local stack_status=$(aws cloudformation describe-stacks --stack-name "$stack_name" --query 'Stacks[0].StackStatus' --output text)

# delete stack with exponential back off retires with max cap of 5 minutes
max_sleep_time=300
hrai-nr marked this conversation as resolved.
Show resolved Hide resolved
sleep_time=30
while [[ $stack_status == "DELETE_IN_PROGRESS" ]]; do
log "Stack $stack_name is still being deleted..."
sleep $sleep_time
if (( sleep_time < max_sleep_time )); then
sleep_time=$(( sleep_time * 2 ))
fi
stack_status=$(aws cloudformation describe-stacks --stack-name "$stack_name" --query 'Stacks[0].StackStatus' --output text 2>/dev/null || true)
done

if [ -z "$stack_status" ]; then
log "Stack $stack_name has been successfully deleted."
elif [ "$stack_status" == "DELETE_FAILED" ]; then
log "Failed to delete stack $stack_name."
else
log "Unexpected stack status: $stack_status."
fi
}

validate_stack_resources_with_subscription() {
local stack_name=$1
local log_group_name=$2
local log_group_filter=$3


log "Validating stack resources for stack: $stack_name"
firehose_stream_physical_id=$(aws cloudformation describe-stack-resources \
--stack-name "$stack_name" \
--logical-resource-id "$FIREHOSE_STREAM_LOGICAL_ID" \
--query "StackResources[0].PhysicalResourceId" \
--output text
)

# Get the ARN of the Firehose delivery stream using the physical ID
firehose_stream_arn=$(aws firehose describe-delivery-stream \
--delivery-stream-name "$firehose_stream_physical_id" \
--query "DeliveryStreamDescription.DeliveryStreamARN" \
--output text
)

# Check firehose_stream_arn is not null before checking subscriptions
if [ -z "$firehose_stream_arn" ] || [ "$firehose_stream_arn" == "None" ]; then
exit_with_error "Failed to retrieve Firehose delivery stream ARN for physical ID: $firehose_stream_physical_id"
fi

subscriptions=$(aws logs describe-subscription-filters --log-group-name "$log_group_name" --query 'subscriptionFilters[*].[destinationArn, filterPattern]' --output text)

# Check if the Firehose delivery stream is subscribed to the log group with the specified filter pattern
if echo "$subscriptions" | grep -q "$firehose_stream_arn" && echo "$subscriptions" | grep -q "$log_group_filter"; then
log "Firehose Delivery Stream $firehose_stream_arn is subscribed to log group: $log_group_name with filter: $log_group_filter"
else
exit_with_error "Firehose Delivery Stream $firehose_stream_arn is not subscribed to log group: $log_group_name"
fi

}

validate_stack_resources_without_subscription() {
hrai-nr marked this conversation as resolved.
Show resolved Hide resolved
local stack_name=$1

log "Validating stack resources for stack: $stack_name"
firehose_stream_physical_id=$(aws cloudformation describe-stack-resources \
--stack-name "$stack_name" \
--logical-resource-id "$FIREHOSE_STREAM_LOGICAL_ID" \
--query "StackResources[0].PhysicalResourceId" \
--output text
)

# Get the ARN of the Firehose delivery stream using the physical ID
firehose_stream_arn=$(aws firehose describe-delivery-stream \
--delivery-stream-name "$firehose_stream_physical_id" \
--query "DeliveryStreamDescription.DeliveryStreamARN" \
--output text
)

# Check firehose_stream_arn is not null
if [ -z "$firehose_stream_arn" ] || [ "$firehose_stream_arn" == "None" ]; then
exit_with_error "Failed to retrieve Firehose delivery stream ARN for physical ID: $firehose_stream_physical_id"
hrai-nr marked this conversation as resolved.
Show resolved Hide resolved
fi
}


exit_with_error() {
echo "Error: $1"
exit 1
}
24 changes: 24 additions & 0 deletions e2e_tests/config-file.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
S3_BUCKET=unified-firehose-test-bucket
NEW_RELIC_REGION=US
NEW_RELIC_ACCOUNT_ID=2813435
BUILD_DIR_BASE=.aws-sam/build
TEMPLATE_FILE_NAME=firehose-template.yaml
TEMPLATE_FILE_FULL_PATH=.aws-sam/build/firehose-template/firehose-template.yaml
LOG_STREAM_NAME=test-log-stream
LOG_GROUP_FILTER_PATTERN=ERROR
FIREHOSE_STREAM_LOGICAL_ID=NewRelicLogsFirehoseStreamToNewRelic
COMMON_ATTRIBUTE_KEY=testKey
COMMON_ATTRIBUTE_VALUE=testValue
# Variable for first test case
FIREHOSE_STACK_NAME_1=NewRelicFirehoseTestStackWithoutFilter
LOG_GROUP_NAME_1=aws-unified-firehose-e2e-test-log-group
# Variable for second test case
FIREHOSE_STACK_NAME_2=NewRelicFirehoseTestStackWithFilter
LOG_GROUP_NAME_2=aws-unified-firehose-e2e-test-log-group-2
# Variable for third test case
FIREHOSE_STACK_NAME_3=NewRelicFirehoseTestStackWithInvalidLogGroup
INVALID_LOG_GROUP_NAME=invalid_log_group
# Variable for fourth test case
FIREHOSE_STACK_NAME_4=NewRelicFirehoseTestStackWithSecretsManagerFalse
LOG_GROUP_NAME_4=aws-unified-firehose-e2e-test-log-group-3
SLEEP_TIME=15
4 changes: 4 additions & 0 deletions e2e_tests/entity_synthesis_param.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Entity synthesis Parameters , for aws related params they will be added later.
hrai-nr marked this conversation as resolved.
Show resolved Hide resolved
instrumentation_provider=aws
instrumentation_name=firehose
instrumentation_version=1.0.0
maya-jha marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading