@@ -38,24 +38,27 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3838exports . sendLogs = exports . sendServiceChecks = exports . sendEvents = exports . sendMetrics = exports . getClient = void 0 ;
3939const core = __importStar ( __nccwpck_require__ ( 2186 ) ) ;
4040const httpm = __importStar ( __nccwpck_require__ ( 9925 ) ) ;
41- function getClient ( apiKey ) {
41+ function getClient ( apiKey , timeout ) {
4242 return new httpm . HttpClient ( 'dd-http-client' , [ ] , {
4343 headers : {
4444 'DD-API-KEY' : apiKey ,
4545 'Content-Type' : 'application/json'
46- }
46+ } ,
47+ socketTimeout : timeout
4748 } ) ;
4849}
4950exports . getClient = getClient ;
5051function isTimeoutError ( error ) {
51- return error . message . includes ( 'timeout' ) || error . message . includes ( 'Timeout' ) ;
52+ // force the error into a string so it both works for Error instances and plain strings
53+ const error_msg = `${ error } ` ;
54+ return error_msg . includes ( 'timeout' ) || error_msg . includes ( 'Timeout' ) ;
5255}
5356function postMetricsIfAny ( http , apiURL , metrics , endpoint , ignoreTimeouts ) {
5457 return __awaiter ( this , void 0 , void 0 , function * ( ) {
5558 // POST data
5659 if ( metrics . series . length ) {
5760 try {
58- core . debug ( `About to send ${ metrics . series . length } metrics` ) ;
61+ core . debug ( `About to send ${ metrics . series . length } metrics to ${ apiURL } /api/ ${ endpoint } ` ) ;
5962 const res = yield http . post ( `${ apiURL } /api/${ endpoint } ` , JSON . stringify ( metrics ) ) ;
6063 if ( res . message . statusCode === undefined ||
6164 res . message . statusCode >= 400 ) {
@@ -72,9 +75,9 @@ function postMetricsIfAny(http, apiURL, metrics, endpoint, ignoreTimeouts) {
7275 }
7376 } ) ;
7477}
75- function sendMetrics ( apiURL , apiKey , metrics , ignoreTimeouts ) {
78+ function sendMetrics ( apiURL , apiKey , metrics , ignoreTimeouts , timeout ) {
7679 return __awaiter ( this , void 0 , void 0 , function * ( ) {
77- const http = getClient ( apiKey ) ;
80+ const http = getClient ( apiKey , timeout ) ;
7881 // distributions use a different procotol.
7982 const distributions = { series : Array ( ) } ;
8083 const otherMetrics = { series : Array ( ) } ;
@@ -97,11 +100,11 @@ function sendMetrics(apiURL, apiKey, metrics, ignoreTimeouts) {
97100 } ) ;
98101}
99102exports . sendMetrics = sendMetrics ;
100- function sendEvents ( apiURL , apiKey , events , ignoreTimeouts ) {
103+ function sendEvents ( apiURL , apiKey , events , ignoreTimeouts , timeout ) {
101104 return __awaiter ( this , void 0 , void 0 , function * ( ) {
102- const http = getClient ( apiKey ) ;
105+ const http = getClient ( apiKey , timeout ) ;
103106 let errors = 0 ;
104- core . debug ( `About to send ${ events . length } events` ) ;
107+ core . debug ( `About to send ${ events . length } events to ${ apiURL } /api/v1/events ` ) ;
105108 for ( const ev of events ) {
106109 try {
107110 const res = yield http . post ( `${ apiURL } /api/v1/events` , JSON . stringify ( ev ) ) ;
@@ -125,11 +128,11 @@ function sendEvents(apiURL, apiKey, events, ignoreTimeouts) {
125128 } ) ;
126129}
127130exports . sendEvents = sendEvents ;
128- function sendServiceChecks ( apiURL , apiKey , serviceChecks , ignoreTimeouts ) {
131+ function sendServiceChecks ( apiURL , apiKey , serviceChecks , ignoreTimeouts , timeout ) {
129132 return __awaiter ( this , void 0 , void 0 , function * ( ) {
130- const http = getClient ( apiKey ) ;
133+ const http = getClient ( apiKey , timeout ) ;
131134 let errors = 0 ;
132- core . debug ( `About to send ${ serviceChecks . length } service checks` ) ;
135+ core . debug ( `About to send ${ serviceChecks . length } service checks to ${ apiURL } /api/v1/check_run ` ) ;
133136 for ( const sc of serviceChecks ) {
134137 try {
135138 const res = yield http . post ( `${ apiURL } /api/v1/check_run` , JSON . stringify ( sc ) ) ;
@@ -153,11 +156,11 @@ function sendServiceChecks(apiURL, apiKey, serviceChecks, ignoreTimeouts) {
153156 } ) ;
154157}
155158exports . sendServiceChecks = sendServiceChecks ;
156- function sendLogs ( logApiURL , apiKey , logs , ignoreTimeouts ) {
159+ function sendLogs ( logApiURL , apiKey , logs , ignoreTimeouts , timeout ) {
157160 return __awaiter ( this , void 0 , void 0 , function * ( ) {
158- const http = getClient ( apiKey ) ;
161+ const http = getClient ( apiKey , timeout ) ;
159162 let errors = 0 ;
160- core . debug ( `About to send ${ logs . length } logs` ) ;
163+ core . debug ( `About to send ${ logs . length } logs to ${ logApiURL } /v1/input ` ) ;
161164 for ( const log of logs ) {
162165 try {
163166 const res = yield http . post ( `${ logApiURL } /v1/input` , JSON . stringify ( log ) ) ;
@@ -267,16 +270,17 @@ function run() {
267270 return __awaiter ( this , void 0 , void 0 , function * ( ) {
268271 const apiKey = core . getInput ( 'api-key' , { required : true } ) ;
269272 const apiURL = core . getInput ( 'api-url' ) || 'https://api.datadoghq.com' ;
270- const ignoreTimeouts = core . getInput ( 'ignore-timeouts' ) === 'false' ;
273+ const ignoreTimeouts = core . getInput ( 'ignore-timeouts' ) === 'true' ;
274+ const timeout = parseInt ( core . getInput ( 'timeout' ) ) || 30000 ;
271275 const metrics = yaml . safeLoad ( core . getInput ( 'metrics' ) ) || [ ] ;
272- yield dd . sendMetrics ( apiURL , apiKey , metrics , ignoreTimeouts ) ;
276+ yield dd . sendMetrics ( apiURL , apiKey , metrics , ignoreTimeouts , timeout ) ;
273277 const events = yaml . safeLoad ( core . getInput ( 'events' ) ) || [ ] ;
274- yield dd . sendEvents ( apiURL , apiKey , events , ignoreTimeouts ) ;
278+ yield dd . sendEvents ( apiURL , apiKey , events , ignoreTimeouts , timeout ) ;
275279 const serviceChecks = yaml . safeLoad ( core . getInput ( 'service-checks' ) ) || [ ] ;
276- yield dd . sendServiceChecks ( apiURL , apiKey , serviceChecks , ignoreTimeouts ) ;
280+ yield dd . sendServiceChecks ( apiURL , apiKey , serviceChecks , ignoreTimeouts , timeout ) ;
277281 const logApiURL = core . getInput ( 'log-api-url' ) || 'https://http-intake.logs.datadoghq.com' ;
278282 const logs = yaml . safeLoad ( core . getInput ( 'logs' ) ) || [ ] ;
279- yield dd . sendLogs ( logApiURL , apiKey , logs , ignoreTimeouts ) ;
283+ yield dd . sendLogs ( logApiURL , apiKey , logs , ignoreTimeouts , timeout ) ;
280284 } ) ;
281285}
282286exports . run = run ;
0 commit comments