Skip to content

C++: Initial telemetry queries #17892

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

Merged
merged 14 commits into from
Nov 12, 2024
Merged

C++: Initial telemetry queries #17892

merged 14 commits into from
Nov 12, 2024

Conversation

calumgrant
Copy link
Contributor

@calumgrant calumgrant commented Nov 1, 2024

This adds new internal telemetry queries, so should not need a changenote.

It loosely follows the examples in https://github.com/github/codeql/tree/main/java/ql/src/Telemetry and https://github.com/github/codeql/tree/main/csharp/ql/src/Telemetry.

As a new idea, Metrics.qll uses QL classes a bit more heavily, instead of binary predicates, but obviously they boil down to the same thing.

We don't (yet) emit a diagnostic warning about low quality databases.

Note that qltest can't test for missing includes, since these lead to a catastrophic error by default.

Fixes https://github.com/github/codeql-c-team/issues/2471

Pull Request checklist

All query authors

Internal query authors only

  • [ ] Autofixes generated based on these changes are valid, only needed if this PR makes significant changes to .ql, .qll, or .qhelp files. See the documentation (internal access required).
  • Changes are validated at scale (internal access required).
  • [ ] Adding a new query? Consider also adding the query to autofix.

@github-actions github-actions bot added the C++ label Nov 1, 2024
@calumgrant calumgrant force-pushed the calumgrant/telemetry branch 2 times, most recently from 913056a to 8035a7c Compare November 1, 2024 17:08
@calumgrant calumgrant marked this pull request as ready for review November 4, 2024 09:28
@calumgrant calumgrant requested a review from a team as a code owner November 4, 2024 09:28
Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

Is there are specific reason we're not re-using some of the functionality already present in cpp/ql/src/Diagnostics?

@calumgrant
Copy link
Contributor Author

Is there are specific reason we're not re-using some of the functionality already present in cpp/ql/src/Diagnostics?

The code in cpp/ql/src/Diagnostics isn't really that helpful, mainly because it's in the wrong format and has @kind diagnostic.

@jketema
Copy link
Contributor

jketema commented Nov 4, 2024

Is there are specific reason we're not re-using some of the functionality already present in cpp/ql/src/Diagnostics?

The code in cpp/ql/src/Diagnostics isn't really that helpful, mainly because it's in the wrong format and has @kind diagnostic.

Not even the libraries in that directory are of use?

Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

Some questions about the used tags.

@calumgrant
Copy link
Contributor Author

Is there are specific reason we're not re-using some of the functionality already present in cpp/ql/src/Diagnostics?

The code in cpp/ql/src/Diagnostics isn't really that helpful, mainly because it's in the wrong format and has @kind diagnostic.

Not even the libraries in that directory are of use?

Well, telemetry is a bit simpler because it's a question of dumping counts and raw data, so we don't need to refine them in the same way.

@calumgrant calumgrant added the no-change-note-required This PR does not need a change note label Nov 4, 2024
@calumgrant calumgrant force-pushed the calumgrant/telemetry branch from 201f282 to ac692ee Compare November 4, 2024 14:04
@calumgrant calumgrant force-pushed the calumgrant/telemetry branch from 4fc90ca to 8029eb2 Compare November 8, 2024 14:38
CannotOpenFile() { this.hasTag(["cannot_open_file", "cannot_open_file_reason"]) }

string getIncludedFile() {
result = this.getMessage().regexpCapture("cannot open source file '([^']+)'", 1)
Copy link
Contributor

@jketema jketema Nov 11, 2024

Choose a reason for hiding this comment

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

Note that this regex does not what you want in the case of cannot_open_file_reason, i.e., you get the reason as part of the result string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I've no real way of testing this as I've never seen the extractor produce this error message. I suppose a .* at the end of the regex might be reasonable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are the file names always quoted? This is non-obvious from the frontend source code.

Copy link
Contributor Author

@calumgrant calumgrant Nov 11, 2024

Choose a reason for hiding this comment

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

Yes, I tested this on some real databases. But an integration test is clearly needed then. Qltest cannot test this situation due to the absence of SEMMLE_CPP_MISSING_INCLUDES_NOT_FATAL.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that having some integration test for this is the only thing that still needs addressing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CannotOpenFile() { this.hasTag(["cannot_open_file", "cannot_open_file_reason"]) }

string getIncludedFile() {
result = this.getMessage().regexpCapture("cannot open source file '([^']+)'", 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the file names always quoted? This is non-obvious from the frontend source code.

@calumgrant calumgrant merged commit 1a68845 into main Nov 12, 2024
14 checks passed
@calumgrant calumgrant deleted the calumgrant/telemetry branch November 12, 2024 11:51
jketema added a commit to jketema/codeql that referenced this pull request Nov 28, 2024
…try"

This reverts commit 1a68845, reversing
changes made to 349518b.
jketema added a commit to jketema/codeql that referenced this pull request Nov 28, 2024
…try"

This reverts commit 1a68845, reversing
changes made to 349518b.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants