Repository navigation
[BUGFIX] Loki: only migrate the Grafana queries of a Loki datasource - #990
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
The migration script of LokiLogQuery constrained the type of the datasource in #target. As the migration engine unifies #target with the Grafana target, this constraint doesn't only reject the targets of another datasource: it also gives the type "loki" to the targets whose datasource has no type, or which have no datasource at all. The check that follows is then always true for them. So the Loki script matched every target with an expression and without datasource type, like the Prometheus script does on purpose. As the migration of a target matched by several plugins is abandoned, these targets were all replaced by the placeholder query "migration_from_grafana_not_supported". For example, it is the case of the 301 queries of the dashboard Node Exporter Full, whose targets have no datasource. The type is now checked by the condition only, as in the documentation of the migration scripts, so the Loki script matches the targets of a Loki datasource only. The other targets are migrated by the Prometheus script again, as before the Loki script was added. Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
3 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
#682 aimed to stop the Loki migration script from matching the Grafana targets of other datasources
(perses/perses#4134), but the script still matches every target whose datasource has no
type, and every targetwithout datasource. The migration engine unifies
#targetwith the Grafana target, so the constraintdatasource: type: "loki"in#targetdoesn't reject these targets: it gives them the typeloki, and the condition#target.datasource.type == "loki"that follows is then true.As the Prometheus script deliberately matches the targets without datasource type, these targets are matched by two
plugins, so since perses/perses#4139 they are replaced by the placeholder query
migration_from_grafana_not_supported.For example, with the current release of the plugins, the 301 queries of
Node Exporter Full end up as placeholders, and the migration logs
ambiguous query migration: 2 plugins matched the same target: LokiLogQuery, PrometheusTimeSeriesQueryfor each ofthem.
This PR checks the type of the datasource in the condition only, with the idiom of the
documentation of the query migration scripts:
(*#target.datasource.type | null) == "loki".#targetno longer constrains the type, and the rest of the script isunchanged.
"datasource": {"type": "loki", "uid": "lk"}LokiLogQueryLokiLogQuery(unchanged)"datasource": {"type": "loki"}LokiLogQueryLokiLogQuery(unchanged)"datasource": {"type": "prometheus", "uid": "prom"}PrometheusTimeSeriesQueryPrometheusTimeSeriesQuery(unchanged)"datasource": {"uid": "prom"}PrometheusTimeSeriesQueryPrometheusTimeSeriesQueryexpr, or with anulluidThe targets without datasource type are thus migrated by the Prometheus script again, as before the Loki script was
added. This also applies to a Loki target without datasource in a panel using a Loki datasource:
perses/perses#4817 gives such a target the datasource of its panel before the query scripts run, as Grafana does, so it is
migrated as a
LokiLogQuery.Tests
percli plugin test-schemas --plugin.path=lokipasses, including the existing migration tests. These tests can onlycheck a migration that produces a result, so I checked the targets that must not match by migrating dashboards with
percli migrate --plugin.pathand the plugins of the current release, with only this script replaced: this gives thetable above.
594 placeholders in 11 dashboards, e.g. 301 in Node Exporter Full. Nothing else changed in the dashboards. With
[BUGFIX] Grafana migration: use the datasource of the panel for the queries without one perses#4817, the migrated queries also keep the datasource of their panel, e.g.
"datasource": "${ds_prometheus}"in Node Exporter Full.their targets have no datasource. Their 4 Loki targets were placeholders, and are now migrated by the Prometheus
script, as before the Loki script was added. Such old dashboards are outside the range supported by the migration
(Grafana 9 and later), and the type of a datasource given by name isn't known.
cue fmtv0.17.1 expects.Screenshots
No UI change.
Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.UI Changes