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

metricFactory.createMetricSearch doesn't support empty dimension map #558

Open
jakeinater opened this issue Aug 15, 2024 · 0 comments
Open
Labels
feature-request New feature

Comments

@jakeinater
Copy link

Feature scope

MetricFactory

Describe your suggested feature

Declaring CustomMetricGroup as following:

      {
        title: 'Test',
        metrics: [
          metricFactory.createMetricSearch(
            'query',
            { dummyDim: undefined as any as string },
            MetricStatistic.SUM,
          ) as MathExpression,
        ],
      },

Which generates a graph with following search query:

SEARCH('{test_namespace,dummyDim}  EligibleEvent', 'Sum', 60)

As far as I can tell, there is no way to omit the DimensionMap. When I emit the metric, I don't associate any dimension, so I need to associate a dummy dimension, which is a little hacky.

Nit: Also unrelated issue, createMetricSearch returns IMetric, which is incompatible with what the MonitoringFacade expects (Metric | MathExpression) resulting in me needing to cast the return into a MathExpression.

Related code snippet:

createMetricSearch(
query: string,
dimensionsMap: DimensionsMap,
statistic: MetricStatistic,
namespace?: string,
label?: string,
period?: Duration,
region?: string,
account?: string
): IMetric {
const finalPeriod =
period ?? this.globalDefaults.period ?? DefaultMetricPeriod;
const searchNamespace = this.getNamespaceWithFallback(namespace);
const namespacePlusDimensionKeys = [
searchNamespace,
...Object.keys(dimensionsMap),
].join(",");
const metricSchema = `{${namespacePlusDimensionKeys}}`;
const dimensionKeysAndValues = Object.entries(
this.removeUndefinedEntries(dimensionsMap)
)
.map(([key, value]) => `${key}="${value}"`)
.join(" ");
const expression = `SEARCH('${metricSchema} ${dimensionKeysAndValues} ${query}', '${statistic}', ${finalPeriod.toSeconds()})`;
return new MathExpression({
expression,
// see https://github.com/aws/aws-cdk/issues/7237
usingMetrics: {},
// cannot be an empty string and undefined is no good either
label: label ?? " ",
period: finalPeriod,
searchRegion: region ?? this.globalDefaults.region,
searchAccount: account ?? this.globalDefaults.account,
});
}

@jakeinater jakeinater added the feature-request New feature label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature
Projects
None yet
Development

No branches or pull requests

1 participant