This repository was archived by the owner on Dec 1, 2018. It is now read-only.
Commit df89170 1 parent 600e70b commit df89170 Copy full SHA for df89170
File tree 1 file changed +20
-0
lines changed
metrics/sinks/stackdriver
1 file changed +20
-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,39 @@ func (sink *StackdriverSink) requestSender(reqQueue chan *sd_api.CreateTimeSerie
302
303
}
303
304
}
304
305
306
+ func marshalRequestAndLog (printer func (string ), 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
+ if glog .V (2 ) {
323
+ marshalRequestAndLog (func (reqJson string ) {
324
+ glog .Warningf ("The request was: %s" , reqJson )
325
+ }, req )
326
+ }
312
327
switch reflect .Indirect (reflect .ValueOf (err )).Type () {
313
328
case reflect .Indirect (reflect .ValueOf (& googleapi.Error {})).Type ():
314
329
responseCode = err .(* googleapi.Error ).Code
315
330
default :
316
331
responseCode = httpResponseCodeUnknown
317
332
}
318
333
} else {
334
+ if glog .V (10 ) {
335
+ marshalRequestAndLog (func (reqJson string ) {
336
+ glog .Infof ("Stackdriver request sent: %s" , reqJson )
337
+ }, req )
338
+ }
319
339
responseCode = empty .ServerResponse .HTTPStatusCode
320
340
}
321
341
You can’t perform that action at this time.
0 commit comments