refactor log print

This commit is contained in:
Ulric Qin 2021-12-30 09:37:52 +08:00
parent 904d09d91c
commit a56d6b568b
1 changed files with 7 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package writer
import (
"bytes"
"context"
"fmt"
"net"
"net/http"
"time"
@ -44,6 +45,10 @@ type WriterType struct {
}
func (w WriterType) Write(items []*prompb.TimeSeries) {
if len(items) == 0 {
return
}
req := &prompb.WriteRequest{
Timeseries: items,
}
@ -56,6 +61,7 @@ func (w WriterType) Write(items []*prompb.TimeSeries) {
if err := w.Post(snappy.Encode(nil, data)); err != nil {
logger.Warningf("post to %s got error: %v", w.Opts.Url, err)
logger.Warning("example timeseries:", items[0].String())
}
}
@ -82,7 +88,7 @@ func (w WriterType) Post(req []byte) error {
}
if resp.StatusCode >= 400 {
logger.Warningf("push data with remote write request got status code: %v, response body: %s", resp.StatusCode, string(body))
err = fmt.Errorf("push data with remote write request got status code: %v, response body: %s", resp.StatusCode, string(body))
return err
}