@@ -17,6 +17,7 @@ public extension CustomQuery {
1717 /// @see compileToRunnableQuery
1818 func precompile(
1919 namespace: String ? = nil ,
20+ useNamespace: Bool ,
2021 organizationAppIDs: [ UUID ] ,
2122 isSuperOrg: Bool
2223 ) throws -> CustomQuery {
@@ -74,6 +75,7 @@ public extension CustomQuery {
7475 // Apply base filters and data source
7576 query = try Self . applyBaseFilters (
7677 namespace: namespace,
78+ useNamespace: useNamespace,
7779 query: query,
7880 organizationAppIDs: organizationAppIDs,
7981 isSuperOrg: isSuperOrg
@@ -179,6 +181,7 @@ public extension CustomQuery {
179181extension CustomQuery {
180182 static func applyBaseFilters(
181183 namespace: String ? ,
184+ useNamespace: Bool ,
182185 query: CustomQuery ,
183186 organizationAppIDs: [ UUID ] ? ,
184187 isSuperOrg: Bool
@@ -213,21 +216,23 @@ extension CustomQuery {
213216 cacheValidityDuration: query. context? . cacheValidityDuration
214217 )
215218
216- let allowedDataSourceNames = [
219+ var allowedDataSourceNames = [
217220 " telemetry-signals " ,
218221 " com.telemetrydeck.all "
219222 ]
220223
221- // Decide the data source based on the data source property and namespaces
222224 if let namespace {
223- // If a namespace is available, use the namespace, even if another data source is specified.
224- // This allows us to specify com.telemetrydeck.all for global queries and still use the customer's
225- // name space if they have one.
226- query . dataSource = . init ( namespace )
227- } else if let dataSource = query. dataSource, allowedDataSourceNames. contains ( dataSource. name) {
228- // If no namespace is available and the customer requested a specific data source, use it
225+ allowedDataSourceNames . append ( namespace )
226+ }
227+
228+ // Decide the data source based on the data source property and namespaces
229+ if let dataSource = query. dataSource, allowedDataSourceNames. contains ( dataSource. name) {
230+ // If the customer requested a specific data source, use it
229231 // if it is in the list of allowed data sources.
230232 query. dataSource = . init( dataSource. name)
233+ } else if let namespace, useNamespace {
234+ // If a namespace is set, use it as the data source
235+ query. dataSource = . init( namespace)
231236 } else {
232237 // Else fall back to telemetry-signals
233238 query. dataSource = . init( " telemetry-signals " )
0 commit comments