Truncate long queries in error logs#2794
Conversation
| response.Write([]byte(fmt.Sprintf("Length: %d\n", len(keys)))) | ||
| for _, v := range keys { | ||
| response.Write([]byte(fmt.Sprintf("%#v\n", utils.TruncateQuery(v)))) | ||
| response.Write([]byte(fmt.Sprintf("%#v\n", utils.TruncateQuery(v, 512)))) |
There was a problem hiding this comment.
I'll be fine with using sqldb.SQLErrorTruncateLen everywhere uniformly.
There was a problem hiding this comment.
My only thought on that is that they are somewhat orthogonal -- truncating in the UI isn't actually affecting errors so I'd want to name it something different.
|
@michael-berlin Do you have any thoughts? Change looks good to me, except for that one comment. |
|
Overall change looks good to me. See my comments on the flags discussion below. Reviewed 5 of 5 files at r2, 3 of 3 files at r3. go/sqldb/sql_error.go, line 10 at r3 (raw file):
Go readability: This must go in a separate group. go/sqldb/sql_error.go, line 22 at r3 (raw file):
I don't think you need this variable. It adds an extra indirection. Instead, you can just export go/vt/vttablet/endtoend/misc_test.go, line 536 at r3 (raw file):
Go readability: Surrounding parentheses are not needed. It looks like you're skipping the Git precommit hook. I thought it would complain about this? Can you please double check? go/vt/vttablet/tabletserver/query_engine.go, line 473 at r3 (raw file): Previously, demmer (Michael Demmer) wrote…
The 512 should be a constant because you're using it in several places and somebody may change it in one place and forget about the others. In the name of the constant you could reflect that the limit is meant as default for UI purposes. In general, I think it makes sense to have two different values for UI truncating and log truncating. How about just adding a second flag (instead of a constant)? The default value for the second flag could be 512 then. Comments from Reviewable |
|
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. go/sqldb/sql_error.go, line 22 at r3 (raw file): Previously, mberlin-bot (Michael Berlin) wrote…
I think what you mean here is define the flag locally here and use it internally? I don't think it needs to be exported out of here since nobody else reads the value. Comments from Reviewable |
|
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. go/sqldb/sql_error.go, line 22 at r3 (raw file): Previously, sougou-bot (Sugu Sougoumarane) wrote…
Yes, SGTM. What do you think about my other comment i.e. moving the 512 default value to a flag as well? Where should we define that flag? Comments from Reviewable |
|
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. go/sqldb/sql_error.go, line 22 at r3 (raw file): Previously, mberlin-bot (Michael Berlin) wrote…
I see that the value is used once in sqlparser and twice in tabletserver. If at all, maybe a constant in tabletserver and leave the one in sqlparser alone. Comments from Reviewable |
|
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. go/sqldb/sql_error.go, line 22 at r3 (raw file): Previously, sougou-bot (Sugu Sougoumarane) wrote…
It's also used in vtgate. Let's definitely make this a constant (ideally in go/vt/utils/utils.go) and not duplicate this magic value of 512. Instead of a constant, we could also add a function for that. // TruncateQueryForUI is used when displaying queries on various Vitess status pages.
// By truncating the query to 512 characters, we avoid that loading the page takes too long.
func TruncateQueryForUI(query string) string {
return TruncateQuery(query, 512)
}Comments from Reviewable |
|
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed. go/sqldb/sql_error.go, line 22 at r3 (raw file): Previously, mberlin-bot (Michael Berlin) wrote…
I had the same thought actually and did basically the same thing. Will polish up the tests and make sure it covers the cases that have been biting us in production. Comments from Reviewable |
0014ee7 to
a4543ce
Compare
|
Done Review status: 0 of 12 files reviewed at latest revision, 4 unresolved discussions. go/sqldb/sql_error.go, line 10 at r3 (raw file): Previously, mberlin-bot (Michael Berlin) wrote…
No longer relevant. go/vt/vttablet/endtoend/misc_test.go, line 536 at r3 (raw file): Previously, mberlin-bot (Michael Berlin) wrote…
I ended up moving around repositories to work with my VM and the symlinks were pointed at dead-ends. However even after fixing them I don't see to be able to get one of these to fail. go/vt/vttablet/tabletserver/query_engine.go, line 473 at r3 (raw file): Previously, mberlin-bot (Michael Berlin) wrote…
I ended up adding two functions and separate command line args for each. Comments from Reviewable |
|
@sougou @michael-berlin When manually forcing various errors I realized my previous attempts didn't actually truncate as expected. Reworked the implementation and verified this properly truncates errors from vttablet and vtgate. |
|
I was thinking you could also use sqlparser.SplitTrailingComment (https://github.com/youtube/vitess/blob/master/go/vt/sqlparser/comments.go#L14), and then truncate the query part only. |
|
@sougou That's a good idea... though perhaps for cleanliness I should move all the truncate functions into the |
|
Yeah. That sounds like a good idea. |
|
@sougou Updated as per your suggestion to preserve the comments. |
sougou
left a comment
There was a problem hiding this comment.
Change looks good. Couple of minor comments.
go/vt/vttablet/endtoend/misc_test.go
Outdated
There was a problem hiding this comment.
In all these tests, it may be simpler and more robust to do equality comparison with the exact output we want.
go/vt/sqlparser/truncate_query.go
Outdated
go/vt/vtgate/vtgate_test.go
Outdated
There was a problem hiding this comment.
Like in the other comment, you can build a wantVars variable and perform an equality comparison using reflect.DeepEqual.
As per PR feedback, added command line flags to separately control the maximum length of queries in the UI and in error logs. Also added additional cases for errors from vtgate.
After testing more cases in the actual deployment I realized that in several cases we actually have a protobuf object and therefore need to call fmt.Sprintf to generate the value before truncating the string.
1d09b58 to
223b887
Compare
|
@sougou Updated with your suggestions. |
This change is