Skip to content

Commit

Permalink
fix(MetricFactory): wrap search query dimensions with quotes to handl…
Browse files Browse the repository at this point in the history
…e potential whitespace (#591)

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
  • Loading branch information
echeung-amzn authored Nov 8, 2024
1 parent fe0e226 commit 97cf069
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
9 changes: 6 additions & 3 deletions lib/common/metric/MetricFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,19 @@ export class MetricFactory {
const finalPeriod =
period ?? this.globalDefaults.period ?? DefaultMetricPeriod;
const searchNamespace = this.getNamespaceWithFallback(namespace);
const keysWithQuotations = Object.keys(dimensionsMap).map(
(key) => `"${key}"`,
);
const namespacePlusDimensionKeys = [
searchNamespace,
...Object.keys(dimensionsMap),
`"${searchNamespace}"`,
...keysWithQuotations,
].join(",");
const metricSchema = `{${namespacePlusDimensionKeys}}`;

const dimensionKeysAndValues = Object.entries(
this.removeUndefinedEntries(dimensionsMap),
)
.map(([key, value]) => `${key}="${value}"`)
.map(([key, value]) => `"${key}"="${value}"`)
.join(" ");

const expression = `SEARCH('${metricSchema} ${dimensionKeysAndValues} ${query}', '${statistic}', ${finalPeriod.toSeconds()})`;
Expand Down
18 changes: 9 additions & 9 deletions test/common/metric/__snapshots__/MetricFactory.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions test/facade/__snapshots__/MonitoringAspect.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/facade/__snapshots__/MonitoringFacade.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 97cf069

Please sign in to comment.