Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a panic when using show diagnostics with text/csv #9682

Merged
merged 1 commit into from
Apr 9, 2018

Conversation

jsternberg
Copy link
Contributor

If the columns change between series, it will now act as if it was a new
statement id and reprint the headers. This only happens with show
diagnostics at the moment and we shouldn't add this functionality
anywhere else anyway.

Fixes #9504.

@ghost ghost assigned jsternberg Apr 4, 2018
@ghost ghost added the review label Apr 4, 2018
@jsternberg jsternberg force-pushed the js-9504-csv-show-diagnostics-panic branch from 7242ac4 to c5ac172 Compare April 5, 2018 15:51
@@ -147,7 +148,29 @@ func (w *csvFormatter) WriteResponse(resp Response) (n int, err error) {
}
}

for _, row := range result.Series {
for i, row := range result.Series {
if i > 0 && !reflect.DeepEqual(result.Series[i-1].Columns, row.Columns) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are both string slices, can you make a helper method to compare them instead of using reflect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

w.columns[1] = "tags"
copy(w.columns[2:], row.Columns)
if err := csv.Write(w.columns); err != nil {
return n, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The n tracking is missing most of the csv calls - it's unfortunate that the csv.Writer doesn't expose the bytes written.

Assuming we do want to track n (for the QueryRequestBytesTransmitted stat), what do you think about using io.MultiWriter with the underlying w and some fake writer like

type countWriter struct { n int64 }
func (w *countWriter) Write(p []byte) (int, err) {
  w.n += len(p)
  return len(p), nil
}

so that we can properly track n?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be good. Can we open up another PR for that though? The behavior is already broken and I'm not breaking it anymore than it previously was.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing - opened #9690 to track it.

@jsternberg jsternberg force-pushed the js-9504-csv-show-diagnostics-panic branch from c5ac172 to 27f1372 Compare April 6, 2018 02:35
w.columns[1] = "tags"
copy(w.columns[2:], row.Columns)
if err := csv.Write(w.columns); err != nil {
return n, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing - opened #9690 to track it.

If the columns change between series, it will now act as if it was a new
statement id and reprint the headers. This only happens with show
diagnostics at the moment and we shouldn't add this functionality
anywhere else anyway.
@jsternberg jsternberg force-pushed the js-9504-csv-show-diagnostics-panic branch from 27f1372 to 243ed2e Compare April 9, 2018 14:09
@jsternberg jsternberg merged commit 529c028 into master Apr 9, 2018
@ghost ghost removed the review label Apr 9, 2018
@jsternberg jsternberg deleted the js-9504-csv-show-diagnostics-panic branch April 9, 2018 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants