Repository navigation
Conversation
jorbaum
left a comment
There was a problem hiding this comment.
Thanks for fixing this. Looks almost ready. I found things worthy addressing.
d7e9064 to
82eab9d
Compare
Yes you did. An I thought of a different way of approaching this. It now calculates a ratio and tries to trim both values with the minimal amount of chars while keeping as much info as possible. |
jorbaum
left a comment
There was a problem hiding this comment.
Thanks for working on this so quickly and adding such a good amount of new tests :) .
I found one regression for sourceInstance == "" and one case where I am quite certain it still panics right now.
Its close to being ready. Please also keep in mind that this code is on a critical path for log forwarding and needs to be performant as in some environment we need to process a lot of logs. But I think the current code is fine as is in that respect. Please think about making it simpler by avoiding floating-point rounding complexity though. But again: it is fine as is.
73c3790 to
16f84db
Compare
109d784 to
2fd9a8d
Compare
while most of the values have been truncated, it seems that task names ( including their `APP/TASK/` prefix ) are not currently truncated. RFC5424 PROCID is limited to 128 bytes, but a valid CF task name (including its APP/TASK/ prefix) can exceed it. The old code sliced sourceInstance with a negative bound (`sourceInstance[:(128 - len(sourceType) - 3)]`), panicking the syslog agent and disrupting delivery to configured drains. It seems that similar issues could occur on deployments utilizing the agent given very long VM Names. This attempts to keep as much info as possible for the `/index` part of the templating. We assume that these values should contain either numerical indexes (app/task instances) or a UUID (vm) identifier. This attempts a truncated rendered PROCID while keeping maximum log-source identification info: - cut only when [sourceType/sourceInstance] doesn't fit in 128 bytes - cap sourceInstance at max 36 chars to keep UUID info and avoid issues for unexpected long values in sourceInstance - sourceType is only trimmed if the result of the above is still too long Fixes cloudfoundry#730
2fd9a8d to
4cbaacb
Compare
jorbaum
left a comment
There was a problem hiding this comment.
LGTM. I think this is ready for merging as is. I got one last idea to not always truncate instance ID to 36 chars.
|
|
||
| maxReturnLen-- | ||
|
|
||
| if len(sourceInstance)+len(sourceType) > maxReturnLen { |
There was a problem hiding this comment.
OPTIONAL: When len(sourceType)+len(sourceInstance) > 125 we now hard-cap sourceInstance to 36 chars even when sourceType is tiny. Think about truncating sourceType first, so we would have the same behavior from before even for edge cases like:
sourceType = "CELL" (4 chars), sourceInstance = a 123-char composite identifier
org-payments-prod.space-checkout-eu.app-fraud-scoring-v2.instance-9b1deb4d-…-2b0d7b3dcb6d.zone-eu10-az3-canary
┌──────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────────────────────────┐
│ │ rendered PROCID │ len │
├──────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────────────────────────┤
│ Previous │ [CELL/org-payments-prod.space-checkout-eu.app-fraud-scoring-v2.instance-9b1deb4d-…dcb6d.zone-eu10-az3-cana] │ 128 — keeps 121 of 123 chars │
├──────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────────────────────────┤
│ Current │ [CELL/org-payments-prod.space-checkout-eu.] │ 43 — hard-capped to 36 chars │
└──────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────────────────────────┘
There was a problem hiding this comment.
but I don't think that's how this will be populated?
I think sourceType will contain CELL/THE-CELL_NAME while sourceIndex will be /UUID or the /0
at least that's what my understanding of the code is currently. sourceInstance seems to contain the index ( numerical/uuid) but sourceType will contain the task/appname/vmname
There was a problem hiding this comment.
OPTIONAL: When len(sourceType)+len(sourceInstance) > 125 we now hard-cap sourceInstance to 36 chars even when sourceType is tiny. Think about truncating sourceType first, so we would have the same behavior from before even for edge cases like
We don't have to do some complex maths when we truncating the value. Whatever we do, we will never know how someone generates the strings. I would rather document how the transaction works and let the users suffer a bit and notice that they are doing some weird things.
IMO: Simple truncate from behind is all that we need
There was a problem hiding this comment.
but I don't think that's how this will be populated?
Yes. This is just me being overly cautious as both are a free-text string in the end even though they SHOULD follow the format you mentioned. Its just a hypothetical example I made up.
chombium
left a comment
There was a problem hiding this comment.
@nouseforaname, @jorbaum keep up the good work 💪
LGTM
The newest syslog-release brings new truncation behaviour in syslog agent. See cloudfoundry/loggregator-agent-release#731
while most of the values have been truncated, it seems that task names ( including their
APP/TASK/prefix ) are not currently truncated.e.g. given a sourceType value with length >= 126 and a sourceInstance != "", the previous state of the code would panic when trying to truncate sourceInstance (assuming sourceInstance is the reason we need to truncate):
for every sourceType >= 126 the above code will produce a panic.
this tries to lose the least amount of info to keep identification of log sources possible.
Type of change
Testing performed?
Checklist:
mainbranch, or relevant version branch