-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Log Stackdriver request when it fails. #1824
Conversation
@@ -309,6 +310,12 @@ func (sink *StackdriverSink) sendOneRequest(req *sd_api.CreateTimeSeriesRequest) | |||
var responseCode int | |||
if err != nil { | |||
glog.Warningf("Error while sending request to Stackdriver %v", err) | |||
reqJson, errJson := json.Marshal(req) | |||
if errJson != nil { | |||
glog.Warningf("The request was %s", reqJson) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V(2)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also please print all requests as V(10)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few nits
func (sink *StackdriverSink) sendOneRequest(req *sd_api.CreateTimeSeriesRequest) { | ||
startTime := time.Now() | ||
empty, err := sink.stackdriverClient.Projects.TimeSeries.Create(fullProjectName(sink.project), req).Do() | ||
|
||
var responseCode int | ||
if err != nil { | ||
glog.Warningf("Error while sending request to Stackdriver %v", err) | ||
if glog.V(2) { | ||
marshalRequestAndLog(func(reqJson []byte) { | ||
glog.Warningf("The request was: %s", reqJson) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glog.Infof.V(2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no such syntax. There is glog.V(2).Infof, however. Quoting from glog doc, those two calls are (almost) equivalent:
if glog.V(2) { glog.Info("log this") }
glog.V(2).Info("log this")
The only difference is, when V(2) is false, the expression inside won't get evaluated. I'm using the former, since instead of simply logging a string I'm also lazy-evaluating conversion to json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was not clear enough. When you are reading the code IMO it's easier to understand:
if glog.V(2) {
glog.V(2).Info("log this") }
}
than
if glog.V(2) {
glog.Warninf("log this") }
}
because in the second case your first impression is that the log severity is Warning
, but then when you look closer, it turns out the this is in fact V(2)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, changed.
func (sink *StackdriverSink) sendOneRequest(req *sd_api.CreateTimeSeriesRequest) { | ||
startTime := time.Now() | ||
empty, err := sink.stackdriverClient.Projects.TimeSeries.Create(fullProjectName(sink.project), req).Do() | ||
|
||
var responseCode int | ||
if err != nil { | ||
glog.Warningf("Error while sending request to Stackdriver %v", err) | ||
if glog.V(2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a comment explaining this if?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
switch reflect.Indirect(reflect.ValueOf(err)).Type() { | ||
case reflect.Indirect(reflect.ValueOf(&googleapi.Error{})).Type(): | ||
responseCode = err.(*googleapi.Error).Code | ||
default: | ||
responseCode = httpResponseCodeUnknown | ||
} | ||
} else { | ||
if glog.V(10) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
switch reflect.Indirect(reflect.ValueOf(err)).Type() { | ||
case reflect.Indirect(reflect.ValueOf(&googleapi.Error{})).Type(): | ||
responseCode = err.(*googleapi.Error).Code | ||
default: | ||
responseCode = httpResponseCodeUnknown | ||
} | ||
} else { | ||
if glog.V(10) { | ||
marshalRequestAndLog(func(reqJson []byte) { | ||
glog.Infof("Stackdriver request sent: %s", reqJson) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glog.Infof.V(10)
cc @loburm |
62537e7
to
e48452a
Compare
Failed requests logged at log level 2. Successful ones logged at log level 10.
/lgtm |
@x13n could you please cherry-pick to release-1.4? |
More data for debugging.