-
Notifications
You must be signed in to change notification settings - Fork 161
feat: Query Profile #2014
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
feat: Query Profile #2014
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
5685b37
Add QueryMode protos.
ehsannas 16fcd28
WIP: Query profiling APIs.
ehsannas e806883
Use generic type.
ehsannas 0d1febb
WIP WIP.
ehsannas 265f1ff
WIP WIP WIP.
ehsannas af54637
Update integration tests.
ehsannas 8cb527d
clean up.
ehsannas 69da273
lint.
ehsannas cc35f56
Fix: Do not re-use _stream().
ehsannas 9f987dd
Address more feedback.
ehsannas 40ded3a
introduce QueryPlan class to make it possible to add node-level info …
ehsannas ce6df90
Merge remote-tracking branch 'origin/main' into query_profiling_impl_2
ehsannas 9819c5e
fix lint errors.
ehsannas ccaad87
Revert host setting.
ehsannas 834ddc9
undo manual proto updates.
ehsannas bb2fbe8
Merge remote-tracking branch 'origin/main' into query_profiling_impl_…
ehsannas 74b7f15
Merge remote-tracking branch 'origin/main' into query_profiling_impl_…
ehsannas 7c3cf77
Update the public APIs to v2.
ehsannas 2c4944c
Reuse existing _stream methods.
ehsannas 71935d1
Introduce ExplainMetrics and PlanSummary.
ehsannas 4621073
Update tests.
ehsannas 3bdb616
Manually import query profile protos.
ehsannas 81d0bf6
WIP: Update impl and tests with new protos.
ehsannas 2e9d274
WIP (2): Update impl and tests with new protos.
ehsannas a31a514
WIP (3): Update impl and tests with new protos.
ehsannas 0c7c9da
WIP (4): Update impl and tests with new protos.
ehsannas 985a972
Add test for explainStream.
ehsannas b735f47
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 7bf7078
Merge remote-tracking branch 'origin/main' into query_profiling_impl_…
ehsannas 371c66d
Remove bytesReturned from the API.
ehsannas 95a2111
Merge remote-tracking branch 'origin/main' into query_profiling_impl_…
ehsannas 0fd0f9e
minor improvements.
ehsannas 4f984fe
minor improvements.
ehsannas d00b7cf
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] c52d77d
improve documentation.
ehsannas 74c2f3f
Fix unit test failure.
ehsannas 460d3f1
minor improvements.
ehsannas fd2d50e
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 1e13262
explain options should be optional.
ehsannas 974ca2a
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 4a3f8c2
Address feedback.
ehsannas 391edb8
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 7501e4f
Merge branch 'main' into ehsann/query_profiling_impl_v2_4
MarkDuckworth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /*! | ||
| * Copyright 2024 Google LLC. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import * as firestore from '@google-cloud/firestore'; | ||
| import {google} from '../protos/firestore_v1_proto_api'; | ||
| import {Serializer} from './serializer'; | ||
| import IPlanSummary = google.firestore.v1.IPlanSummary; | ||
| import IExecutionStats = google.firestore.v1.IExecutionStats; | ||
| import IExplainMetrics = google.firestore.v1.IExplainMetrics; | ||
|
|
||
| /** | ||
| * PlanSummary contains information about the planning stage of a query. | ||
| * | ||
| * @class PlanSummary | ||
| */ | ||
| export class PlanSummary implements firestore.PlanSummary { | ||
| /** | ||
| * @private | ||
| * @internal | ||
| */ | ||
| constructor(readonly indexesUsed: Record<string, unknown>[]) {} | ||
|
|
||
| /** | ||
| * @private | ||
| * @internal | ||
| */ | ||
| static _fromProto( | ||
| plan: IPlanSummary | null | undefined, | ||
| serializer: Serializer | ||
| ): PlanSummary { | ||
| const indexes: Record<string, unknown>[] = []; | ||
| if (plan && plan.indexesUsed) { | ||
| for (const index of plan.indexesUsed) { | ||
| indexes.push(serializer.decodeGoogleProtobufStruct(index)); | ||
| } | ||
| } | ||
| return new PlanSummary(indexes); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * ExecutionStats contains information about the execution of a query. | ||
| * | ||
| * @class ExecutionStats | ||
| */ | ||
| export class ExecutionStats implements firestore.ExecutionStats { | ||
| /** | ||
| * @private | ||
| * @internal | ||
| */ | ||
| constructor( | ||
ehsannas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| readonly resultsReturned: number, | ||
| readonly executionDuration: firestore.Duration, | ||
| readonly readOperations: number, | ||
| readonly debugStats: Record<string, unknown> | ||
| ) {} | ||
|
|
||
| /** | ||
| * @private | ||
| * @internal | ||
| */ | ||
| static _fromProto( | ||
| stats: IExecutionStats | null | undefined, | ||
| serializer: Serializer | ||
| ): ExecutionStats | null { | ||
| if (stats) { | ||
| return new ExecutionStats( | ||
| Number(stats.resultsReturned), | ||
| { | ||
| seconds: Number(stats.executionDuration?.seconds), | ||
| nanoseconds: Number(stats.executionDuration?.nanos), | ||
| }, | ||
| Number(stats.readOperations), | ||
| serializer.decodeGoogleProtobufStruct(stats.debugStats) | ||
| ); | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * ExplainMetrics contains information about planning and execution of a query. | ||
| * | ||
| * @class ExplainMetrics | ||
| */ | ||
| export class ExplainMetrics implements firestore.ExplainMetrics { | ||
| /** | ||
| * @private | ||
| * @internal | ||
| */ | ||
| constructor( | ||
ehsannas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| readonly planSummary: PlanSummary, | ||
| readonly executionStats: ExecutionStats | null | ||
| ) {} | ||
|
|
||
| /** | ||
| * @private | ||
| * @internal | ||
| */ | ||
| static _fromProto( | ||
| metrics: IExplainMetrics, | ||
| serializer: Serializer | ||
| ): ExplainMetrics { | ||
| return new ExplainMetrics( | ||
| PlanSummary._fromProto(metrics.planSummary, serializer), | ||
| ExecutionStats._fromProto(metrics.executionStats, serializer) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * ExplainResults contains information about planning, execution, and results | ||
| * of a query. | ||
| * | ||
| * @class ExplainResults | ||
| */ | ||
| export class ExplainResults<T> implements firestore.ExplainResults<T> { | ||
| /** | ||
| * @private | ||
| * @internal | ||
| */ | ||
| constructor( | ||
ehsannas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| readonly metrics: ExplainMetrics, | ||
| readonly snapshot: T | null | ||
| ) {} | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.