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

server,log: report tenant names in logging output #108807

Merged
merged 5 commits into from
Aug 17, 2023

Conversation

knz
Copy link
Contributor

@knz knz commented Aug 15, 2023

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:

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.

@knz knz requested review from stevendanna, abarganier and a team August 15, 2023 20:33
@knz knz requested review from a team as code owners August 15, 2023 20:33
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@knz knz force-pushed the 20230815-log-tenant-name branch 3 times, most recently from 9c49d36 to 61a8641 Compare August 15, 2023 20:48
Copy link
Collaborator

@stevendanna stevendanna left a 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: :shipit: 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.

@knz knz force-pushed the 20230815-log-tenant-name branch from 61a8641 to 0244274 Compare August 16, 2023 10:16
Copy link
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: 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.

@knz knz requested a review from stevendanna August 16, 2023 10:17
Copy link
Collaborator

@stevendanna stevendanna left a 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.

Copy link
Contributor

@abarganier abarganier left a 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 :lgtm: - 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: :shipit: 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.

Copy link
Contributor

@abarganier abarganier left a comment

Choose a reason for hiding this comment

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

(approved)

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @knz and @stevendanna)

@knz knz force-pushed the 20230815-log-tenant-name branch from 0244274 to 8c15022 Compare August 17, 2023 20:02
@knz knz requested a review from a team as a code owner August 17, 2023 20:02
@knz knz requested review from herkolategan and DarrylWong and removed request for a team August 17, 2023 20:02
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.
@knz knz force-pushed the 20230815-log-tenant-name branch from 8c15022 to 3169b2a Compare August 17, 2023 20:11
Copy link
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: 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.

@knz
Copy link
Contributor Author

knz commented Aug 17, 2023

TFYR!

bors r=stevendanna,abargainier

@craig craig bot merged commit 02065f5 into cockroachdb:master Aug 17, 2023
@craig
Copy link
Contributor

craig bot commented Aug 17, 2023

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

util/log: log tenant identity using tenant name instead of ID
4 participants