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

store: Tag FilterQuery with GCP conforming info #4079

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions store/postgres/src/relational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ impl Layout {
range,
block,
query_id,
&self.site,
)?;
let query_clone = query.clone();

Expand Down
16 changes: 13 additions & 3 deletions store/postgres/src/relational_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::{
BlockRangeColumn, BlockRangeLowerBoundClause, BlockRangeUpperBoundClause, BLOCK_COLUMN,
BLOCK_RANGE_COLUMN, BLOCK_RANGE_CURRENT,
},
primary::Namespace,
primary::{Namespace, Site},
};

/// Those are columns that we always want to fetch from the database.
Expand Down Expand Up @@ -2826,6 +2826,7 @@ pub struct FilterQuery<'a> {
range: FilterRange,
block: BlockNumber,
query_id: Option<String>,
site: &'a Site,
}

/// String representation that is useful for debugging when `walk_ast` fails
Expand All @@ -2851,6 +2852,7 @@ impl<'a> FilterQuery<'a> {
range: EntityRange,
block: BlockNumber,
query_id: Option<String>,
site: &'a Site,
) -> Result<Self, QueryExecutionError> {
let sort_key = SortKey::new(order, collection, filter, block)?;

Expand All @@ -2860,6 +2862,7 @@ impl<'a> FilterQuery<'a> {
range: FilterRange(range),
block,
query_id,
site,
})
}

Expand Down Expand Up @@ -3120,10 +3123,17 @@ impl<'a> QueryFragment<Pg> for FilterQuery<'a> {
return Ok(());
}

// Tag the query with various information to make connecting it to
// the GraphQL query it came from easier. The names of the tags are
// chosen so that GCP's Query Insights will recognize them
if let Some(qid) = &self.query_id {
out.push_sql("/* qid: ");
out.push_sql("/* controller='filter',application='");
out.push_sql(self.site.namespace.as_str());
out.push_sql("',route='");
out.push_sql(qid);
out.push_sql(" */\n");
out.push_sql("',action='");
out.push_sql(&self.block.to_string());
out.push_sql("' */\n");
}
// We generate four different kinds of queries, depending on whether
// we need to window and whether we query just one or multiple entity
Expand Down