From 49fbf0cbfde15a8ea339d19f500bb51b93b5e48e Mon Sep 17 00:00:00 2001 From: Kellen Stuart <37430166+Kellen-Stuart@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:35:56 -0700 Subject: [PATCH] feat(query): Provide a default query if not specified (#188) **Old Behavior** If the query parameter was not provided - the `[0]` arg - then an error would be returned ``` No query provided ``` **New Behavior** This merge request defaults the query to ``` fields @timestamp, @message, @logStream, @log | sort @timestamp desc ``` (if not provided). **Testing** Screenshot of the output from a manual test ``` No Cloudwatch Insight Query provided. Defaulting to: fields @timestamp, @message, @logStream, @log | sort @timestamp desc Querying between 2023-10-06T20:43:15.096Z and 2023-10-06T21:43:15.096Z for 1 log group(s): ["/aws/lambda/CoreAPI-processesTaskGeneratePatientExport"] 0 records (0.00 MB) scanned, 0 matched No results returned. ``` --------- Co-authored-by: Kellen Stuart --- README.md | 7 +++++++ src/index.ts | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 94c9868..0595e76 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,13 @@ cwq --log-group '' Where `` is the log group you want to search and `` is the [CloudWatch Logs Insights query](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html) to search with. +If `` is not specified, the [CloudWatch Logs Insights query](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html) will default to: + +``` +fields @timestamp, @message, @logStream, @log +| sort @timestamp desc +``` + Further usage guidelines are described below and options can be found via the help argument: ```bash diff --git a/src/index.ts b/src/index.ts index 4112334..1d3e3ad 100755 --- a/src/index.ts +++ b/src/index.ts @@ -84,9 +84,15 @@ process.on("SIGINT", async () => { const endTime = time.parseTimeOrDuration(args.end); const limit = args.limit; - const query = args._[0]; + let query = args._[0]; if (!query) { - throw new Error("No query provided"); + query = ` + fields @timestamp, @message, @logStream, @log + | sort @timestamp desc + `; + console.error( + `No Cloudwatch Insight Query provided. Defaulting to: \n${query}` + ); } const queryString = query.toString();