@aws-cdk/aws-cloudwatch
Version:
The CDK Construct Library for AWS::CloudWatch
61 lines (60 loc) • 2.31 kB
TypeScript
import { Duration } from '@aws-cdk/core';
import { IMetric, MetricConfig, MetricExpressionConfig, MetricStatConfig } from '../metric-types';
/**
* Return a unique string representation for this metric.
*
* Can be used to determine as a hash key to determine if 2 Metric objects
* represent the same metric. Excludes rendering properties.
*/
export declare function metricKey(metric: IMetric): string;
/**
* Return the period of a metric
*
* For a stat metric, return the immediate period.
*
* For an expression metric, all metrics used in it have been made to have the
* same period, so we return the period of the first inner metric.
*/
export declare function metricPeriod(metric: IMetric): Duration;
/**
* Given a metric object, inspect it and call the correct function for the type of output
*
* In addition to the metric object itself, takes a callback object with two
* methods, to be invoked for the particular type of metric.
*
* If the metric represent a metric query (nominally generated through an
* instantiation of `Metric` but can be generated by any class that implements
* `IMetric`) a particular field in its `toMetricConfig()` output will be set
* (to wit, `metricStat`) and the `withStat()` callback will be called with
* that object.
*
* If the metric represents an expression (usually by instantiating `MathExpression`
* but users can implement `IMetric` arbitrarily) the `mathExpression` field
* will be set in the object returned from `toMetricConfig` and the callback
* called `withExpression` will be applied to that object.
*
* Will return the values returned by the callbacks.
*
* To be used as such:
*
* ```ts
* const ret = dispatchMetric(someMetric, {
* withStat(stat) {
* // do something with stat
* return 1;
* },
* withExpression(expr) {
* // do something with expr
* return 2;
* },
* });
* ```
*
* This function encapsulates some type analysis that would otherwise have to be
* repeated in all places where code needs to make a distinction on the type
* of metric object that is being passed.
*/
export declare function dispatchMetric<A, B>(metric: IMetric, fns: {
withStat: (x: MetricStatConfig, c: MetricConfig) => A;
withExpression: (x: MetricExpressionConfig, c: MetricConfig) => B;
}): A | B;