Some Notes on Data source Info / Data source Ref:
-
Terms I'm using for these notes:
- DatasourceRef: is model that includes (uid+type), is saved by dashboards and alerting (note: alerting is current UID only)
- DatasourceInfo: is full information that a datasource neededs to execute a request, and can be looked up by the Ref
-
Contexts:
- Alerting: The Ref is saved. Alerts run as a service, so in this context there is no user (although perhaps there should be a service user or role). Therefore for saved alerts run by the service, authorization is done at creation time, not run time - (as users would not want alerts to stop working if a user is removed).
- Query API: Runtime, in this context there is a user
-
Main Question:
- What Services are responsbile for what for data source execution?
- Where trailing "What" is:
- Authorizing a User (or Service) to a data source (or data source ref?), and who caches this?
- Taking a data source ref and getting data source info
- Decryption of secrets within data source info?
-
Considerations:
- Security (e.g. Defense in depth, services not having secrets they don't need)
- Performance (e.g. not looking up things twice)
- Making things services - and the stateless aspect (TBH "stateless" in this context isn't entirely clear to me)
-
Misc Notes:
- SSE doesn't need data source info, only the ref, I think only data source plugins and editing of data sources needs the full info
-
A Possible Architecture
- Service to Authorize Datasource Ref to Users (To be called at borders (e.g. APIs or exported services))
- Another service to Translate Datasource Ref -> Datasource Info (to be called by internal services)
- With this, things like recorded queries would use the Data Source Ref Authorization service, SSE as well only sees the Datasoure Ref but isn't responsbile for authorization. Data sources get info (I imagine an execute queries call could use the ref to fetch data source info before sending the request to a data source).
MetricRequest DTO is actually suitable for multiple data sources and/or other types of queries, such as SSE. Except the time range, something we want to have per each query.
One optimization we do now when there's no SSE query is to bundle multiple queries for the same data source, but that's can perhaps seen as an implementation detail? Are we doing this for SSE as well?
Thinking about the current API payload when calling /api/ds/query. To me it would make sense to let SSE handle all data source queries, e.g. "new query service referred to in earlier comment" could be SSE. Can it already today handle queries not containing any expressions?
This approach would require SSE to check ds permissions which might or might not be optimal. One of the nice things though with this is that it doesn't need any
models.DataSource
for expression queries or grafanads queries, only for real data source queries.