@@ -23,41 +23,6 @@ const dimensionValue = 'Integ-Test-Agent';
23
23
const dimensions : Record < string , string > = { } ;
24
24
dimensions [ dimensionKey ] = dimensionValue ;
25
25
26
- const metricExists = async ( metricName : string , expectedSampleCount : number ) : Promise < boolean > => {
27
- const request = {
28
- Namespace : 'aws-embedded-metrics' ,
29
- MetricName : metricName ,
30
- Dimensions : [
31
- { Name : 'ServiceName' , Value : serviceName } ,
32
- { Name : 'ServiceType' , Value : serviceType } ,
33
- { Name : 'LogGroup' , Value : logGroupName } ,
34
- { Name : dimensionKey , Value : dimensionValue } ,
35
- ] ,
36
- Period : 60 ,
37
- StartTime : new Date ( startTime . getTime ( ) - 5000 ) ,
38
- EndTime : new Date ( now ( ) ) ,
39
- Statistics : [ 'SampleCount' ] ,
40
- } ;
41
-
42
- const result = await cwmClient . getMetricStatistics ( request ) . promise ( ) ;
43
-
44
- if ( result && result . Datapoints && result . Datapoints . length > 0 ) {
45
- const samples = result . Datapoints . map ( dataPoint => dataPoint . SampleCount || 0 ) . reduce ( ( total , i ) => total + i ) ;
46
- console . log ( `Received ${ samples } samples.` ) ;
47
- return samples === expectedSampleCount ;
48
- }
49
-
50
- return false ;
51
- } ;
52
-
53
- const waitForMetricExistence = async ( metricName : string , expectedSampleCount : number ) : Promise < void > => {
54
- let attempts = 0 ;
55
- while ( ! ( await metricExists ( metricName , expectedSampleCount ) ) ) {
56
- console . log ( 'No metrics yet. Sleeping before trying again. Attempt #' , attempts ++ ) ;
57
- await Sleep ( 2000 ) ;
58
- }
59
- } ;
60
-
61
26
test (
62
27
'end to end integration test with agent over UDP' ,
63
28
async ( ) => {
@@ -86,23 +51,60 @@ test(
86
51
// arrange
87
52
const idleTimeout = 500 ;
88
53
const metricName = 'TCP-MultipleFlushes' ;
89
- const expectedSamples = 2 ;
54
+ const expectedSamples = 3 ;
90
55
91
56
Configuration . agentEndpoint = 'tcp://0.0.0.0:25888' ;
92
57
93
- const doWork = metricScope ( metrics => ( ) => {
94
- metrics . putDimensions ( dimensions ) ;
95
- metrics . putMetric ( metricName , 100 , 'Milliseconds' ) ;
96
- metrics . setProperty ( 'RequestId' , '422b1569-16f6-4a03-b8f0-fe3fd9b100f8' ) ;
97
- } ) ;
58
+ const doWork = metricScope ( metrics => ( ) => {
59
+ metrics . putDimensions ( dimensions ) ;
60
+ metrics . putMetric ( metricName , 100 , 'Milliseconds' ) ;
61
+ metrics . setProperty ( 'RequestId' , '422b1569-16f6-4a03-b8f0-fe3fd9b100f8' ) ;
62
+ } ) ;
98
63
99
- // act
100
- doWork ( ) ;
101
- await Sleep ( idleTimeout ) ;
102
- doWork ( ) ;
64
+ // act
65
+ doWork ( ) ;
66
+ doWork ( ) ;
67
+ await Sleep ( idleTimeout ) ;
68
+ doWork ( ) ;
103
69
104
70
// assert
105
71
await waitForMetricExistence ( metricName , expectedSamples ) ;
106
72
} ,
107
73
timeoutMillis ,
108
74
) ;
75
+
76
+
77
+ const metricExists = async ( metricName : string , expectedSampleCount : number ) : Promise < boolean > => {
78
+ const request = {
79
+ Namespace : 'aws-embedded-metrics' ,
80
+ MetricName : metricName ,
81
+ Dimensions : [
82
+ { Name : 'ServiceName' , Value : serviceName } ,
83
+ { Name : 'ServiceType' , Value : serviceType } ,
84
+ { Name : 'LogGroup' , Value : logGroupName } ,
85
+ { Name : dimensionKey , Value : dimensionValue } ,
86
+ ] ,
87
+ Period : 60 ,
88
+ StartTime : new Date ( startTime . getTime ( ) - 5000 ) ,
89
+ EndTime : new Date ( now ( ) ) ,
90
+ Statistics : [ 'SampleCount' ] ,
91
+ } ;
92
+
93
+ const result = await cwmClient . getMetricStatistics ( request ) . promise ( ) ;
94
+
95
+ if ( result && result . Datapoints && result . Datapoints . length > 0 ) {
96
+ const samples = result . Datapoints . map ( dataPoint => dataPoint . SampleCount || 0 ) . reduce ( ( total , i ) => total + i ) ;
97
+ console . log ( `Received ${ samples } samples.` ) ;
98
+ return samples === expectedSampleCount ;
99
+ }
100
+
101
+ return false ;
102
+ } ;
103
+
104
+ const waitForMetricExistence = async ( metricName : string , expectedSampleCount : number ) : Promise < void > => {
105
+ let attempts = 0 ;
106
+ while ( ! ( await metricExists ( metricName , expectedSampleCount ) ) ) {
107
+ console . log ( 'No metrics yet. Sleeping before trying again. Attempt #' , attempts ++ ) ;
108
+ await Sleep ( 2000 ) ;
109
+ }
110
+ } ;
0 commit comments