Browse Source

refactor: remote write log print

tags/v5.8.0
710leo 5 years ago
parent
commit
e27ec8136e
2 changed files with 23 additions and 2 deletions
  1. +22
    -1
      backend/prome/convert.go
  2. +1
    -1
      backend/prome/prome.go

+ 22
- 1
backend/prome/convert.go View File

@@ -19,6 +19,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/prompb"
"github.com/toolkits/pkg/logger"

"github.com/didi/nightingale/v5/vos"
)
@@ -137,8 +138,15 @@ func remoteWritePost(c *HttpClient, req []byte) error {
if scanner.Scan() {
line = scanner.Text()
}
err = errors.Errorf("server returned HTTP status %s: %s", httpResp.Status, line)

if httpResp.StatusCode == 400 {
//400的错误是客户端的问题,不返回给上层,输出到debug日志中
logger.Debugf("server returned HTTP status %s: %s req:%v", httpResp.Status, line, getSamples(req))
} else {
err = errors.Errorf("server returned HTTP status %s: %s", httpResp.Status, line)
}
}

if httpResp.StatusCode/100 == 5 {
return RecoverableError{err}
}
@@ -160,3 +168,16 @@ func (pd *PromeDataSource) buildWriteRequest(samples []prompb.TimeSeries) ([]byt
compressed := snappy.Encode(nil, data)
return compressed, nil
}

func getSamples(compressed []byte) []prompb.TimeSeries {
var samples []prompb.TimeSeries
req := &prompb.WriteRequest{
Timeseries: samples,
Metadata: nil,
}

d, _ := snappy.Decode(nil, compressed)
proto.Unmarshal(d, req)

return req.Timeseries
}

+ 1
- 1
backend/prome/prome.go View File

@@ -247,7 +247,7 @@ func (pd *PromeDataSource) processWrite(payload []byte) {
if !sendOk {
logger.Errorf("send prome finally fail: %v", finalErr)
} else {
logger.Infof("send to prome %s ok", cc.url.String())
logger.Debugf("send to prome %s ok", cc.url.String())
}
}(newC, payload)
}


Loading…
Cancel
Save