From 8f6db23e5d375f47e9d5756d5d4a781a1bb26be2 Mon Sep 17 00:00:00 2001 From: mrickard Date: Fri, 2 Feb 2024 10:15:40 -0500 Subject: [PATCH 1/5] chore: Updated test fixtures and rename test policy fixture Signed-off-by: mrickard --- tests/fixtures/arm64.output.service.json | 4 ++-- tests/fixtures/debug-log-level.output.service.json | 4 ++-- tests/fixtures/debug.output.service.json | 4 ++-- .../distributed-tracing-enabled.output.service.json | 4 ++-- tests/fixtures/eu.output.service.json | 4 ++-- tests/fixtures/function-has-layers.output.service.json | 4 ++-- tests/fixtures/include.output.service.json | 2 +- .../includes-all-provider-layer.output.service.json | 2 +- .../fixtures/lambda-extension-disabled.output.service.json | 4 ++-- tests/fixtures/lambda-extension-enabled.output.service.json | 4 ++-- .../license-key-secret-disabled.output.service.json | 4 ++-- tests/fixtures/log-disabled.output.service.json | 4 ++-- .../log-ingestion-via-extension.output.service.json | 4 ++-- tests/fixtures/log-level.output.service.json | 4 ++-- tests/fixtures/manual-wrapping.output.service.json | 2 +- tests/fixtures/node-versions.output.service.json | 6 +++--- .../provider-environment-log-level.output.service.json | 4 ++-- tests/fixtures/provider-environment.output.service.json | 4 ++-- tests/fixtures/provider-layer.output.service.json | 2 +- tests/fixtures/proxy.output.service.json | 4 ++-- tests/fixtures/stage-included.output.service.json | 4 ++-- .../trusted-account-key-excluded.output.service.json | 4 ++-- .../trusted-account-key-included.output.service.json | 4 ++-- tests/{paginatedResults.json => paginatedPoliciesList.json} | 0 24 files changed, 43 insertions(+), 43 deletions(-) rename tests/{paginatedResults.json => paginatedPoliciesList.json} (100%) diff --git a/tests/fixtures/arm64.output.service.json b/tests/fixtures/arm64.output.service.json index 37d13410..a5b12f47 100644 --- a/tests/fixtures/arm64.output.service.json +++ b/tests/fixtures/arm64.output.service.json @@ -24,7 +24,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16XARM64:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16XARM64:83" ], "package": { "exclude": [ @@ -52,7 +52,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18XARM64:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18XARM64:58" ], "package": { "exclude": [ diff --git a/tests/fixtures/debug-log-level.output.service.json b/tests/fixtures/debug-log-level.output.service.json index 279d9764..531db348 100644 --- a/tests/fixtures/debug-log-level.output.service.json +++ b/tests/fixtures/debug-log-level.output.service.json @@ -32,7 +32,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -54,7 +54,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/debug.output.service.json b/tests/fixtures/debug.output.service.json index c8aa74d0..13366769 100644 --- a/tests/fixtures/debug.output.service.json +++ b/tests/fixtures/debug.output.service.json @@ -31,7 +31,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -53,7 +53,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/distributed-tracing-enabled.output.service.json b/tests/fixtures/distributed-tracing-enabled.output.service.json index fc05d2a5..50e310c5 100644 --- a/tests/fixtures/distributed-tracing-enabled.output.service.json +++ b/tests/fixtures/distributed-tracing-enabled.output.service.json @@ -26,7 +26,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -50,7 +50,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/eu.output.service.json b/tests/fixtures/eu.output.service.json index 97fc493c..c438c791 100644 --- a/tests/fixtures/eu.output.service.json +++ b/tests/fixtures/eu.output.service.json @@ -29,7 +29,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -55,7 +55,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/function-has-layers.output.service.json b/tests/fixtures/function-has-layers.output.service.json index 08244030..6383054f 100644 --- a/tests/fixtures/function-has-layers.output.service.json +++ b/tests/fixtures/function-has-layers.output.service.json @@ -2,7 +2,7 @@ "service": "newrelic-lambda-layers-nodejs-example", "provider": { "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "name": "aws", "stage": "prod", @@ -46,7 +46,7 @@ "runtime": "nodejs18.x", "layers": [ "arn:aws:lambda:us-east-1:123456789012:layer:SomeOtherLayer:1", - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ] }, "layer-nodejs18x2": { diff --git a/tests/fixtures/include.output.service.json b/tests/fixtures/include.output.service.json index 9b3b936a..fde86e36 100644 --- a/tests/fixtures/include.output.service.json +++ b/tests/fixtures/include.output.service.json @@ -43,7 +43,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": [ "./**", diff --git a/tests/fixtures/includes-all-provider-layer.output.service.json b/tests/fixtures/includes-all-provider-layer.output.service.json index 7bd6f83c..09d43609 100644 --- a/tests/fixtures/includes-all-provider-layer.output.service.json +++ b/tests/fixtures/includes-all-provider-layer.output.service.json @@ -2,7 +2,7 @@ "service": "newrelic-lambda-layers-nodejs-example", "provider": { "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "name": "aws", "stage": "prod", diff --git a/tests/fixtures/lambda-extension-disabled.output.service.json b/tests/fixtures/lambda-extension-disabled.output.service.json index 15cfb61e..fa9c47d7 100644 --- a/tests/fixtures/lambda-extension-disabled.output.service.json +++ b/tests/fixtures/lambda-extension-disabled.output.service.json @@ -25,7 +25,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -49,7 +49,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/lambda-extension-enabled.output.service.json b/tests/fixtures/lambda-extension-enabled.output.service.json index 81f09c59..7cffb6cc 100644 --- a/tests/fixtures/lambda-extension-enabled.output.service.json +++ b/tests/fixtures/lambda-extension-enabled.output.service.json @@ -24,7 +24,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -47,7 +47,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/license-key-secret-disabled.output.service.json b/tests/fixtures/license-key-secret-disabled.output.service.json index 1ce37120..320058aa 100644 --- a/tests/fixtures/license-key-secret-disabled.output.service.json +++ b/tests/fixtures/license-key-secret-disabled.output.service.json @@ -25,7 +25,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": [ @@ -53,7 +53,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": [ diff --git a/tests/fixtures/log-disabled.output.service.json b/tests/fixtures/log-disabled.output.service.json index ddf3567b..302b7ecf 100644 --- a/tests/fixtures/log-disabled.output.service.json +++ b/tests/fixtures/log-disabled.output.service.json @@ -31,7 +31,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -50,7 +50,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/log-ingestion-via-extension.output.service.json b/tests/fixtures/log-ingestion-via-extension.output.service.json index ec63f9a3..c3bc88bf 100644 --- a/tests/fixtures/log-ingestion-via-extension.output.service.json +++ b/tests/fixtures/log-ingestion-via-extension.output.service.json @@ -28,7 +28,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": [ @@ -57,7 +57,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": [ diff --git a/tests/fixtures/log-level.output.service.json b/tests/fixtures/log-level.output.service.json index 52c2851d..51bfcfba 100644 --- a/tests/fixtures/log-level.output.service.json +++ b/tests/fixtures/log-level.output.service.json @@ -31,7 +31,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -53,7 +53,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/manual-wrapping.output.service.json b/tests/fixtures/manual-wrapping.output.service.json index 369cdcb7..3082eaa5 100644 --- a/tests/fixtures/manual-wrapping.output.service.json +++ b/tests/fixtures/manual-wrapping.output.service.json @@ -40,7 +40,7 @@ ], "provider": { "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "name": "aws", "region": "us-east-1", diff --git a/tests/fixtures/node-versions.output.service.json b/tests/fixtures/node-versions.output.service.json index c53eabff..11f149ad 100644 --- a/tests/fixtures/node-versions.output.service.json +++ b/tests/fixtures/node-versions.output.service.json @@ -29,7 +29,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -48,7 +48,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -67,7 +67,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS20X:5" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS20X:8" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/provider-environment-log-level.output.service.json b/tests/fixtures/provider-environment-log-level.output.service.json index 0b1622c3..a196ebdd 100644 --- a/tests/fixtures/provider-environment-log-level.output.service.json +++ b/tests/fixtures/provider-environment-log-level.output.service.json @@ -34,7 +34,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -56,7 +56,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/provider-environment.output.service.json b/tests/fixtures/provider-environment.output.service.json index dca5925f..a69d2c75 100644 --- a/tests/fixtures/provider-environment.output.service.json +++ b/tests/fixtures/provider-environment.output.service.json @@ -33,7 +33,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -55,7 +55,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/provider-layer.output.service.json b/tests/fixtures/provider-layer.output.service.json index b0e93db2..305b9999 100644 --- a/tests/fixtures/provider-layer.output.service.json +++ b/tests/fixtures/provider-layer.output.service.json @@ -2,7 +2,7 @@ "service": "newrelic-lambda-layers-nodejs-example", "provider": { "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "name": "aws", "stage": "prod", diff --git a/tests/fixtures/proxy.output.service.json b/tests/fixtures/proxy.output.service.json index 66522e4c..f3e50dc9 100644 --- a/tests/fixtures/proxy.output.service.json +++ b/tests/fixtures/proxy.output.service.json @@ -24,7 +24,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": [ @@ -52,7 +52,7 @@ ], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": [ diff --git a/tests/fixtures/stage-included.output.service.json b/tests/fixtures/stage-included.output.service.json index 3887af35..7e0502f5 100644 --- a/tests/fixtures/stage-included.output.service.json +++ b/tests/fixtures/stage-included.output.service.json @@ -30,7 +30,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -49,7 +49,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/trusted-account-key-excluded.output.service.json b/tests/fixtures/trusted-account-key-excluded.output.service.json index b2e86d37..9eea824d 100644 --- a/tests/fixtures/trusted-account-key-excluded.output.service.json +++ b/tests/fixtures/trusted-account-key-excluded.output.service.json @@ -29,7 +29,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -48,7 +48,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/fixtures/trusted-account-key-included.output.service.json b/tests/fixtures/trusted-account-key-included.output.service.json index 7f877c4b..9838e87d 100644 --- a/tests/fixtures/trusted-account-key-included.output.service.json +++ b/tests/fixtures/trusted-account-key-included.output.service.json @@ -30,7 +30,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:80" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS16X:83" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], @@ -49,7 +49,7 @@ "events": [{ "schedule": "rate(5 minutes)" }], "handler": "newrelic-lambda-wrapper.handler", "layers": [ - "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:55" + "arn:aws:lambda:us-east-1:451483290750:layer:NewRelicNodeJS18X:58" ], "package": { "exclude": ["./**", "!newrelic-wrapper-helper.js"], diff --git a/tests/paginatedResults.json b/tests/paginatedPoliciesList.json similarity index 100% rename from tests/paginatedResults.json rename to tests/paginatedPoliciesList.json From 29e8f912dd7037bca97b919894ff8a9bfa4a5b17 Mon Sep 17 00:00:00 2001 From: mrickard Date: Mon, 5 Feb 2024 16:37:14 -0500 Subject: [PATCH 2/5] chore: Refactored newrelic-log-ingestion request to paginate through the listFunctions response, rather than assuming getFunction will match. (It won't.) Moved aws.request-using methods from index.ts to integration.ts, for testability Signed-off-by: mrickard --- src/index.ts | 351 +---------------------------------------- src/integration.ts | 383 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 391 insertions(+), 343 deletions(-) diff --git a/src/index.ts b/src/index.ts index 54f00349..f7fe74de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,13 +7,6 @@ import { fetchLicenseKey, nerdgraphFetch } from "./api"; import Integration from "./integration"; import { waitForStatus } from "./utils"; -const DEFAULT_FILTER_PATTERNS = [ - "REPORT", - "NR_LAMBDA_MONITORING", - "Task timed out", - "RequestId", -]; - const enum JavaHandler { handleRequest = "handleRequest", handleStreamsRequest = "handleStreamsRequest", @@ -176,6 +169,14 @@ https://blog.newrelic.com/product-news/aws-lambda-extensions-integrations/ return new Integration(this).check(); } + public addLogSubscriptions() { + return new Integration(this).addLogSubscriptions(); + } + + public removeLogSubscriptions() { + return new Integration(this).removeLogSubscriptions(); + } + public async checkForSecretPolicy() { return new Integration(this).checkForManagedSecretPolicy(); } @@ -420,69 +421,6 @@ or make sure that you already have Serverless 3.x installed in your project. // any cleanup can happen here. Previously used for Node 8. } - public async addLogSubscriptions() { - if (this.autoSubscriptionDisabled) { - this.log.notice("Skipping adding log subscription. Explicitly disabled"); - return; - } - - const funcs = this.functions; - let { cloudWatchFilter = [...DEFAULT_FILTER_PATTERNS] } = this.config; - - let cloudWatchFilterString = ""; - if ( - typeof cloudWatchFilter === "object" && - cloudWatchFilter.indexOf("*") === -1 - ) { - cloudWatchFilter = cloudWatchFilter.map((el) => `?\"${el}\"`); - cloudWatchFilterString = cloudWatchFilter.join(" "); - } else if (cloudWatchFilter.indexOf("*") === -1) { - cloudWatchFilterString = String(cloudWatchFilter); - } - - this.log.notice(`log filter: ${cloudWatchFilterString}`); - - const promises = []; - - for (const funcName of Object.keys(funcs)) { - if (this.shouldSkipFunction(funcName)) { - return; - } - - this.log.notice(`Configuring New Relic log subscription for ${funcName}`); - - const funcDef = funcs[funcName]; - promises.push( - this.ensureLogSubscription(funcDef.name, cloudWatchFilterString) - ); - } - - await Promise.all(promises); - - if (this.extFellBackToCW) { - this.log.notice(this.extFallbackMessage); - } - } - - public async removeLogSubscriptions() { - if (this.autoSubscriptionDisabled) { - this.log.notice( - "Skipping removing log subscription. Explicitly disabled" - ); - return; - } - const funcs = this.functions; - const promises = []; - - for (const funcName of Object.keys(funcs)) { - const { name } = funcs[funcName]; - this.log.notice(`Removing New Relic log subscription for ${funcName}`); - promises.push(this.removeSubscriptionFilter(name)); - } - - await Promise.all(promises); - } - private async addLayer( funcName: string, funcDef: any, @@ -776,175 +714,6 @@ or make sure that you already have Serverless 3.x installed in your project. return pkg; } - private async ensureLogSubscription( - funcName: string, - cloudWatchFilterString: string - ) { - try { - await this.awsProvider.request("Lambda", "getFunction", { - FunctionName: funcName, - }); - } catch (err) { - if (err.providerError) { - this.log.error(err.providerError.message); - } - return; - } - - let destinationArn; - - const { logIngestionFunctionName = "newrelic-log-ingestion", apiKey } = - this.config; - - try { - destinationArn = await this.getDestinationArn(logIngestionFunctionName); - } catch (err) { - this.log.error( - `Could not find a \`${logIngestionFunctionName}\` function installed.` - ); - this.log.warning( - "Details about setup requirements are available here: https://docs.newrelic.com/docs/serverless-function-monitoring/aws-lambda-monitoring/get-started/enable-new-relic-monitoring-aws-lambda#enable-process" - ); - if (err.providerError) { - this.log.error(err.providerError.message); - } - if (!apiKey) { - this.log.error( - "Unable to create newrelic-log-ingestion because New Relic API key not configured." - ); - return; - } - - this.log.notice( - `creating required newrelic-log-ingestion function in region ${this.region}` - ); - await this.addLogIngestionFunction(); - return; - } - - let subscriptionFilters; - - try { - subscriptionFilters = await this.describeSubscriptionFilters(funcName); - } catch (err) { - if (err.providerError) { - this.log.error(err.providerError.message); - } - return; - } - - const competingFilters = subscriptionFilters.filter( - (filter) => filter.filterName !== "NewRelicLogStreaming" - ); - - if (competingFilters.length) { - this.log.warning( - "WARNING: Found a log subscription filter that was not installed by New Relic. This may prevent the New Relic log subscription filter from being installed. If you know you don't need this log subscription filter, you should first remove it and rerun this command. If your organization requires this log subscription filter, please contact New Relic at serverless@newrelic.com for assistance with getting the AWS log subscription filter limit increased." - ); - } - - const existingFilters = subscriptionFilters.filter( - (filter) => filter.filterName === "NewRelicLogStreaming" - ); - - if (existingFilters.length) { - this.log.notice( - `Found log subscription for ${funcName}, verifying configuration` - ); - - await Promise.all( - existingFilters - .filter((filter) => filter.filterPattern !== cloudWatchFilterString) - .map(async (filter) => this.removeSubscriptionFilter(funcName)) - .map(async (filter) => - this.addSubscriptionFilter( - funcName, - destinationArn, - cloudWatchFilterString - ) - ) - ); - } else { - this.log.notice(`Adding New Relic log subscription to ${funcName}`); - - await this.addSubscriptionFilter( - funcName, - destinationArn, - cloudWatchFilterString - ); - } - } - - private async getDestinationArn(logIngestionFunctionName: string) { - try { - return this.awsProvider - .request("Lambda", "getFunction", { - FunctionName: logIngestionFunctionName, - }) - .then((res) => res.Configuration.FunctionArn); - } catch (e) { - this.log.error(`Error getting ingestion function destination ARN.`); - this.log.error(e); - } - } - - private async addLogIngestionFunction() { - const templateUrl = await this.getSarTemplate(); - if (!templateUrl) { - this.log.error( - "Unable to create newRelic-log-ingestion without sar template." - ); - return; - } - - try { - const mode = "CREATE"; - const stackName = "NewRelicLogIngestion"; - const changeSetName = `${stackName}-${mode}-${Date.now()}`; - const parameters = await this.formatFunctionVariables(); - - const params = { - Capabilities: ["CAPABILITY_IAM"], - ChangeSetName: changeSetName, - ChangeSetType: mode, - Parameters: parameters, - StackName: stackName, - TemplateURL: templateUrl, - }; - - let cfResponse; - try { - cfResponse = await this.awsProvider.request( - "CloudFormation", - "createChangeSet", - params - ); - } catch (e) { - this.log.error(`Unable to get stack information.`); - this.log.error(e); - } - const { Id, StackId } = cfResponse; - - this.log.notice( - "Waiting for change set creation to complete, this may take a minute..." - ); - - await waitForStatus( - { - awsMethod: "describeChangeSet", - callbackMethod: () => this.executeChangeSet(Id, StackId), - methodParams: { ChangeSetName: Id }, - statusPath: "Status", - }, - this - ); - } catch (err) { - this.log.warning( - "Unable to create newrelic-log-ingestion function. Please verify that required environment variables have been set." - ); - } - } - private async retrieveLicenseKey() { const { apiKey, accountId, nrRegion, proxy } = this.config; const userData = await nerdgraphFetch( @@ -957,110 +726,6 @@ or make sure that you already have Serverless 3.x installed in your project. this.licenseKey = _.get(userData, "data.actor.account.licenseKey", null); return this.licenseKey; } - - private async formatFunctionVariables() { - const { logEnabled } = this.config; - const licenseKey = this.licenseKey - ? this.licenseKey - : await this.retrieveLicenseKey(); - const loggingVar = logEnabled ? "True" : "False"; - - return [ - { - ParameterKey: "NRLoggingEnabled", - ParameterValue: `${loggingVar}`, - }, - { - ParameterKey: "NRLicenseKey", - ParameterValue: `${licenseKey}`, - }, - ]; - } - - private async getSarTemplate() { - try { - const data = await this.awsProvider.request( - "ServerlessApplicationRepository", - "createCloudFormationTemplate", - { - ApplicationId: - "arn:aws:serverlessrepo:us-east-1:463657938898:applications/NewRelic-log-ingestion", - } - ); - - const { TemplateUrl } = data; - return TemplateUrl; - } catch (err) { - this.log.error( - `Something went wrong while fetching the sar template: ${err}` - ); - } - } - - private async executeChangeSet(changeSetName: string, stackId: string) { - try { - await this.awsProvider.request("CloudFormation", "executeChangeSet", { - ChangeSetName: changeSetName, - }); - this.log.notice( - "Waiting for newrelic-log-ingestion install to complete, this may take a minute..." - ); - - await waitForStatus( - { - awsMethod: "describeStacks", - callbackMethod: () => this.addLogSubscriptions(), - methodParams: { StackName: stackId }, - statusPath: "Stacks[0].StackStatus", - }, - this - ); - } catch (changeSetErr) { - this.log.error( - `Something went wrong while executing the change set: ${changeSetErr}` - ); - } - } - - private async describeSubscriptionFilters(funcName: string) { - return this.awsProvider - .request("CloudWatchLogs", "describeSubscriptionFilters", { - logGroupName: `/aws/lambda/${funcName}`, - }) - .then((res) => res.subscriptionFilters); - } - - private async addSubscriptionFilter( - funcName: string, - destinationArn: string, - cloudWatchFilterString: string - ) { - return this.awsProvider - .request("CloudWatchLogs", "putSubscriptionFilter", { - destinationArn, - filterName: "NewRelicLogStreaming", - filterPattern: cloudWatchFilterString, - logGroupName: `/aws/lambda/${funcName}`, - }) - .catch((err) => { - if (err.providerError) { - this.log.error(err.providerError.message); - } - }); - } - - private removeSubscriptionFilter(funcName: string) { - return this.awsProvider - .request("CloudWatchLogs", "DeleteSubscriptionFilter", { - filterName: "NewRelicLogStreaming", - logGroupName: `/aws/lambda/${funcName}`, - }) - .catch((err) => { - if (err.providerError) { - this.log.error(err.providerError.message); - } - }); - } } module.exports = NewRelicLambdaLayerPlugin; diff --git a/src/integration.ts b/src/integration.ts index 85707044..4b6b079c 100644 --- a/src/integration.ts +++ b/src/integration.ts @@ -7,13 +7,26 @@ import { } from "./api"; import { fetchPolicy, waitForStatus } from "./utils"; +const DEFAULT_FILTER_PATTERNS = [ + "REPORT", + "NR_LAMBDA_MONITORING", + "Task timed out", + "RequestId", +]; + export default class Integration { public config: any; public awsProvider: any; public serverless: any; public log: any; public region: string; + public functions: any; + public autoSubscriptionDisabled: boolean; + public shouldSkipFunction: any; + public extFellBackToCW: boolean; + public extFallbackMessage: string; private licenseKey: string; + private retrieveLicenseKey: any; constructor({ config, @@ -22,6 +35,12 @@ export default class Integration { region, licenseKey, log, + functions, + autoSubscriptionDisabled, + shouldSkipFunction, + extFellBackToCW, + extFallbackMessage, + retrieveLicenseKey, }: any) { this.config = config; this.log = log; @@ -29,6 +48,13 @@ export default class Integration { this.serverless = serverless; this.region = region; this.licenseKey = licenseKey; + this.region = region; + this.functions = functions; + this.autoSubscriptionDisabled = autoSubscriptionDisabled; + this.shouldSkipFunction = shouldSkipFunction; + this.extFellBackToCW = extFellBackToCW; + this.extFallbackMessage = extFallbackMessage; + this.retrieveLicenseKey = retrieveLicenseKey; } public async check() { @@ -368,4 +394,361 @@ export default class Integration { ); } } + + public async addLogSubscriptions() { + if (this.autoSubscriptionDisabled) { + this.log.notice("Skipping adding log subscription. Explicitly disabled"); + return; + } + + const funcs = this.functions; + let { cloudWatchFilter = [...DEFAULT_FILTER_PATTERNS] } = this.config; + + let cloudWatchFilterString = ""; + if ( + typeof cloudWatchFilter === "object" && + cloudWatchFilter.indexOf("*") === -1 + ) { + cloudWatchFilter = cloudWatchFilter.map((el) => `?\"${el}\"`); + cloudWatchFilterString = cloudWatchFilter.join(" "); + } else if (cloudWatchFilter.indexOf("*") === -1) { + cloudWatchFilterString = String(cloudWatchFilter); + } + + this.log.notice(`log filter: ${cloudWatchFilterString}`); + + const promises = []; + + for (const funcName of Object.keys(funcs)) { + if (this.shouldSkipFunction(funcName)) { + return; + } + + this.log.notice(`Configuring New Relic log subscription for ${funcName}`); + + const funcDef = funcs[funcName]; + promises.push( + this.ensureLogSubscription(funcDef.name, cloudWatchFilterString) + ); + } + + await Promise.all(promises); + + if (this.extFellBackToCW) { + this.log.notice(this.extFallbackMessage); + } + } + + public async removeLogSubscriptions() { + if (this.autoSubscriptionDisabled) { + this.log.notice( + "Skipping removing log subscription. Explicitly disabled" + ); + return; + } + const funcs = this.functions; + const promises = []; + + for (const funcName of Object.keys(funcs)) { + const { name } = funcs[funcName]; + this.log.notice(`Removing New Relic log subscription for ${funcName}`); + promises.push(this.removeSubscriptionFilter(name)); + } + + await Promise.all(promises); + } + + private async paginatedListFunctions(params, ingestionFnFilter) { + const results = await this.awsProvider.request( + "Lambda", + "listFunctions", + params + ); + + const existingIngestionFnResults = + results?.Functions?.filter(ingestionFnFilter); + if ( + results.NextMarker && + (!existingIngestionFnResults || existingIngestionFnResults.length === 0) + ) { + params.Marker = results.NextMarker; + return this.paginatedListFunctions(params, ingestionFnFilter); + } + return existingIngestionFnResults; + } + + public async getDestinationArn(logIngestionFunctionName: string) { + const ingestionFnFilter = (fnData) => + fnData.FunctionName.match(logIngestionFunctionName); + try { + const result = await this.paginatedListFunctions( + { MaxItems: 50 }, + ingestionFnFilter + ); + return result[0]?.FunctionArn; + } catch (e) { + this.log.error(`Error getting ingestion function destination ARN.`); + this.log.error(e); + } + } + + private async describeSubscriptionFilters(funcName: string) { + return this.awsProvider + .request("CloudWatchLogs", "describeSubscriptionFilters", { + logGroupName: `/aws/lambda/${funcName}`, + }) + .then((res) => res.subscriptionFilters); + } + + private async addSubscriptionFilter( + funcName: string, + destinationArn: string, + cloudWatchFilterString: string + ) { + return this.awsProvider + .request("CloudWatchLogs", "putSubscriptionFilter", { + destinationArn, + filterName: "NewRelicLogStreaming", + filterPattern: cloudWatchFilterString, + logGroupName: `/aws/lambda/${funcName}`, + }) + .catch((err) => { + if (err.providerError) { + this.log.error(err.providerError.message); + } + }); + } + + private removeSubscriptionFilter(funcName: string) { + return this.awsProvider + .request("CloudWatchLogs", "DeleteSubscriptionFilter", { + filterName: "NewRelicLogStreaming", + logGroupName: `/aws/lambda/${funcName}`, + }) + .catch((err) => { + if (err.providerError) { + this.log.error(err.providerError.message); + } + }); + } + + private async ensureLogSubscription( + funcName: string, + cloudWatchFilterString: string + ) { + try { + await this.awsProvider.request("Lambda", "getFunction", { + FunctionName: funcName, + }); + } catch (err) { + if (err.providerError) { + this.log.error(err.providerError.message); + } + return; + } + + let destinationArn; + + const { logIngestionFunctionName = "newrelic-log-ingestion", apiKey } = + this.config; + + try { + destinationArn = await this.getDestinationArn(logIngestionFunctionName); + } catch (err) { + this.log.error( + `Could not find a \`${logIngestionFunctionName}\` function installed.` + ); + this.log.warning( + "Details about setup requirements are available here: https://docs.newrelic.com/docs/serverless-function-monitoring/aws-lambda-monitoring/get-started/enable-new-relic-monitoring-aws-lambda#enable-process" + ); + if (err.providerError) { + this.log.error(err.providerError.message); + } + if (!apiKey) { + this.log.error( + "Unable to create newrelic-log-ingestion because New Relic API key not configured." + ); + return; + } + + this.log.notice( + `creating required newrelic-log-ingestion function in region ${this.region}` + ); + await this.addLogIngestionFunction(); + return; + } + + let subscriptionFilters; + + try { + subscriptionFilters = await this.describeSubscriptionFilters(funcName); + } catch (err) { + if (err.providerError) { + this.log.error(err.providerError.message); + } + return; + } + + const competingFilters = subscriptionFilters.filter( + (filter) => filter.filterName !== "NewRelicLogStreaming" + ); + + if (competingFilters.length) { + this.log.warning( + "WARNING: Found a log subscription filter that was not installed by New Relic. This may prevent the New Relic log subscription filter from being installed. If you know you don't need this log subscription filter, you should first remove it and rerun this command. If your organization requires this log subscription filter, please contact New Relic at serverless@newrelic.com for assistance with getting the AWS log subscription filter limit increased." + ); + } + + const existingFilters = subscriptionFilters.filter( + (filter) => filter.filterName === "NewRelicLogStreaming" + ); + + if (existingFilters.length) { + this.log.notice( + `Found log subscription for ${funcName}, verifying configuration` + ); + + await Promise.all( + existingFilters + .filter((filter) => filter.filterPattern !== cloudWatchFilterString) + .map(async (filter) => this.removeSubscriptionFilter(funcName)) + .map(async (filter) => + this.addSubscriptionFilter( + funcName, + destinationArn, + cloudWatchFilterString + ) + ) + ); + } else { + this.log.notice(`Adding New Relic log subscription to ${funcName}`); + + await this.addSubscriptionFilter( + funcName, + destinationArn, + cloudWatchFilterString + ); + } + } + + private async addLogIngestionFunction() { + const templateUrl = await this.getSarTemplate(); + if (!templateUrl) { + this.log.error( + "Unable to create newRelic-log-ingestion without sar template." + ); + return; + } + + try { + const mode = "CREATE"; + const stackName = "NewRelicLogIngestion"; + const changeSetName = `${stackName}-${mode}-${Date.now()}`; + const parameters = await this.formatFunctionVariables(); + + const params = { + Capabilities: ["CAPABILITY_IAM"], + ChangeSetName: changeSetName, + ChangeSetType: mode, + Parameters: parameters, + StackName: stackName, + TemplateURL: templateUrl, + }; + + let cfResponse; + try { + cfResponse = await this.awsProvider.request( + "CloudFormation", + "createChangeSet", + params + ); + } catch (e) { + this.log.error(`Unable to get stack information.`); + this.log.error(e); + } + const { Id, StackId } = cfResponse; + + this.log.notice( + "Waiting for change set creation to complete, this may take a minute..." + ); + + await waitForStatus( + { + awsMethod: "describeChangeSet", + callbackMethod: () => this.executeChangeSet(Id, StackId), + methodParams: { ChangeSetName: Id }, + statusPath: "Status", + }, + this + ); + } catch (err) { + this.log.warning( + "Unable to create newrelic-log-ingestion function. Please verify that required environment variables have been set." + ); + } + } + + private async formatFunctionVariables() { + const { logEnabled } = this.config; + const licenseKey = this.licenseKey + ? this.licenseKey + : await this.retrieveLicenseKey(); + const loggingVar = logEnabled ? "True" : "False"; + + return [ + { + ParameterKey: "NRLoggingEnabled", + ParameterValue: `${loggingVar}`, + }, + { + ParameterKey: "NRLicenseKey", + ParameterValue: `${licenseKey}`, + }, + ]; + } + + private async getSarTemplate() { + try { + const data = await this.awsProvider.request( + "ServerlessApplicationRepository", + "createCloudFormationTemplate", + { + ApplicationId: + "arn:aws:serverlessrepo:us-east-1:463657938898:applications/NewRelic-log-ingestion", + } + ); + + const { TemplateUrl } = data; + return TemplateUrl; + } catch (err) { + this.log.error( + `Something went wrong while fetching the sar template: ${err}` + ); + } + } + + private async executeChangeSet(changeSetName: string, stackId: string) { + try { + await this.awsProvider.request("CloudFormation", "executeChangeSet", { + ChangeSetName: changeSetName, + }); + this.log.notice( + "Waiting for newrelic-log-ingestion install to complete, this may take a minute..." + ); + + await waitForStatus( + { + awsMethod: "describeStacks", + callbackMethod: () => this.addLogSubscriptions(), + methodParams: { StackName: stackId }, + statusPath: "Stacks[0].StackStatus", + }, + this + ); + } catch (changeSetErr) { + this.log.error( + `Something went wrong while executing the change set: ${changeSetErr}` + ); + } + } } From 642ced380e7f89edcb885a646f7803fffabca846 Mon Sep 17 00:00:00 2001 From: mrickard Date: Mon, 5 Feb 2024 16:38:00 -0500 Subject: [PATCH 3/5] chore: Added test for paginating over listFunctions Signed-off-by: mrickard --- tests/integration.test.ts | 67 ++++++++++++++--- tests/paginatedFunctionsList.json | 120 ++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 9 deletions(-) create mode 100644 tests/paginatedFunctionsList.json diff --git a/tests/integration.test.ts b/tests/integration.test.ts index 35b6a688..e6c42eef 100644 --- a/tests/integration.test.ts +++ b/tests/integration.test.ts @@ -13,25 +13,38 @@ const logShim = { }; // for simulating AWS ListPolicies, just one per page in this test -const requestResults = require("./paginatedResults.json"); +const policiesFixture = require("./paginatedPoliciesList.json"); +const functionsFixture = require("./paginatedFunctionsList.json"); + +const setRequestEnv = (service, method) => { + let fixture = policiesFixture + if (service === 'Lambda' || method === 'listFunctions') { + fixture = functionsFixture + } + return { fixture } +} const returnPaginatedAwsRequest = (service, method, params) => { + const { fixture } = setRequestEnv(service, method) if (!params.Marker) { - return requestResults.paginated.first; + return fixture.paginated.first; } - return requestResults.paginated[params.Marker]; + return fixture.paginated[params.Marker]; }; const returnPaginatedNoMatchAwsRequest = (service, method, params) => { + const { fixture } = setRequestEnv(service, method) if (!params.Marker) { - return requestResults.paginatedNoMatch.first; + return fixture.paginatedNoMatch.first; } - return requestResults.paginatedNoMatch[params.Marker]; + return fixture.paginatedNoMatch[params.Marker]; }; const returnNonPaginatedAwsRequest = (service, method, params) => { - return requestResults.nonPaginated; + const { fixture } = setRequestEnv(service, method) + return fixture.nonPaginated; }; const returnNonPaginatedNoMatchAwsRequest = (service, method, params) => { - return requestResults.nonPaginatedNoMatch; + const { fixture } = setRequestEnv(service, method) + return fixture.nonPaginatedNoMatch; }; describe("Integration functions", () => { @@ -66,7 +79,7 @@ describe("Integration functions", () => { "PolicyName", ]); expect(existingPolicy.currentRegionPolicy[0].PolicyName).toEqual( - requestResults.paginated.fourth.Policies[0].PolicyName + policiesFixture.paginated.fourth.Policies[0].PolicyName ); expect(existingPolicy.secretExists).toBeTruthy(); }); @@ -82,7 +95,7 @@ describe("Integration functions", () => { "PolicyName", ]); expect(existingPolicy.currentRegionPolicy[0].PolicyName).toEqual( - requestResults.paginated.fourth.Policies[0].PolicyName + policiesFixture.paginated.fourth.Policies[0].PolicyName ); expect(existingPolicy.secretExists).toBeTruthy(); }); @@ -107,4 +120,40 @@ describe("Integration functions", () => { expect(existingPolicy.secretExists).toBeFalsy(); }); }); + describe("search for existing log ingestion function", () => { + it("correctly finds match in multiple pages of results", async () => { + awsProvider.request = jest.fn(returnPaginatedAwsRequest); + pluginMock.awsProvider = { ...awsProvider }; + const slsIntegration = new Integration(pluginMock); + const existingIngestScript = await slsIntegration.getDestinationArn('newrelic-log-ingestion'); + expect(existingIngestScript).toBeDefined(); + expect(existingIngestScript).toEqual( + functionsFixture.paginated.fourth.Functions[0].FunctionArn + ); + }); + it("correctly finds match in non-paginated results", async () => { + awsProvider.request = jest.fn(returnNonPaginatedAwsRequest); + pluginMock.awsProvider = { ...awsProvider }; + const slsIntegration = new Integration(pluginMock); + const existingIngestScript = await slsIntegration.getDestinationArn('newrelic-log-ingestion'); + expect(existingIngestScript).toBeDefined(); + expect(existingIngestScript).toEqual( + functionsFixture.paginated.fourth.Functions[0].FunctionArn + ); + }); + it("correctly handles paginated results with no match", async () => { + awsProvider.request = jest.fn(returnPaginatedNoMatchAwsRequest); + pluginMock.awsProvider = { ...awsProvider }; + const slsIntegration = new Integration(pluginMock); + const existingIngestScript = await slsIntegration.getDestinationArn('newrelic-log-ingestion'); + expect(existingIngestScript).toBeFalsy(); + }); + it("correctly handles non-paginated results with no match", async () => { + awsProvider.request = jest.fn(returnNonPaginatedNoMatchAwsRequest); + pluginMock.awsProvider = { ...awsProvider }; + const slsIntegration = new Integration(pluginMock); + const existingIngestScript = await slsIntegration.getDestinationArn('newrelic-log-ingestion'); + expect(existingIngestScript).toBeFalsy(); + }); + }); }); diff --git a/tests/paginatedFunctionsList.json b/tests/paginatedFunctionsList.json new file mode 100644 index 00000000..aa57bd34 --- /dev/null +++ b/tests/paginatedFunctionsList.json @@ -0,0 +1,120 @@ +{ + "paginated": { + "first": { + "Functions": [ + { + "FunctionName": "FirstFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:FirstFunctionName" + } + ], + "NextMarker": "second" + }, + "second": { + "Functions": [ + { + "FunctionName": "SecondFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:SecondFunctionName" + } + ], + "NextMarker": "third" + }, + "third": { + "Functions": [ + { + "FunctionName": "ThirdFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:ThirdFunctionName" + } + ], + "NextMarker": "fourth" + }, + "fourth": { + "Functions": [ + { + "FunctionName": "newrelic-log-ingestion-0123456789ab", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:newrelic-log-ingestion-0123456789ab" + } + ] + } + }, + "paginatedNoMatch": { + "first": { + "Functions": [ + { + "FunctionName": "FirstFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:FirstFunctionName" + } + ], + "NextMarker": "second" + }, + "second": { + "Functions": [ + { + "FunctionName": "SecondFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:SecondFunctionName" + } + ], + "NextMarker": "third" + }, + "third": { + "Functions": [ + { + "FunctionName": "ThirdFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:ThirdFunctionName" + } + ], + "NextMarker": "fourth" + }, + "fourth": { + "Functions": [ + { + "FunctionName": "FourthFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:policy/FourthFunctionName" + } + ] + } + }, + "nonPaginated": { + "Functions": [ + { + "FunctionName": "FirstFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:FirstFunctionName" + }, + { + "FunctionName": "SecondFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:SecondFunctionName" + }, + { + "FunctionName": "ThirdFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:ThirdFunctionName" + }, + { + "FunctionName": "newrelic-log-ingestion-0123456789ab", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:newrelic-log-ingestion-0123456789ab" + } + ] + }, + "nonPaginatedNoMatch": { + "Functions": [ + { + "FunctionName": "FirstFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:FirstFunctionName", + "Path": "/service-role/" + }, + { + "FunctionName": "SecondFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:SecondFunctionName", + "Path": "/service-role/" + }, + { + "FunctionName": "ThirdFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:function:ThirdFunctionName", + "Path": "/service-role/" + }, + { + "FunctionName": "FourthFunctionName", + "FunctionArn": "arn:aws:lambda:us-east-1:123456789:policy/FourthFunctionName", + "Path": "/" + } + ] + } +} From 0862a8a9aab072f45a7b757d5c25530b2d9856ba Mon Sep 17 00:00:00 2001 From: mrickard Date: Mon, 5 Feb 2024 17:00:17 -0500 Subject: [PATCH 4/5] chore: Cleaned up unused params and imports Signed-off-by: mrickard --- src/index.ts | 1 - tests/integration.test.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index f7fe74de..261faee1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,6 @@ import * as semver from "semver"; import * as Serverless from "serverless"; import { fetchLicenseKey, nerdgraphFetch } from "./api"; import Integration from "./integration"; -import { waitForStatus } from "./utils"; const enum JavaHandler { handleRequest = "handleRequest", diff --git a/tests/integration.test.ts b/tests/integration.test.ts index e6c42eef..6bd11df1 100644 --- a/tests/integration.test.ts +++ b/tests/integration.test.ts @@ -38,11 +38,11 @@ const returnPaginatedNoMatchAwsRequest = (service, method, params) => { } return fixture.paginatedNoMatch[params.Marker]; }; -const returnNonPaginatedAwsRequest = (service, method, params) => { +const returnNonPaginatedAwsRequest = (service, method) => { const { fixture } = setRequestEnv(service, method) return fixture.nonPaginated; }; -const returnNonPaginatedNoMatchAwsRequest = (service, method, params) => { +const returnNonPaginatedNoMatchAwsRequest = (service, method) => { const { fixture } = setRequestEnv(service, method) return fixture.nonPaginatedNoMatch; }; From 3a61346263a1b4db4a404751af0b9e92f4c5c8d1 Mon Sep 17 00:00:00 2001 From: mrickard Date: Tue, 6 Feb 2024 12:17:25 -0500 Subject: [PATCH 5/5] chore: Bumped version to 5.0.1 Signed-off-by: mrickard --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 591f2f02..d402e628 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "serverless-newrelic-lambda-layers", - "version": "4.3.0", + "version": "5.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "serverless-newrelic-lambda-layers", - "version": "4.3.0", + "version": "5.0.1", "license": "Apache-2.0", "devDependencies": { "@types/fs-extra": "^9.0.13", diff --git a/package.json b/package.json index 4a729304..d59a0df5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-newrelic-lambda-layers", - "version": "5.0.0", + "version": "5.0.1", "description": "Serverless plugin for NewRelic APM AWS Lambda layers.", "main": "dist/index.js", "files": [