Skip to content

Commit beb5a30

Browse files
authored
Merge pull request #161 from msaf1980/fix-clickhouse-summary
fix: logging for clickhouse query summary (no header)
2 parents 900590a + a8521b4 commit beb5a30

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

helper/clickhouse/clickhouse.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,21 @@ func reader(ctx context.Context, dsn string, query string, postBody io.Reader, g
247247
// chproxy overwrite our query id. So read it again
248248
chQueryID = resp.Header.Get("X-ClickHouse-Query-Id")
249249

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))
250+
summaryHeader := resp.Header.Get("X-Clickhouse-Summary")
251+
if len(summaryHeader) > 0 {
252+
summary := make(map[string]string)
253+
err = json.Unmarshal([]byte(summaryHeader), &summary)
254+
if err == nil {
255+
// TODO: use in carbon metrics sender when it will be implemented
256+
fields := make([]zapcore.Field, 0, len(summary))
257+
for k, v := range summary {
258+
fields = append(fields, zap.String(k, v))
259+
}
260+
logger = logger.With(fields...)
261+
} else {
262+
logger.Warn("query", zap.Error(err), zap.String("clickhouse-summary", summaryHeader))
263+
err = nil
257264
}
258-
logger = logger.With(fields...)
259265
}
260266

261267
// check for return 5xx error, may be 502 code if clickhouse accesed via reverse proxy

0 commit comments

Comments
 (0)