-
Notifications
You must be signed in to change notification settings - Fork 2
E2E test cases for firehose #16
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
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1acdee6
E2E test cases for firehose
hrai-nr b1c3c87
Code fixes for aws sam installation
hrai-nr cdef57c
adding permission
hrai-nr 4fd02e7
debugging
hrai-nr 9391d40
debugging
hrai-nr d25d2be
changing code to add logic to validate logs
hrai-nr 3b7afc8
code refactor and added more testcases
hrai-nr 929052b
fixing typo
hrai-nr e118b08
bug fix
hrai-nr 3e94e4b
separating the temporary json
hrai-nr 2ba39a6
added logic for error handling
hrai-nr 6692cdd
making tests parallel using strategy matrix
hrai-nr dfb4688
adding develop branch
hrai-nr e7258a6
adding develop to workflow
hrai-nr 92066ad
code changes based on review comment more refactoring
hrai-nr 7d27aa0
fixing small bugs
hrai-nr a192385
changed to push
hrai-nr 3b8077b
code refactor based on review
hrai-nr ab360e0
fixing bug
hrai-nr 5dfdfdc
monir bug fix
hrai-nr d36583d
changing it to push
hrai-nr 36e1eaf
comment for aws related params
hrai-nr ee38e13
refactored code
hrai-nr aa05455
refactored code
hrai-nr 14a6819
refactored code for filter
hrai-nr 22eab8c
simplified the timestamp
hrai-nr a047924
chaniging pull_request to push
hrai-nr 21e9e29
separating build process
hrai-nr 338b48a
adding permission
hrai-nr b381032
adding bucket name and template name
hrai-nr 455001e
bug fix
hrai-nr a2fd393
changing to push
hrai-nr 58a39f3
e2e tests run on pr approval, on failure send notification to log-int…
ahegdeNR 3c7f764
added e2e tests to run once every month as cron job
ahegdeNR b950551
Merge pull request #21 from newrelic/e2e-tests-workflow-modification
ahegdeNR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
pull_request: | ||
branches: | ||
- main | ||
- develop | ||
|
||
jobs: | ||
validate-template-code: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: E2E Test Workflow For Firehose | ||
|
||
on: | ||
pull_request_review: | ||
types: | ||
- submitted | ||
schedule: | ||
- cron: '0 0 1 * *' | ||
|
||
jobs: | ||
deploy-and-test: | ||
if: github.event.review.state == 'approved' | ||
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 }} | ||
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 }} | ||
S3_BUCKET: unified-firehose-test-bucket | ||
TEMPLATE_FILE_NAME: firehose-template.yaml | ||
run: | | ||
cd e2e_tests/ | ||
./build_template.sh | ||
./firehose_e2e_tests.sh ${{ matrix.test-case }} | ||
hrai-nr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- 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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Building and deploying the changes | ||
BASE_NAME=$(basename "$TEMPLATE_FILE_NAME" .yaml) | ||
BUILD_DIR="$BASE_NAME" | ||
|
||
# Build and package the SAM template | ||
sam build --template-file "../$TEMPLATE_FILE_NAME" --build-dir "$BUILD_DIR" | ||
sam package --s3-bucket "$S3_BUCKET" --template-file "$BUILD_DIR/template.yaml" --output-template-file "$BUILD_DIR/$TEMPLATE_FILE_NAME" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/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_and_get_firehose_stream_arn() { | ||
local stack_name=$1 | ||
|
||
log "Retrieving Firehose stream ARN 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" | ||
fi | ||
|
||
echo "$firehose_stream_arn" | ||
} | ||
|
||
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_arn=$(validate_and_get_firehose_stream_arn "$stack_name") | ||
|
||
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 | ||
if echo "$subscriptions" | grep -q "$firehose_stream_arn"; then | ||
if [ -z "$log_group_filter" ] || [ "$log_group_filter" == "''" ]; then | ||
log "Firehose Delivery Stream $firehose_stream_arn is subscribed to log group: $log_group_name" | ||
elif 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 with filter: $log_group_filter" | ||
fi | ||
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" | ||
validate_and_get_firehose_stream_arn "$stack_name" | ||
|
||
} | ||
|
||
|
||
exit_with_error() { | ||
echo "Error: $1" | ||
exit 1 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
S3_BUCKET=unified-firehose-test-bucket | ||
NEW_RELIC_REGION=US | ||
NEW_RELIC_ACCOUNT_ID=2813435 | ||
TEMPLATE_FILE_NAME=firehose-template.yaml | ||
TEMPLATE_FILE_FULL_PATH=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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=firehose | ||
instrumentation_version=1.0.0 | ||
maya-jha marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.