Skip to content

Commit 7a25f2f

Browse files
committed
feat(metrics): apply styling
1 parent dad0f20 commit 7a25f2f

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

packages/metrics/src/Metrics.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
ExtraOptions,
1212
MetricUnit,
1313
MetricUnits,
14-
MetricResolution
14+
MetricResolution,
1515
} from './types';
1616

1717
const MAX_METRICS_SIZE = 100;
@@ -487,7 +487,12 @@ class Metrics extends Utility implements MetricsInterface {
487487
}
488488
}
489489

490-
private storeMetric(name: string, unit: MetricUnit, value: number, resolution?: MetricResolution): void {
490+
private storeMetric(
491+
name: string,
492+
unit: MetricUnit,
493+
value: number,
494+
resolution?: MetricResolution,
495+
): void {
491496
if (Object.keys(this.storedMetrics).length >= MAX_METRICS_SIZE) {
492497
this.publishStoredMetrics();
493498
}
@@ -497,7 +502,7 @@ class Metrics extends Utility implements MetricsInterface {
497502
unit,
498503
value,
499504
name,
500-
resolution
505+
resolution,
501506
};
502507

503508
} else {
@@ -511,4 +516,8 @@ class Metrics extends Utility implements MetricsInterface {
511516

512517
}
513518

514-
export { Metrics, MetricUnits, MetricResolution };
519+
export {
520+
Metrics,
521+
MetricUnits,
522+
MetricResolution,
523+
};

packages/metrics/src/MetricsInterface.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { Metrics } from './Metrics';
2-
import { MetricUnit, MetricResolution, EmfOutput, HandlerMethodDecorator, Dimensions, MetricsOptions } from './types';
3-
2+
import {
3+
MetricUnit,
4+
MetricResolution,
5+
EmfOutput,
6+
HandlerMethodDecorator,
7+
Dimensions,
8+
MetricsOptions
9+
} from './types';
410
interface MetricsInterface {
511
addDimension(name: string, value: string): void
612
addDimensions(dimensions: {[key: string]: string}): void

packages/metrics/src/types/Metrics.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ type EmfOutput = {
2121
CloudWatchMetrics: {
2222
Namespace: string
2323
Dimensions: [string[]]
24-
Metrics: { Name: string; Unit: MetricUnit; StorageResolution?: MetricResolution }[]
24+
Metrics: {
25+
Name: string
26+
Unit: MetricUnit
27+
StorageResolution?: MetricResolution
28+
}[]
2529
}[]
2630
}
2731
};

packages/metrics/tests/unit/Metrics.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ describe('Class: Metrics', () => {
565565
});
566566

567567
describe('Feature: Resolution of Metrics', ()=>{
568-
test('Should serialized metrics in EMF format not contain StorageResolution as key if none is set',()=>{
568+
569+
test('serialized metrics in EMF format should not contain `StorageResolution` as key if none is set', () => {
569570
const metrics = new Metrics();
570571
metrics.addMetric('test_name', MetricUnits.Seconds, 10);
571572
const serializedMetrics = metrics.serializeMetrics();
@@ -575,8 +576,7 @@ describe('Class: Metrics', () => {
575576
expect(Object.keys(serializedMetrics._aws.CloudWatchMetrics[0].Metrics[0])).toContain('Unit');
576577

577578
});
578-
579-
test('Should be StorageResolution 60 if MetricResolution is set to `Standard`',()=>{
579+
test('should set StorageResolution 60 if MetricResolution is set to `Standard`', () => {
580580
const metrics = new Metrics();
581581
metrics.addMetric('test_name', MetricUnits.Seconds, 10, MetricResolution.Standard);
582582
const serializedMetrics = metrics.serializeMetrics();

packages/metrics/tests/unit/middleware/middy.test.ts

+21-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
* @group unit/metrics/middleware
55
*/
66

7-
import { Metrics, MetricUnits, logMetrics, MetricResolution } from '../../../../metrics/src';
8-
import middy from '@middy/core';
7+
import {
8+
Metrics,
9+
MetricUnits,
10+
logMetrics,
11+
MetricResolution
12+
} from '../../../../metrics/src';import middy from '@middy/core';
913
import { ExtraOptions } from '../../../src/types';
1014

1115
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
@@ -315,8 +319,9 @@ describe('Middy middleware', () => {
315319
);
316320
});
317321
});
318-
describe('Feature: Resolution of Metrics', ()=>{
319-
test('Should use metric resolution `Standard, 60` if `Standard` is set', async () => {
322+
describe('Metrics resolution', () => {
323+
324+
test('should use metric resolution `Standard, 60` if `Standard` is set', async () => {
320325
// Prepare
321326
const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
322327

@@ -338,7 +343,11 @@ describe('Middy middleware', () => {
338343
{
339344
Namespace: 'serverlessAirline',
340345
Dimensions: [['service']],
341-
Metrics: [{ Name: 'successfulBooking', Unit: 'Count', StorageResolution: 60 }],
346+
Metrics: [{
347+
Name: 'successfulBooking',
348+
Unit: 'Count',
349+
StorageResolution: 60,
350+
}],
342351
},
343352
],
344353
},
@@ -347,7 +356,8 @@ describe('Middy middleware', () => {
347356
})
348357
);
349358
});
350-
test('Should use metric resolution `High, 1` if `High` is set', async () => {
359+
360+
test('should use metric resolution `High, 1` if `High` is set', async () => {
351361
// Prepare
352362
const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
353363

@@ -369,7 +379,11 @@ describe('Middy middleware', () => {
369379
{
370380
Namespace: 'serverlessAirline',
371381
Dimensions: [['service']],
372-
Metrics: [{ Name: 'successfulBooking', Unit: 'Count', StorageResolution: 1 }],
382+
Metrics: [{
383+
Name: 'successfulBooking',
384+
Unit: 'Count',
385+
StorageResolution: 1
386+
}],
373387
},
374388
],
375389
},

0 commit comments

Comments
 (0)