-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix(library): add error field truncating #231
Conversation
Codecov Report
@@ Coverage Diff @@
## master #231 +/- ##
=======================================
Coverage 97.06% 97.06%
=======================================
Files 53 53
Lines 5794 5797 +3
=======================================
+ Hits 5624 5627 +3
Misses 125 125
Partials 45 45
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which part of the error is most likely to include the useful bits? In python, I always want the end of the traceback. I'm still too new to go to say for sure.
What if you took the first and last 250 characters, dropping everything in the middle?
I like this idea. Most errors contain the vital information in the beginning or end. |
Also, wonder if in addition to character limits if we should just support more characters for the field in the database. I don't think it would be super harmful to allow 1000 characters. |
Is it possible to place the truncation code to the "last responsible moment" so that within any libraries or other bits of code that want to use the full error, they can, but when we go to place the data into the database we're only saving the important bits? I don't have context into if you've already explored that, but could reduce the code duplication and not preemptively truncate before we need to do so. Otherwise it looks good and I don't see any obvious issues. Thanks for your contribution! |
constants/limit.go
Outdated
@@ -24,6 +24,9 @@ const ( | |||
// BuildTimeoutDefault defines the default value in minutes for repo build timeout. | |||
BuildTimeoutDefault = 30 | |||
|
|||
// ErrorLimit defines the maximum size in characters for resource error fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, one small thing, this comment is helpful, but it doesn't let anyone know what happens if the limit is exceeded. They'd have to dig into the code to understand that half of the beginning and half of the end are kept. It might be beneficial for future folks looking in the codebase to understand the intent of that and what happens if it gets exceeded.
I relocated these changes to be within the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! This all looks good to me.
database/build.go
Outdated
@@ -27,6 +27,8 @@ const ( | |||
maxTitleLength = 1000 | |||
// Maximum message field length. | |||
maxMessageLength = 2000 | |||
// Maximum error field length. | |||
maxErrorLength = 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @kneal 👍
We should explore expanding the number of chars we allow for the error
field across all resources.
Doubling it from 500
-> 1000
sounds like a fair place to start 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's currently a somewhat rare occurrence (afaik) so handling the outliers this way instead of having the outliers shape the data size seems fine to me. do we expect this be more commonplace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal view would be I don't think that field has ever changed in size. So, maybe this is showing errors that could be growing in size. I also don't think 1000
is that big of a concern and then would save us having to parse errors and hopefully not cut off the important part. If we had to go beyond 1000
then I think truncating could be useful.
I'm also not sure if we use error wrapping everywhere in the worker/runtime to make these errors longer so depending how errors are handled or want to be handled long term in that codebase 1000
might be the norm but I honestly don't know. The error:
field in the build resource is entirely for admins because thats where we populate a platform error. So, cutting off the data really only hurts ourselves for richer research.
We should explore expanding the number of chars we allow for the error field across all resources.
@jbrockopp probably not a bad idea since I don't think that's ever been done. I assume most of these char lengths are there original defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good callout on error wrapping! in other words, it has good chances of becoming larger. I'm good with bumping to 1000
then 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if we bump the limit to 1000, do we still want to crop the value if it exceeds that limit? Or do we have another idea for an approach to that situation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other idea I have would be compression if we wanna keep the field small but keep the full error messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you support compressing the other fields currently being processed by the crop
method? (message
and title
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the answer to that one. I think for error it might make sense to compress because that field could be quite variable depending on how the error wrapping works.
Title and Message might make sense to crop or inherit because those come from the SCM system attached and I would assume GitHub has limits on those. So, it might make sense to just mirror those limits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if we bump the limit to 1000, do we still want to crop the value if it exceeds that limit? Or do we have another idea for an approach to that situation?
I'm onboard with the idea of a "simple" cropping strategy similar to title
and message
.
In the future, if this becomes a problem with the 1000
char limit, then we should introduce compression.
database/build.go
Outdated
if len(b.Error.String) > maxErrorLength { | ||
front := maxErrorLength - (maxErrorLength / 2) | ||
end := len(b.Error.String) - (maxErrorLength / 2) | ||
str := b.Error.String[:front] + b.Error.String[end:] | ||
b.Error = sql.NullString{String: str, Valid: true} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we're taking the right approach here? 😅
Personally, I'd rather start with increasing the number of characters before going down this route 👍
If we feel that's insufficient, then we should use compression for the error
field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand not wanting to process string logic like this, but I am curious as to why the message
and title
fields get cropped in a similar fashion?
Also, I do wonder if it may be more efficient to handle larger errors by referencing the log from which it came rather than attempt to store some truncated version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To your point, I think we might put the errors in STDOUT but I can't be sure about that. A big advantage to why we added the error field was to track platform errors that occur in the runtime and have them uniquely identified vs the user error in a container.
Having the field exposed here also in the past made it easier for admins to do their own support because they didn't have to go digging through logs to find the error or crash log. They could just see the information directly in the build and troubleshoot that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes Issue 468
On rare occasions, the error generated by a step exceeds our database limit of 500 characters. When this happens, the build hangs and does not complete. This PR makes sure we don't set the error field to a value we can't support in the database.