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-352205] CFN template validate metrics with logging integration #22

Merged
merged 15 commits into from
Feb 25, 2025
54 changes: 52 additions & 2 deletions .github/workflows/run-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
contents: write
strategy:
matrix:
TEMPLATE_FILE: [lambda-template]
TEMPLATE_FILE: [lambda-template, logging-lambda-firehose-template, logging-lambda-metric-polling, logging-lambda-metric-stream, logging-firehose-metric-polling, logging-firehose-metric-stream, logging-lambda-firehose-metric-polling, logging-lambda-firehose-metric-stream]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -158,8 +158,58 @@ jobs:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

run-e2e-tests-lambda-firehose-metrics:
needs: [build-templates]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
strategy:
matrix:
test-case: [test_for_lambda_firehose_stack, test_for_firehose_metric_polling_stack, test_for_firehose_metric_streaming_stack, test_for_lambda_metrics_polling_stack, test_for_lambda_metrics_streaming_stack, test_for_lambda_firehose_metric_polling_stack, test_for_lambda_firehose_metric_streaming_stack]
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 lambda and metrics stack
env:
NEW_RELIC_USER_KEY: ${{ secrets.NEW_RELIC_USER_KEY }}
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
run: |
cd e2e-tests/
./lambda-with-metrics-test.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:
needs: [run-e2e-tests-cloudwatch, run-e2e-tests-s3]
needs: [run-e2e-tests-cloudwatch, run-e2e-tests-s3, run-e2e-tests-lambda-firehose-metrics]
runs-on: ubuntu-latest
permissions:
id-token: write
Expand Down
220 changes: 217 additions & 3 deletions e2e-tests/common-scripts/stack-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,232 @@ deploy_s3_trigger_stack() {
--capabilities CAPABILITY_IAM
}

deploy_lambda_firehose_stack() {
s3_bucket_names=$1
log_group_config=$2
common_attributes=$3
enable_cloudwatch_logging_for_firehose=$4
store_license_key_in_secret_manager=$5

echo "Deploying lambda-firehose stack with name: $LAMBDA_FIREHOSE_CASE"

aws cloudformation deploy \
--template-file "$TEMPLATE_BUILD_DIR/$LAMBDA_FIREHOSE_TEMPLATE" \
--stack-name "$LAMBDA_FIREHOSE_CASE" \
--parameter-overrides \
LicenseKey="$NEW_RELIC_LICENSE_KEY" \
NewRelicRegion="$NEW_RELIC_REGION" \
NewRelicAccountId="$NEW_RELIC_ACCOUNT_ID" \
S3BucketNames="$s3_bucket_names" \
LogGroupConfig="$log_group_config" \
CommonAttributes="$common_attributes" \
LoggingFirehoseStreamName="$LOGGING_STREAM_NAME-first" \
LoggingS3BackupBucketName="$LOGGING_BACKUP_BUCKET_NAME-first" \
EnableCloudWatchLoggingForFirehose="$enable_cloudwatch_logging_for_firehose" \
StoreNRLicenseKeyInSecretManager="$store_license_key_in_secret_manager" \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM
}

deploy_lambda_metric_polling_stack() {
log_group_config=$1
common_attributes=$2
store_license_key_in_secret_manager=$3
s3_bucket_names=$4

echo "Deploying lambda metric polling stack with name: $LAMBDA_METRIC_POLLING_CASE"

aws cloudformation deploy \
--template-file "$TEMPLATE_BUILD_DIR/$LAMBDA_METRIC_POLLING_TEMPLATE" \
--stack-name "$LAMBDA_METRIC_POLLING_CASE" \
--parameter-overrides \
IAMRoleName="$IAM_ROLE_NAME" \
NewRelicAccountId="$NEW_RELIC_ACCOUNT_ID" \
IntegrationName="$INTEGRATION_NAME" \
NewRelicAPIKey="$NEW_RELIC_USER_KEY" \
PollingIntegrationSlugs="$POLLING_INTEGRATION_SLUGS" \
NewRelicLicenseKey="$NEW_RELIC_LICENSE_KEY" \
NewRelicRegion="$NEW_RELIC_REGION" \
S3BucketNames="$s3_bucket_names" \
LogGroupConfig="$log_group_config" \
CommonAttributes="$common_attributes" \
StoreNRLicenseKeyInSecretManager="$store_license_key_in_secret_manager" \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM
}

deploy_lambda_metric_streaming_stack() {
log_group_config=$1
common_attributes=$2
store_license_key_in_secret_manager=$3
s3_bucket_names=$4

echo "Deploying lambda metric streaming stack with name: $LAMBDA_METRIC_STREAMING_CASE"

aws cloudformation deploy \
--template-file "$TEMPLATE_BUILD_DIR/$LAMBDA_METRIC_STREAMING_TEMPLATE" \
--stack-name "$LAMBDA_METRIC_STREAMING_CASE" \
--parameter-overrides \
IAMRoleName="$IAM_ROLE_NAME" \
NewRelicAccountId="$NEW_RELIC_ACCOUNT_ID" \
IntegrationName="$INTEGRATION_NAME" \
NewRelicAPIKey="$NEW_RELIC_USER_KEY" \
PollingIntegrationSlugs="$POLLING_INTEGRATION_SLUGS" \
NewRelicLicenseKey="$NEW_RELIC_LICENSE_KEY" \
NewRelicRegion="$NEW_RELIC_REGION" \
MetricCollectionMode="$METRIC_COLLECTION_MODE" \
FirehoseStreamName="$METRIC_STREAM_NAME-third" \
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this how you were able to override the stream name and could run tests in parallel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maya-jha yes that's right

CloudWatchMetricStreamName="$CLOUDWATCH_STREAM_NAME-third" \
S3BackupBucketName="$METRICS_BACKUP_BUCKET_NAME" \
CreateConfigService="false" \
S3ConfigBucketName="$S3_CONFIG_BUCKET_NAME" \
S3BucketNames="$s3_bucket_names" \
LogGroupConfig="$log_group_config" \
CommonAttributes="$common_attributes" \
StoreNRLicenseKeyInSecretManager="$store_license_key_in_secret_manager" \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM
}

deploy_firehose_metric_polling_stack() {
log_group_config=$1
common_attributes=$2
store_license_key_in_secret_manager=$3

echo "Deploying firehose metric polling stack with name: $FIREHOSE_METRIC_POLLING_CASE"

aws cloudformation deploy \
--template-file "$TEMPLATE_BUILD_DIR/$FIREHOSE_METRIC_POLLING_TEMPLATE" \
--stack-name "$FIREHOSE_METRIC_POLLING_CASE" \
--parameter-overrides \
IAMRoleName="$IAM_ROLE_NAME" \
NewRelicAccountId="$NEW_RELIC_ACCOUNT_ID" \
IntegrationName="$INTEGRATION_NAME" \
NewRelicAPIKey="$NEW_RELIC_USER_KEY" \
PollingIntegrationSlugs="$POLLING_INTEGRATION_SLUGS" \
NewRelicLicenseKey="$NEW_RELIC_LICENSE_KEY" \
NewRelicRegion="$NEW_RELIC_REGION" \
LogGroupConfig="$log_group_config" \
LoggingFirehoseStreamName="$LOGGING_STREAM_NAME-fourth" \
LoggingS3BackupBucketName="$LOGGING_BACKUP_BUCKET_NAME" \
EnableCloudWatchLoggingForFirehose="false" \
CommonAttributes="$common_attributes" \
StoreNRLicenseKeyInSecretManager="$store_license_key_in_secret_manager" \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM \
--disable-rollback
}

deploy_firehose_metric_streaming_stack() {
log_group_config=$1
common_attributes=$2
store_license_key_in_secret_manager=$3

echo "Deploying firehose metric streaming stack with name: $FIREHOSE_METRIC_STREAMING_CASE"

aws cloudformation deploy \
--template-file "$TEMPLATE_BUILD_DIR/$FIREHOSE_METRIC_STREAMING_TEMPLATE" \
--stack-name "$FIREHOSE_METRIC_STREAMING_CASE" \
--parameter-overrides \
IAMRoleName="$IAM_ROLE_NAME" \
NewRelicAccountId="$NEW_RELIC_ACCOUNT_ID" \
IntegrationName="$INTEGRATION_NAME" \
NewRelicAPIKey="$NEW_RELIC_USER_KEY" \
PollingIntegrationSlugs="$POLLING_INTEGRATION_SLUGS" \
MetricCollectionMode="$METRIC_COLLECTION_MODE" \
NewRelicLicenseKey="$NEW_RELIC_LICENSE_KEY" \
NewRelicRegion="$NEW_RELIC_REGION" \
LogGroupConfig="$log_group_config" \
FirehoseStreamName="$METRIC_STREAM_NAME-fifth" \
CloudWatchMetricStreamName="$CLOUDWATCH_STREAM_NAME-fifth" \
S3BackupBucketName="$METRICS_BACKUP_BUCKET_NAME" \
LoggingFirehoseStreamName="$LOGGING_STREAM_NAME-fifth" \
LoggingS3BackupBucketName="$LOGGING_BACKUP_BUCKET_NAME" \
CreateConfigService="false" \
S3ConfigBucketName="$S3_CONFIG_BUCKET_NAME" \
EnableCloudWatchLoggingForFirehose="false" \
CommonAttributes="$common_attributes" \
StoreNRLicenseKeyInSecretManager="$store_license_key_in_secret_manager" \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM \
--disable-rollback
}

deploy_lambda_firehose_metric_polling_stack() {
log_group_config=$1
common_attributes=$2
store_license_key_in_secret_manager=$3
s3_bucket_names=$4


echo "Deploying lambda firehose metric polling stack with name: $LAMBDA_FIREHOSE_METRIC_POLLING_CASE"

aws cloudformation deploy \
--template-file "$TEMPLATE_BUILD_DIR/$LAMBDA_FIREHOSE_METRIC_POLLING_TEMPLATE" \
--stack-name "$LAMBDA_FIREHOSE_METRIC_POLLING_CASE" \
--parameter-overrides \
IAMRoleName="$IAM_ROLE_NAME" \
NewRelicAccountId="$NEW_RELIC_ACCOUNT_ID" \
IntegrationName="$INTEGRATION_NAME" \
NewRelicAPIKey="$NEW_RELIC_USER_KEY" \
PollingIntegrationSlugs="$POLLING_INTEGRATION_SLUGS" \
NewRelicLicenseKey="$NEW_RELIC_LICENSE_KEY" \
NewRelicRegion="$NEW_RELIC_REGION" \
LogGroupConfig="$log_group_config" \
S3BucketNames="$s3_bucket_names" \
LoggingFirehoseStreamName="$LOGGING_STREAM_NAME-sixth" \
LoggingS3BackupBucketName="$LOGGING_BACKUP_BUCKET_NAME" \
EnableCloudWatchLoggingForFirehose="false" \
CommonAttributes="$common_attributes" \
StoreNRLicenseKeyInSecretManager="$store_license_key_in_secret_manager" \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM \
--disable-rollback
}

deploy_lambda_firehose_metric_streaming_stack() {
log_group_config=$1
common_attributes=$2
store_license_key_in_secret_manager=$3
s3_bucket_names=$4


echo "Deploying lambda firehose metric streaming stack with name: $LAMBDA_FIREHOSE_METRIC_STREAMING_CASE"

aws cloudformation deploy \
--template-file "$TEMPLATE_BUILD_DIR/$LAMBDA_FIREHOSE_METRIC_STREAMING_TEMPLATE" \
--stack-name "$LAMBDA_FIREHOSE_METRIC_STREAMING_CASE" \
--parameter-overrides \
IAMRoleName="$IAM_ROLE_NAME" \
NewRelicAccountId="$NEW_RELIC_ACCOUNT_ID" \
IntegrationName="$INTEGRATION_NAME" \
NewRelicAPIKey="$NEW_RELIC_USER_KEY" \
PollingIntegrationSlugs="$POLLING_INTEGRATION_SLUGS" \
MetricCollectionMode="$METRIC_COLLECTION_MODE" \
NewRelicLicenseKey="$NEW_RELIC_LICENSE_KEY" \
NewRelicRegion="$NEW_RELIC_REGION" \
LogGroupConfig="$log_group_config" \
S3BucketNames="$s3_bucket_names" \
FirehoseStreamName="$METRIC_STREAM_NAME-seventh" \
CloudWatchMetricStreamName="$CLOUDWATCH_STREAM_NAME-seventh" \
S3BackupBucketName="$METRICS_BACKUP_BUCKET_NAME" \
LoggingFirehoseStreamName="$LOGGING_STREAM_NAME-seventh" \
LoggingS3BackupBucketName="$LOGGING_BACKUP_BUCKET_NAME" \
CreateConfigService="false" \
S3ConfigBucketName="$S3_CONFIG_BUCKET_NAME" \
EnableCloudWatchLoggingForFirehose="false" \
CommonAttributes="$common_attributes" \
StoreNRLicenseKeyInSecretManager="$store_license_key_in_secret_manager" \
--capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND CAPABILITY_NAMED_IAM \
--disable-rollback
}

validate_stack_deployment_status() {
stack_name=$1

echo "Validating stack deployment status for stack name: $stack_name"

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
if [[ "$stack_status" == "CREATE_COMPLETE" ]]; then
echo "Stack $stack_name was created successfully."
else
echo "Stack $stack_name failed to be created and rolled back."
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
echo "Stack $stack_name was created successfully."
fi
}

Expand Down
30 changes: 30 additions & 0 deletions e2e-tests/common-scripts/test-configs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,25 @@ S3_PREFIX_CASE=e2e-s3-prefix-test
S3_SECRET_MANAGER_CASE=e2e-s3-secret-manager-test
S3_INVALID_BUCKET_CASE=e2e-s3-invalid-bucket-test

FIREHOSE_METRIC_POLLING_CASE=e2e-firehose-metric-polling-test
FIREHOSE_METRIC_STREAMING_CASE=e2e-firehose-metric-streaming-test
LAMBDA_FIREHOSE_METRIC_POLLING_CASE=e2e-lambda-firehose-metric-polling-test
LAMBDA_FIREHOSE_METRIC_STREAMING_CASE=e2e-lambda-firehose-metric-streaming-test
LAMBDA_METRIC_POLLING_CASE=e2e-lambda-metric-polling-test
LAMBDA_METRIC_STREAMING_CASE=e2e-lambda-metric-streaming-test
LAMBDA_FIREHOSE_CASE=e2e-lambda-firehose-test

# template constants
LAMBDA_TEMPLATE=lambda-template.yaml/lambda-template.yaml
TEMPLATE_BUILD_DIR=../build-artifacts
LAMBDA_LOGICAL_RESOURCE_ID=NewRelicLogsServerlessLogForwarder
FIREHOSE_METRIC_POLLING_TEMPLATE=logging-firehose-metric-polling.yaml/logging-firehose-metric-polling.yaml
FIREHOSE_METRIC_STREAMING_TEMPLATE=logging-firehose-metric-stream.yaml/logging-firehose-metric-stream.yaml
LAMBDA_FIREHOSE_METRIC_POLLING_TEMPLATE=logging-lambda-firehose-metric-polling.yaml/logging-lambda-firehose-metric-polling.yaml
LAMBDA_FIREHOSE_METRIC_STREAMING_TEMPLATE=logging-lambda-firehose-metric-stream.yaml/logging-lambda-firehose-metric-stream.yaml
LAMBDA_METRIC_POLLING_TEMPLATE=logging-lambda-metric-polling.yaml/logging-lambda-metric-polling.yaml
LAMBDA_METRIC_STREAMING_TEMPLATE=logging-lambda-metric-stream.yaml/logging-lambda-metric-stream.yaml
LAMBDA_FIREHOSE_TEMPLATE=logging-lambda-firehose-template.yaml/logging-lambda-firehose-template.yaml

# deployment constants for s3 bucket cases
S3_BUCKET_NAME=aws-unified-lambda-e2e-test-bucket
Expand All @@ -32,6 +47,21 @@ LOG_GROUP_NAME_INVALID=aws-unified-lambda-e2e-test-log-group-invalid
LOG_GROUP_FILTER_PATTERN=ERROR
LOG_STREAM_NAME=aws-unified-lambda-e2e-test-stream

# deployment constants for logging and metrics template cases
LOG_GROUP_NAME_METRICS_CASE=aws-unified-lambda-e2e-test-log-group-metrics-case
S3_BUCKET_NAME_METRICS_CASE=aws-unified-lambda-e2e-test-bucket-metrics-case

IAM_ROLE_NAME=NewRelicInfrastructure-Integrations
INTEGRATION_NAME=AWS-API-Polling-2025Feb11D10H48M12S
METRICS_BACKUP_BUCKET_NAME=firehose-backup
LOGGING_BACKUP_BUCKET_NAME=firehose-logging-backup
POLLING_INTEGRATION_SLUGS=apigateway
METRIC_COLLECTION_MODE=PUSH
S3_CONFIG_BUCKET_NAME=config-backup
METRIC_STREAM_NAME=NewRelic-Delivery-Stream
CLOUDWATCH_STREAM_NAME=NewRelic-Metric-Stream
LOGGING_STREAM_NAME=NewRelic-Logging-Delivery-Stream

# fetch nr logs constants
LOG_MESSAGE_CLOUDWATCH="This is cloudwatch logs"
LOG_MESSAGE_S3="This is s3 logs"
Expand Down
Loading
Loading