@@ -3,6 +3,7 @@ package clickhouse
33import (
44 "context"
55 "encoding/binary"
6+ "encoding/json"
67 "errors"
78 "fmt"
89 "html"
@@ -18,6 +19,7 @@ import (
1819 "github.com/lomik/graphite-clickhouse/pkg/scope"
1920
2021 "go.uber.org/zap"
22+ "go.uber.org/zap/zapcore"
2123)
2224
2325type ErrDataParse struct {
@@ -189,6 +191,10 @@ func reader(ctx context.Context, dsn string, query string, postBody io.Reader, g
189191
190192 q := p .Query ()
191193 q .Set ("query_id" , fmt .Sprintf ("%s::%s" , requestID , queryID ))
194+ // Get X-Clickhouse-Summary header
195+ // TODO: remove when https://github.com/ClickHouse/ClickHouse/issues/16207 is done
196+ q .Set ("send_progress_in_http_headers" , "1" )
197+ q .Set ("http_headers_progress_interval_ms" , "10000" )
192198 p .RawQuery = q .Encode ()
193199
194200 var contentHeader string
@@ -241,6 +247,17 @@ func reader(ctx context.Context, dsn string, query string, postBody io.Reader, g
241247 // chproxy overwrite our query id. So read it again
242248 chQueryID = resp .Header .Get ("X-ClickHouse-Query-Id" )
243249
250+ summary := make (map [string ]string )
251+ err = json .Unmarshal ([]byte (resp .Header .Get ("X-Clickhouse-Summary" )), & summary )
252+ if err == nil {
253+ // TODO: use in carbon metrics sender when it will be implemented
254+ fields := make ([]zapcore.Field , 0 , len (summary ))
255+ for k , v := range summary {
256+ fields = append (fields , zap .String (k , v ))
257+ }
258+ logger = logger .With (fields ... )
259+ }
260+
244261 // check for return 5xx error, may be 502 code if clickhouse accesed via reverse proxy
245262 if resp .StatusCode > 500 && resp .StatusCode < 512 {
246263 body , _ := ioutil .ReadAll (resp .Body )
0 commit comments