fix: revert the way we do ds lookups #911
Merged
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.
Problem
Background context
Synthetic Monitoring relies on two supporting databases to work at full capacity: a Grafana Cloud-hosted prometheus database and a Grafana Cloud-hosted Loki database.
A Grafana Cloud instance automatically provisions two datasource 'connectors' which connect to each respectively, confusingly referred to as a Prometheus Datasource and a Loki Datasource. In theory these should all remain stable, are named predictably and are immutable.
The problem which lies with the plugin is that it based on certain assumptions which may be untrue in certain situations (it is worth noting they are rare but do and will continue to exist and some clients specifically ask to bypass these assumptions):
jsonData
for the Synthetic Monitoring Datasource is the source of truth for these connections./api/v1/tenant/update
route to reassign different instances to associate withThe next problem that the Synthetic Monitoring plugin faces is that the metrics and logs api are queried via their datasources within Grafana. We query datasources by their UIDs, however the SM tenant endpoint (which is the real source of truth) does not concern itself with associating with datasources but with Grafana Cloud-hosted database instances.
The api can provide the
hostedId
of the database instances it is writing to but it has no knowledge of what datasources a Grafana Cloud instance has which it uses to query against.If we do not wish to rely on the assumptions above to know what datasources we can utilise it is currently up to to the plugin to ask the SM tenant endpoint and search through a user's available datasources and ask for the hostedIds of each (in this case the
basicAuthUser === hostedId
). It is worth noting this may not always be reliable because a user may have access to multiple datasources which share the same hostedId but have different access policies.Actual problem
In the previous update we worked on the assumption that somewhere during the Grafana Cloud bootup that the datasources provided by
getDatasourceSrv.getList()
was mutating the provisioning data and doing the cross-referencing for us. See below in our development environment where the jsonData provided by the SM/settings
endpoint omits the uid but it is present when querying the Synthetic Monitoring jsonData provided bygetDatasourceSrv.getList()
It appears this new assumption is wrong and that not all instances have this data available.
Solution
Unfortunately the solution for now is to go back to the original assumptions that the provisioning data provided by the SM plugin is correct and do the datasource look ups utilising this information.
A more thorough solution will be explored in future work.