refactor: add more tracing information to writes

pull/16118/head
Edd Robinson 2019-12-04 18:50:26 +00:00
parent 9f643126f1
commit d367aee428
2 changed files with 17 additions and 0 deletions

View File

@ -90,6 +90,15 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
userAgent = "unknown"
}
span.LogKV("user_agent", userAgent, "referer", r.Referer(), "remote_addr", r.RemoteAddr)
for k, v := range r.Header {
if len(v) == 0 {
continue
}
// If header has multiple values, only the first value will be logged on the trace.
span.LogKV(k, v[0])
}
defer span.Finish()
// TODO: better way to do this?

View File

@ -145,6 +145,7 @@ func (h *WriteHandler) handleWrite(w http.ResponseWriter, r *http.Request) {
}
orgID = org.ID
span.LogKV("org_id", orgID)
var bucket *influxdb.Bucket
if id, err := influxdb.IDFromString(req.Bucket); err == nil {
@ -173,6 +174,7 @@ func (h *WriteHandler) handleWrite(w http.ResponseWriter, r *http.Request) {
bucket = b
}
span.LogKV("bucket_id", bucket.ID)
p, err := influxdb.NewPermissionAtID(bucket.ID, influxdb.WriteAction, influxdb.BucketsResourceType, org.ID)
if err != nil {
@ -197,7 +199,10 @@ func (h *WriteHandler) handleWrite(w http.ResponseWriter, r *http.Request) {
// TODO(jeff): we should be publishing with the org and bucket instead of
// parsing, rewriting, and publishing, but the interface isn't quite there yet.
// be sure to remove this when it is there!
span, _ = tracing.StartSpanFromContextWithOperationName(ctx, "read request body")
data, err := ioutil.ReadAll(in)
span.LogKV("request_bytes", len(data))
span.Finish()
if err != nil {
logger.Error("Error reading body", zap.Error(err))
h.HandleHTTPError(ctx, &influxdb.Error{
@ -219,9 +224,12 @@ func (h *WriteHandler) handleWrite(w http.ResponseWriter, r *http.Request) {
return
}
span, _ = tracing.StartSpanFromContextWithOperationName(ctx, "encoding and parsing")
encoded := tsdb.EncodeName(org.ID, bucket.ID)
mm := models.EscapeMeasurement(encoded[:])
points, err := models.ParsePointsWithPrecision(data, mm, time.Now(), req.Precision)
span.LogKV("values_total", len(points))
span.Finish()
if err != nil {
logger.Error("Error parsing points", zap.Error(err))
h.HandleHTTPError(ctx, &influxdb.Error{