-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
server,log: report tenant names in logging output #108807
Conversation
9c49d36
to
61a8641
Compare
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.
Thanks for all the nice small cleanups that you did along the way here.
I left minor comments and question, take those that are useful, leave the rest.
While reading I had the vague sense of "V seems like a letter we might want in the future for something else" with respect to the log tag. But, staring at my keyboard I don't see a letter I like particularly better.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @abarganier and @knz)
pkg/server/server_sql.go
line 1422 at r5 (raw file):
if entry, _ := s.tenantConnect.TenantInfo(); entry.Name != "" { s.cfg.idProvider.SetTenantName(entry.Name) }
Perhaps we should comment on the behaviour on RENAME.
It looks to me like rename isn't handled currently. I'm OK with not handling it yet. I think we could probably handle it by extending our startCheckService routine to also update the name if it sees a name update during its polling.
pkg/util/log/format_crdb.go
line 28 at r5 (raw file):
// tenantNameLogTagKey is the log tag key used when tagging // log entries with a tenant name. const tenantNameLogTagKey = 'V'
I imagine this is V
for "Virtual Cluster"?
pkg/util/log/format_crdb_v1.go
line 342 at r5 (raw file):
// and a size estimate for the printout of the label. func checkTenantLabel(tenantID string, tenantName string) (hasLabel bool, length int) { return tenantID != "", len(tenantID) + len("T,L,") + len(tenantName)
It doesn't matter for the size estimate. But what is the L here?
pkg/util/log/format_crdb_v2.go
line 722 at r5 (raw file):
func (f entryDecoderV2Fragment) getTenantDetails() (tenantID, tenantName string) { tags := f[v2TagsIdx] if bytes.Equal(tags, []byte("-")) {
This is in the existing code as well, but it could be helpful to move this to a constant just so we can put a comment on it that explains what it is a marker for.
pkg/util/log/format_json.go
line 260 at r5 (raw file):
} const serverIdentifierFields = "NxqTL"
Should this be s/L/V/?
pkg/util/log/format_crdb_v1_test.go
line 205 at r5 (raw file):
tc := []struct { in string expOut string
[nit] expRemainder
might be a slightly better name.
61a8641
to
0244274
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @abarganier and @stevendanna)
pkg/server/server_sql.go
line 1422 at r5 (raw file):
Previously, stevendanna (Steven Danna) wrote…
Perhaps we should comment on the behaviour on RENAME.
It looks to me like rename isn't handled currently. I'm OK with not handling it yet. I think we could probably handle it by extending our startCheckService routine to also update the name if it sees a name update during its polling.
We have litigated this already in the last cycle: name changes are not allowed when the service mode is not NONE.
I added an explanatory comment here and a reminder in sql/tenant_update.go.
pkg/util/log/format_crdb.go
line 28 at r5 (raw file):
Previously, stevendanna (Steven Danna) wrote…
I imagine this is
V
for "Virtual Cluster"?
It's the nearest I could come to something we could explain. All the other "interesting" letters were taken already.
pkg/util/log/format_crdb_v1.go
line 342 at r5 (raw file):
Previously, stevendanna (Steven Danna) wrote…
It doesn't matter for the size estimate. But what is the L here?
Done.
pkg/util/log/format_crdb_v2.go
line 722 at r5 (raw file):
Previously, stevendanna (Steven Danna) wrote…
This is in the existing code as well, but it could be helpful to move this to a constant just so we can put a comment on it that explains what it is a marker for.
Done.
pkg/util/log/format_json.go
line 260 at r5 (raw file):
Previously, stevendanna (Steven Danna) wrote…
Should this be s/L/V/?
Done.
pkg/util/log/format_crdb_v1_test.go
line 205 at r5 (raw file):
Previously, stevendanna (Steven Danna) wrote…
[nit]
expRemainder
might be a slightly better name.
Done.
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.
Reviewable has eaten my follow up twice. TLDR: Thanks for addressing my comments. Thanks for the explanatory comment on the rename case. Looks good to me.
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.
Note: we are choosing to report the tenant name in addition to the
tenant ID to preserve compatibility with automation (eg. logspy) which
needs to filter entries based on ID.
Ack, thanks for noting this compatibility!
This - happy to see the tenant names finally make their way into logs! I know some up-front work was required to make the names available to the tenants in the first place, so thank you for all the effort to make that happen.
Reviewed 1 of 6 files at r6.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @knz and @stevendanna)
pkg/util/log/format_crdb.go
line 28 at r5 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
It's the nearest I could come to something we could explain. All the other "interesting" letters were taken already.
I'm okay with the V
- as long as it's unique and documented, it works fine. Also, "Virtual Cluster" is a good explanation for it!
And agreed, all the "good" letters are already spoken for it seems 😅
pkg/util/log/format_crdb_v1.go
line 387 at r6 (raw file):
// The remainder is variable-length and could exceed // the static size of tmp. But we do have an upper bound. buf.Grow(len(entry.Tags)*2 + tenantLabelLength + 14 + len(entry.Message))
len(entry.Tags)*2
? Does this mean we're increasing the upper bound?
pkg/util/log/format_crdb_v1.go
line 584 at r6 (raw file):
hasTenantID, tenantID, tagsToProcess = maybeReadOneTag(tagsToProcess, tenantIDLogTagBytePrefix) if !hasTenantID { return serverident.SystemTenantID, "", tagsToProcess
This assumes that if there's no tenant ID tag, there's also no tenant name tag. Is that a safe assumption to make for the future? I wonder if we should check for the tenant name anyway to protect against things changing around that assumption later on.
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.
(approved)
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @knz and @stevendanna)
Release note: None
Release note: None
Release note: None
Release note: None
0244274
to
8c15022
Compare
Prior to this patch, the tenant details reported in logging output were limited to just the tenant ID. This is because the original tenant server initialization code only had access to the tenant ID (provided as CLI argument). Since recently, the tenant name is also becoming known during tenant server initialization. This is currently done via the tenant connector. This commit expands on this foundation by injecting the tenant name into the logging output as soon as it is available. For example: ``` I230815 19:31:07.290757 922 sql/temporary_schema.go:554 ⋮ [T4,Vblah,n1] 148 found 0 temporary schemas ^^^^^ here ``` or using JSON: ``` {"channel_numeric":0,"channel":"DEV",...,"tenant_id":4,"tenant_name":"blah",...} ^^^^^^^^^^^^^^^^^^^^ here ``` Note: we are choosing to report the tenant name *in addition* to the tenant ID to preserve compatibilit with automation (eg. logspy) which needs to filter entries based on ID. Release note (cluster virtualization): The name of the virtual cluster (tenant), when known, is now reported in logging events. Refer to the documentation of individual logging format for details.
8c15022
to
3169b2a
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @abarganier, @DarrylWong, @herkolategan, and @stevendanna)
pkg/util/log/format_crdb_v1.go
line 387 at r6 (raw file):
Previously, abarganier (Alex Barganier) wrote…
len(entry.Tags)*2
? Does this mean we're increasing the upper bound?
This is an optimistic upper bound (the buffer can grow larger).
The *3
is a fix for a buglet: the estimate should include 1 character for the key, one for the value and one for the comma.
pkg/util/log/format_crdb_v1.go
line 584 at r6 (raw file):
Previously, abarganier (Alex Barganier) wrote…
This assumes that if there's no tenant ID tag, there's also no tenant name tag. Is that a safe assumption to make for the future? I wonder if we should check for the tenant name anyway to protect against things changing around that assumption later on.
Added an explanatory comment.
The main reason is that if the name is known, but the ID is not, we get two separate problems:
- we have logic in place in a couple points which auto-default the ID to SystemTenantID when not known.
- all our filtering logic currently requires an ID. We can't afford not to have one. What ID to choose if there's none but there's a name?
In both cases it would be misleading to do that while keeping a secondary tenant name. Until these limitations are addressed, we can fold secondary tenant entries with just a name into the system tenant's event stream. It merely makes the entries hard(er) to find.
TFYR! bors r=stevendanna,abargainier |
Build succeeded: |
Epic: CRDB-27982
Fixes #103406.
Prior to this change, the tenant details reported in logging output
were limited to just the tenant ID. This is because the original
tenant server initialization code only had access to the tenant
ID (provided as CLI argument).
Since recently, the tenant name is also becoming known during tenant
server initialization. This is currently done via the tenant
connector.
This commit expands on this foundation by injecting the tenant name
into the logging output as soon as it is available.
For example:
or using JSON:
Note: we are choosing to report the tenant name in addition to the
tenant ID to preserve compatibilit with automation (eg. logspy) which
needs to filter entries based on ID.
Release note (cluster virtualization): The name of the virtual
cluster (tenant), when known, is now reported in logging events.
Refer to the documentation of individual logging format for details.