aws-embedded-metrics
Advanced tools
Comparing version 2.0.6 to 3.0.0
export declare enum Constants { | ||
MAX_DIMENSIONS = 9, | ||
MAX_DIMENSION_SET_SIZE = 30, | ||
DEFAULT_NAMESPACE = "aws-embedded-metrics", | ||
@@ -4,0 +4,0 @@ MAX_METRICS_PER_EVENT = 100, |
@@ -19,3 +19,3 @@ "use strict"; | ||
(function (Constants) { | ||
Constants[Constants["MAX_DIMENSIONS"] = 9] = "MAX_DIMENSIONS"; | ||
Constants[Constants["MAX_DIMENSION_SET_SIZE"] = 30] = "MAX_DIMENSION_SET_SIZE"; | ||
Constants["DEFAULT_NAMESPACE"] = "aws-embedded-metrics"; | ||
@@ -22,0 +22,0 @@ Constants[Constants["MAX_METRICS_PER_EVENT"] = 100] = "MAX_METRICS_PER_EVENT"; |
@@ -43,2 +43,8 @@ import { MetricValues } from './MetricValues'; | ||
/** | ||
* Validates dimension set length is not more than Constants.MAX_DIMENSION_SET_SIZE | ||
* | ||
* @param dimensionSet | ||
*/ | ||
static validateDimensionSet(dimensionSet: Record<string, string>): void; | ||
/** | ||
* Adds a new set of dimensions. Any time a new dimensions set | ||
@@ -45,0 +51,0 @@ * is added, the set is first prepended by the default dimensions. |
@@ -20,2 +20,4 @@ "use strict"; | ||
const MetricValues_1 = require("./MetricValues"); | ||
const Constants_1 = require("../Constants"); | ||
const DimensionSetExceededError_1 = require("../exceptions/DimensionSetExceededError"); | ||
class MetricsContext { | ||
@@ -84,2 +86,11 @@ /** | ||
/** | ||
* Validates dimension set length is not more than Constants.MAX_DIMENSION_SET_SIZE | ||
* | ||
* @param dimensionSet | ||
*/ | ||
static validateDimensionSet(dimensionSet) { | ||
if (Object.keys(dimensionSet).length > Constants_1.Constants.MAX_DIMENSION_SET_SIZE) | ||
throw new DimensionSetExceededError_1.DimensionSetExceededError(`Maximum number of dimensions per dimension set allowed are ${Constants_1.Constants.MAX_DIMENSION_SET_SIZE}`); | ||
} | ||
/** | ||
* Adds a new set of dimensions. Any time a new dimensions set | ||
@@ -91,2 +102,3 @@ * is added, the set is first prepended by the default dimensions. | ||
putDimensions(incomingDimensionSet) { | ||
MetricsContext.validateDimensionSet(incomingDimensionSet); | ||
if (this.dimensions.length === 0) { | ||
@@ -124,2 +136,3 @@ this.dimensions.push(incomingDimensionSet); | ||
this.shouldUseDefaultDimensions = false; | ||
dimensionSets.forEach(dimensionSet => MetricsContext.validateDimensionSet(dimensionSet)); | ||
this.dimensions = dimensionSets; | ||
@@ -126,0 +139,0 @@ } |
@@ -19,2 +19,3 @@ "use strict"; | ||
const Constants_1 = require("../Constants"); | ||
const DimensionSetExceededError_1 = require("../exceptions/DimensionSetExceededError"); | ||
/** | ||
@@ -38,3 +39,8 @@ * Serializes the provided context to the CWL Structured | ||
// representation for sink-specific validations | ||
const keys = Object.keys(d).slice(0, Constants_1.Constants.MAX_DIMENSIONS); | ||
const keys = Object.keys(d); | ||
if (keys.length > Constants_1.Constants.MAX_DIMENSION_SET_SIZE) { | ||
const errMsg = `Maximum number of dimensions allowed are ${Constants_1.Constants.MAX_DIMENSION_SET_SIZE}.` + | ||
`Account for default dimensions if not using set_dimensions.`; | ||
throw new DimensionSetExceededError_1.DimensionSetExceededError(errMsg); | ||
} | ||
dimensionKeys.push(keys); | ||
@@ -41,0 +47,0 @@ dimensionProperties = Object.assign(Object.assign({}, dimensionProperties), d); |
{ | ||
"name": "aws-embedded-metrics", | ||
"version": "2.0.6", | ||
"version": "3.0.0", | ||
"description": "AWS Embedded Metrics Client Library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
121005
69
2351