@@ -47,19 +47,32 @@ function getClient(apiKey) {
4747 } ) ;
4848}
4949exports . getClient = getClient ;
50- function postMetricsIfAny ( http , apiURL , metrics , endpoint ) {
50+ function isTimeoutError ( error ) {
51+ return error . message . includes ( 'timeout' ) || error . message . includes ( 'Timeout' ) ;
52+ }
53+ function postMetricsIfAny ( http , apiURL , metrics , endpoint , ignoreTimeouts ) {
5154 return __awaiter ( this , void 0 , void 0 , function * ( ) {
5255 // POST data
5356 if ( metrics . series . length ) {
54- core . debug ( `About to send ${ metrics . series . length } metrics` ) ;
55- const res = yield http . post ( `${ apiURL } /api/${ endpoint } ` , JSON . stringify ( metrics ) ) ;
56- if ( res . message . statusCode === undefined || res . message . statusCode >= 400 ) {
57- throw new Error ( `HTTP request failed: ${ res . message . statusMessage } ${ res . message . statusCode } ` ) ;
57+ try {
58+ core . debug ( `About to send ${ metrics . series . length } metrics` ) ;
59+ const res = yield http . post ( `${ apiURL } /api/${ endpoint } ` , JSON . stringify ( metrics ) ) ;
60+ if ( res . message . statusCode === undefined ||
61+ res . message . statusCode >= 400 ) {
62+ throw new Error ( `HTTP request failed: ${ res . message . statusMessage } ${ res . message . statusCode } ` ) ;
63+ }
64+ }
65+ catch ( error ) {
66+ if ( ignoreTimeouts && isTimeoutError ( error ) ) {
67+ core . warning ( `Timeout occurred while sending metrics, but continuing due to ignore-timeout setting` ) ;
68+ return ;
69+ }
70+ throw error ;
5871 }
5972 }
6073 } ) ;
6174}
62- function sendMetrics ( apiURL , apiKey , metrics ) {
75+ function sendMetrics ( apiURL , apiKey , metrics , ignoreTimeouts ) {
6376 return __awaiter ( this , void 0 , void 0 , function * ( ) {
6477 const http = getClient ( apiKey ) ;
6578 // distributions use a different procotol.
@@ -79,21 +92,31 @@ function sendMetrics(apiURL, apiKey, metrics) {
7992 tags : m . tags
8093 } ) ;
8194 }
82- yield postMetricsIfAny ( http , apiURL , otherMetrics , 'v1/series' ) ;
83- yield postMetricsIfAny ( http , apiURL , distributions , 'v1/distribution_points' ) ;
95+ yield postMetricsIfAny ( http , apiURL , otherMetrics , 'v1/series' , ignoreTimeouts ) ;
96+ yield postMetricsIfAny ( http , apiURL , distributions , 'v1/distribution_points' , ignoreTimeouts ) ;
8497 } ) ;
8598}
8699exports . sendMetrics = sendMetrics ;
87- function sendEvents ( apiURL , apiKey , events ) {
100+ function sendEvents ( apiURL , apiKey , events , ignoreTimeouts ) {
88101 return __awaiter ( this , void 0 , void 0 , function * ( ) {
89102 const http = getClient ( apiKey ) ;
90103 let errors = 0 ;
91104 core . debug ( `About to send ${ events . length } events` ) ;
92105 for ( const ev of events ) {
93- const res = yield http . post ( `${ apiURL } /api/v1/events` , JSON . stringify ( ev ) ) ;
94- if ( res . message . statusCode === undefined || res . message . statusCode >= 400 ) {
95- errors ++ ;
96- core . error ( `HTTP request failed: ${ res . message . statusMessage } ` ) ;
106+ try {
107+ const res = yield http . post ( `${ apiURL } /api/v1/events` , JSON . stringify ( ev ) ) ;
108+ if ( res . message . statusCode === undefined ||
109+ res . message . statusCode >= 400 ) {
110+ errors ++ ;
111+ core . error ( `HTTP request failed: ${ res . message . statusMessage } ` ) ;
112+ }
113+ }
114+ catch ( error ) {
115+ if ( ignoreTimeouts && isTimeoutError ( error ) ) {
116+ core . warning ( `Timeout occurred while sending event, but continuing due to ignore-timeout setting` ) ;
117+ continue ;
118+ }
119+ throw error ;
97120 }
98121 }
99122 if ( errors > 0 ) {
@@ -102,16 +125,26 @@ function sendEvents(apiURL, apiKey, events) {
102125 } ) ;
103126}
104127exports . sendEvents = sendEvents ;
105- function sendServiceChecks ( apiURL , apiKey , serviceChecks ) {
128+ function sendServiceChecks ( apiURL , apiKey , serviceChecks , ignoreTimeouts ) {
106129 return __awaiter ( this , void 0 , void 0 , function * ( ) {
107130 const http = getClient ( apiKey ) ;
108131 let errors = 0 ;
109132 core . debug ( `About to send ${ serviceChecks . length } service checks` ) ;
110133 for ( const sc of serviceChecks ) {
111- const res = yield http . post ( `${ apiURL } /api/v1/check_run` , JSON . stringify ( sc ) ) ;
112- if ( res . message . statusCode === undefined || res . message . statusCode >= 400 ) {
113- errors ++ ;
114- core . error ( `HTTP request failed: ${ res . message . statusMessage } ` ) ;
134+ try {
135+ const res = yield http . post ( `${ apiURL } /api/v1/check_run` , JSON . stringify ( sc ) ) ;
136+ if ( res . message . statusCode === undefined ||
137+ res . message . statusCode >= 400 ) {
138+ errors ++ ;
139+ core . error ( `HTTP request failed: ${ res . message . statusMessage } ` ) ;
140+ }
141+ }
142+ catch ( error ) {
143+ if ( ignoreTimeouts && isTimeoutError ( error ) ) {
144+ core . warning ( `Timeout occurred while sending service check, but continuing due to ignore-timeout setting` ) ;
145+ continue ;
146+ }
147+ throw error ;
115148 }
116149 }
117150 if ( errors > 0 ) {
@@ -120,17 +153,27 @@ function sendServiceChecks(apiURL, apiKey, serviceChecks) {
120153 } ) ;
121154}
122155exports . sendServiceChecks = sendServiceChecks ;
123- function sendLogs ( logApiURL , apiKey , logs ) {
156+ function sendLogs ( logApiURL , apiKey , logs , ignoreTimeouts ) {
124157 return __awaiter ( this , void 0 , void 0 , function * ( ) {
125158 const http = getClient ( apiKey ) ;
126159 let errors = 0 ;
127160 core . debug ( `About to send ${ logs . length } logs` ) ;
128161 for ( const log of logs ) {
129- const res = yield http . post ( `${ logApiURL } /v1/input` , JSON . stringify ( log ) ) ;
130- if ( res . message . statusCode === undefined || res . message . statusCode >= 400 ) {
131- errors ++ ;
132- core . error ( `HTTP request failed: ${ res . message . statusMessage } ` ) ;
133- throw new Error ( `Failed sending ${ errors } out of ${ logs . length } events` ) ;
162+ try {
163+ const res = yield http . post ( `${ logApiURL } /v1/input` , JSON . stringify ( log ) ) ;
164+ if ( res . message . statusCode === undefined ||
165+ res . message . statusCode >= 400 ) {
166+ errors ++ ;
167+ core . error ( `HTTP request failed: ${ res . message . statusMessage } ` ) ;
168+ throw new Error ( `Failed sending ${ errors } out of ${ logs . length } events` ) ;
169+ }
170+ }
171+ catch ( error ) {
172+ if ( ignoreTimeouts && isTimeoutError ( error ) ) {
173+ core . warning ( `Timeout occurred while sending logs, but continuing due to ignore-timeout setting` ) ;
174+ continue ;
175+ }
176+ throw error ;
134177 }
135178 }
136179 if ( errors > 0 ) {
@@ -222,21 +265,18 @@ const yaml = __importStar(__nccwpck_require__(1917));
222265const dd = __importStar ( __nccwpck_require__ ( 1401 ) ) ;
223266function run ( ) {
224267 return __awaiter ( this , void 0 , void 0 , function * ( ) {
225- // try {
226268 const apiKey = core . getInput ( 'api-key' , { required : true } ) ;
227269 const apiURL = core . getInput ( 'api-url' ) || 'https://api.datadoghq.com' ;
270+ const ignoreTimeouts = core . getInput ( 'ignore-timeouts' ) === 'false' ;
228271 const metrics = yaml . safeLoad ( core . getInput ( 'metrics' ) ) || [ ] ;
229- yield dd . sendMetrics ( apiURL , apiKey , metrics ) ;
272+ yield dd . sendMetrics ( apiURL , apiKey , metrics , ignoreTimeouts ) ;
230273 const events = yaml . safeLoad ( core . getInput ( 'events' ) ) || [ ] ;
231- yield dd . sendEvents ( apiURL , apiKey , events ) ;
274+ yield dd . sendEvents ( apiURL , apiKey , events , ignoreTimeouts ) ;
232275 const serviceChecks = yaml . safeLoad ( core . getInput ( 'service-checks' ) ) || [ ] ;
233- yield dd . sendServiceChecks ( apiURL , apiKey , serviceChecks ) ;
276+ yield dd . sendServiceChecks ( apiURL , apiKey , serviceChecks , ignoreTimeouts ) ;
234277 const logApiURL = core . getInput ( 'log-api-url' ) || 'https://http-intake.logs.datadoghq.com' ;
235278 const logs = yaml . safeLoad ( core . getInput ( 'logs' ) ) || [ ] ;
236- yield dd . sendLogs ( logApiURL , apiKey , logs ) ;
237- // } catch (error) {
238- // core.setFailed(`Run failed: ${error.message}`)
239- // }
279+ yield dd . sendLogs ( logApiURL , apiKey , logs , ignoreTimeouts ) ;
240280 } ) ;
241281}
242282exports . run = run ;
0 commit comments