From ae7d6bdc4638d8e8e3cc380e5a3c55741a67f3b4 Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Wed, 19 Oct 2022 12:51:41 -0700 Subject: [PATCH] store: Tag FilterQuery with GCP conforming info --- store/postgres/src/relational.rs | 1 + store/postgres/src/relational_queries.rs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/store/postgres/src/relational.rs b/store/postgres/src/relational.rs index 6846835bfe4..b2e13e1cb14 100644 --- a/store/postgres/src/relational.rs +++ b/store/postgres/src/relational.rs @@ -673,6 +673,7 @@ impl Layout { range, block, query_id, + &self.site, )?; let query_clone = query.clone(); diff --git a/store/postgres/src/relational_queries.rs b/store/postgres/src/relational_queries.rs index c3b435e5eb3..116f61c49ff 100644 --- a/store/postgres/src/relational_queries.rs +++ b/store/postgres/src/relational_queries.rs @@ -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. @@ -2826,6 +2826,7 @@ pub struct FilterQuery<'a> { range: FilterRange, block: BlockNumber, query_id: Option, + site: &'a Site, } /// String representation that is useful for debugging when `walk_ast` fails @@ -2851,6 +2852,7 @@ impl<'a> FilterQuery<'a> { range: EntityRange, block: BlockNumber, query_id: Option, + site: &'a Site, ) -> Result { let sort_key = SortKey::new(order, collection, filter, block)?; @@ -2860,6 +2862,7 @@ impl<'a> FilterQuery<'a> { range: FilterRange(range), block, query_id, + site, }) } @@ -3120,10 +3123,17 @@ impl<'a> QueryFragment 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