This repository was archived by the owner on Dec 1, 2018. It is now read-only.
Commit 6b966a8 1 parent 600e70b commit 6b966a8 Copy full SHA for 6b966a8
File tree 1 file changed +22
-0
lines changed
metrics/sinks/stackdriver
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 15
15
package stackdriver
16
16
17
17
import (
18
+ "encoding/json"
18
19
"fmt"
19
20
"math/rand"
20
21
"net/url"
@@ -302,20 +303,41 @@ func (sink *StackdriverSink) requestSender(reqQueue chan *sd_api.CreateTimeSerie
302
303
}
303
304
}
304
305
306
+ func marshalRequestAndLog (printer func ([]byte ), req * sd_api.CreateTimeSeriesRequest ) {
307
+ reqJson , errJson := json .Marshal (req )
308
+ if errJson != nil {
309
+ printer (reqJson )
310
+ } else {
311
+ glog .Errorf ("Couldn't marshal Stackdriver request %v" , errJson )
312
+ }
313
+ }
314
+
305
315
func (sink * StackdriverSink ) sendOneRequest (req * sd_api.CreateTimeSeriesRequest ) {
306
316
startTime := time .Now ()
307
317
empty , err := sink .stackdriverClient .Projects .TimeSeries .Create (fullProjectName (sink .project ), req ).Do ()
308
318
309
319
var responseCode int
310
320
if err != nil {
311
321
glog .Warningf ("Error while sending request to Stackdriver %v" , err )
322
+ // Convert request to json and log it, but only if logging level is equal to 2 or more.
323
+ if glog .V (2 ) {
324
+ marshalRequestAndLog (func (reqJson []byte ) {
325
+ glog .V (2 ).Infof ("The request was: %s" , reqJson )
326
+ }, req )
327
+ }
312
328
switch reflect .Indirect (reflect .ValueOf (err )).Type () {
313
329
case reflect .Indirect (reflect .ValueOf (& googleapi.Error {})).Type ():
314
330
responseCode = err .(* googleapi.Error ).Code
315
331
default :
316
332
responseCode = httpResponseCodeUnknown
317
333
}
318
334
} else {
335
+ // Convert request to json and log it, but only if logging level is equal to 10 or more.
336
+ if glog .V (10 ) {
337
+ marshalRequestAndLog (func (reqJson []byte ) {
338
+ glog .V (2 ).Infof ("Stackdriver request sent: %s" , reqJson )
339
+ }, req )
340
+ }
319
341
responseCode = empty .ServerResponse .HTTPStatusCode
320
342
}
321
343
You can’t perform that action at this time.
0 commit comments