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

sql: add SQLInstanceIDs to telemetry SampledQuery event #106753

Merged
merged 1 commit into from Jul 14, 2023
Merged

sql: add SQLInstanceIDs to telemetry SampledQuery event #106753

merged 1 commit into from Jul 14, 2023

Conversation

j82w
Copy link
Contributor

@j82w j82w commented Jul 13, 2023

This adds the SQLInstanceIDs which shows which SQLInstanceIDs the
statement was executed on to the SampledQuery event. This aligns the
data in statement statistics and the SampledQuery event.

Closes: #106719

Release note (bug fix): Added the missing SQLInstanceIDs used to
execute the statement to the telemetry SampledQuery event.

@j82w j82w requested a review from a team July 13, 2023 12:44
@j82w j82w requested review from a team as code owners July 13, 2023 12:45
@j82w j82w requested review from abarganier and DrewKimball and removed request for a team July 13, 2023 12:45
@cockroach-teamcity
Copy link
Member

This change is Reviewable

for sqlId := range queryLevelStats.SqlInstanceIds {
sqlInstanceIDs = append(sqlInstanceIDs, sqlId.String())
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

May I recommend you make the event type contain an array of integers (instead of an array of strings), then include the queryLevelStats.SqlInstanceIds slice directly into the event without conversion to string.

@j82w
Copy link
Contributor Author

j82w commented Jul 13, 2023

pkg/sql/exec_log.go line 332 at r1 (raw file):

Previously, knz (Raphael 'kena' Poss) wrote…

May I recommend you make the event type contain an array of integers (instead of an array of strings), then include the queryLevelStats.SqlInstanceIds slice directly into the event without conversion to string.

I went with a string for the following reasons. Let me know if you think I should still change it to an int?

  1. The type is a set using a map map[base.SQLInstanceID]struct{} so it would still need to be converted to an array.
  2. queryLevelStats.SqlInstanceIds shouldn't be included directly because the type is base.SQLInstanceID type. We don't want external users taking a dependency on that type.
  3. The string function has custom logic to represent 0 as ?. It's obvious that 0 is an invalid number.
  4. The current auto generated logic only supports repeated strings for some reason. Not sure if there is a reason for this.

Copy link
Contributor

@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.

Reviewed 3 of 5 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @abarganier, @DrewKimball, and @j82w)


pkg/sql/exec_log.go line 332 at r1 (raw file):

The type is a set using a map map[base.SQLInstanceID]struct{} so it would still need to be converted to an array.

Ah I had missed that. But converting a list of integers (which SQLInstanceID is under the hood - it's just an int32!) is cheaper than converting them to a list of strings.

queryLevelStats.SqlInstanceIds shouldn't be included directly because the type is base.SQLInstanceID type. We don't want external users taking a dependency on that type.

Agreed. The protobuf / event def would be defined to contain a list of integers, not SQLInstanceIDs.

The string function has custom logic to represent 0 as ?. It's obvious that 0 is an invalid number.

Why did you find it important to underline that? What does it buy you?
(I think it would be counter-productive to take the value 0 and put it in a structured log event.
If ever encounter 0 in production or a test, it is indicative of a bug! I'd be ok if we would just error out loudly if we ever find 0 in there.)

The current auto generated logic only supports repeated strings for some reason. Not sure if there is a reason for this.

There is already support for arrays of different types (specifically, string, uint32, LevelStats and protobuf). They are listed in log/eventpb/eventpbgen/gen.go and you can easily add a new one.
(Although for SQL instance IDs, you could just make-do with arrays of uint32 for now and rely on the existing code.)

@j82w
Copy link
Contributor Author

j82w commented Jul 13, 2023

pkg/sql/exec_log.go line 332 at r1 (raw file):
Done.

Why did you find it important to underline that? What does it buy you?

Most users and devs looking at logs won't know that 0 is a invalid issue that points to there being a bug. When possible I prefer to make it specific and avoid tribal knowledge.

(I think it would be counter-productive to take the value 0 and put it in a structured log event.
If ever encounter 0 in production or a test, it is indicative of a bug! I'd be ok if we would just error out loudly if we ever find 0 in there.)

I disagree because putting a 0 is the only way to find possible bugs. If we don't log the event or don't include the sql instance id it just makes it ambiguous for everyone. This is writing a log message so we don't want it fail the query or do anything to impact the workload. It's better to just log the bad number and to find it then to possibly cause an issue stopping a customer workload.

Copy link
Contributor

@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.

Reviewed 5 of 5 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @abarganier, @DrewKimball, and @j82w)


-- commits line 5 at r3:
nit: (here and below) i've noticed you often have heading spaces at the start of lines. I don't know where this comes from? but it stands out compared to the rest of the git log.


pkg/sql/exec_log.go line 332 at r1 (raw file):

Previously, j82w (Jake) wrote…

Done.

Why did you find it important to underline that? What does it buy you?

Most users and devs looking at logs won't know that 0 is a invalid issue that points to there being a bug. When possible I prefer to make it specific and avoid tribal knowledge.

(I think it would be counter-productive to take the value 0 and put it in a structured log event.
If ever encounter 0 in production or a test, it is indicative of a bug! I'd be ok if we would just error out loudly if we ever find 0 in there.)

I disagree because putting a 0 is the only way to find possible bugs. If we don't log the event or don't include the sql instance id it just makes it ambiguous for everyone. This is writing a log message so we don't want it fail the query or do anything to impact the workload. It's better to just log the bad number and to find it then to possibly cause an issue stopping a customer workload.

👍

@j82w
Copy link
Contributor Author

j82w commented Jul 13, 2023

-- commits line 5 at r3:

Previously, knz (Raphael 'kena' Poss) wrote…

nit: (here and below) i've noticed you often have heading spaces at the start of lines. I don't know where this comes from? but it stands out compared to the rest of the git log.

I'll fix it. I didn't notice it. I have vs code as my git editor and it seems like it adds it automatically. Not sure why.

This adds the SQLInstanceIDs which shows which SQLInstanceIDs the
statement was executed on to the SampledQuery event. This aligns the
data in statement statistics and the SampledQuery event.

Closes: #106719

Release note (bug fix): Added the missing SQLInstanceIDs used to
execute the statement to the telemetry SampledQuery event.
@j82w
Copy link
Contributor Author

j82w commented Jul 14, 2023

bors r+

@j82w j82w added the backport-23.1.x Flags PRs that need to be backported to 23.1 label Jul 14, 2023
@craig
Copy link
Contributor

craig bot commented Jul 14, 2023

Build succeeded:

@craig craig bot merged commit 26f3831 into cockroachdb:master Jul 14, 2023
7 checks passed
@blathers-crl
Copy link

blathers-crl bot commented Jul 14, 2023

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 6e12082 to blathers/backport-release-23.1-106753: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eventpb.SampledQuery event: add missing SQL instance IDs information
3 participants