Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch: Fix query initialization logic & query transformation from Prometheus/Loki #31322

Merged
merged 2 commits into from Feb 23, 2021

Conversation

Elfo404
Copy link
Member

@Elfo404 Elfo404 commented Feb 18, 2021

What this PR does / why we need it:
Before the react refactoring, when switching from a prometheus or loki datasource to Elasticsearch in explore, we were generating logs query. While this was still happening, the new query initialization logic was overwriting those changes.

Additionally, everytime we were switching from ANY datasource to elasticsearch we were creating a log query, which is what most users probably want when switching from prometheus/loki, but not from other datasources.

Which issue(s) this PR fixes:

Fixes #31300

Special notes for your reviewer:
I changed a bit the initialization logic, this should be 100% compatible with what we had before, but it needs a bit of testing to be sure.

I'll also create an issue and a follow-up PR to add documentation for the "transform prometheus/loki query to elastic search query functionality"

Copy link
Member

@ivanahuckova ivanahuckova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I have tested Prom -> Elastic and Loki -> Elastic data source switch and it gave me correct query based on previous data source in both cases. I have also looked at older Elastic dashboards to see if there aren't any unexpected results, but all looked good. 👍 for adding and updating tests.

Good job. :)

importQueries(queries: DataQuery[], datasourceType: string): ElasticsearchQuery[] {
if (datasourceType === 'prometheus' || datasourceType === 'loki') {
return queries.map((query) => {
let prometheusQuery: PromQuery = query as PromQuery;
let prometheusQuery = query as PromQuery;
const expr = getElasticsearchQuery(extractPrometheusLabels(prometheusQuery.expr));
return {
isLogsQuery: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need isLogsQuery: true if we are adding type: 'logs'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not completely sure about it, i'm keeping it to avoid breaking anything, but for sure I'm gonna revisit it now with the BE refactoring. Thanks for pointing that out!

@Elfo404 Elfo404 merged commit 4429f2c into master Feb 23, 2021
@Elfo404 Elfo404 deleted the gio/fix/es-query-init branch February 23, 2021 21:58
ryantxu pushed a commit that referenced this pull request Feb 24, 2021
…from Promethous/Loki (#31322)

* Elasticsearch: Fix query initialization logic

* Only import prometheus & loki queries as log queries
@Elfo404 Elfo404 added the old backport v7.4.x Mark PR for automatic backport to v7.4.x label Feb 24, 2021
grafanabot pushed a commit that referenced this pull request Feb 24, 2021
…from Promethous/Loki (#31322)

* Elasticsearch: Fix query initialization logic

* Only import prometheus & loki queries as log queries

(cherry picked from commit 4429f2c)
Elfo404 added a commit that referenced this pull request Feb 24, 2021
…from Promethous/Loki (#31322) (#31441)

* Elasticsearch: Fix query initialization logic

* Only import prometheus & loki queries as log queries

(cherry picked from commit 4429f2c)

Co-authored-by: Giordano Ricci <gio.ricci@grafana.com>
@achatterjee-grafana achatterjee-grafana changed the title Elasticsearch: Fix query initialization logic & query transformation from Promethous/Loki Elasticsearch: Fix query initialization logic & query transformation from Prometheus/Loki Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Elasticsearch: Transform prometheus query to elasticsearch query does not work
2 participants