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

Alerting: Fix mathexp.NoData cannot be reduced #55347

Merged
merged 1 commit into from Sep 21, 2022

Conversation

grobinson-grafana
Copy link
Contributor

What this PR does / why we need it:

This is one of two possible fixes for #55085. It changes the reduce function to reduce mathexp.NoData to a result with no values instead of an error "can only reduce type series, got type noData".

Which issue(s) this PR fixes:

Fixes #55085

Special notes for your reviewer:

@@ -171,6 +171,8 @@ func (gr *ReduceCommand) Execute(_ context.Context, vars mathexp.Vars) (mathexp.
Text: fmt.Sprintf("Reduce operation is not needed. Input query or expression %s is already reduced data.", gr.VarToReduce),
})
newRes.Values = append(newRes.Values, copyV)
case mathexp.NoData:
newRes.Values = append(newRes.Values, v)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that for mathexp.Number we create a copy called copyV. I'm not sure we need to do that here unless we also need to copy the metadata?

Copy link
Contributor

Choose a reason for hiding this comment

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

The copying is so pointers don't accidentally mutate data in upstream operations (since the result of each operation can be returned in SSE).

Metadata is still a bit wonky and undefined. But in general, for the output of a non-datasource query operation such as reduce, it is probably better to create a NewNoData() that creates a Frame with no fields.

Side Note: My idea with "NoData" is "untyped nodata". In the future, I could see adding NoDataTimeSeries etc.

@grafanabot
Copy link
Contributor

This commit fixes a bug where queries from datasources such as
InfluxDB that returned no data would not create a DatasourceNoData
alert, but instead an error "can only reduce type series, got type
noData".
@grafanabot
Copy link
Contributor

@grobinson-grafana grobinson-grafana modified the milestones: 9.2.0, 9.1.6 Sep 19, 2022
@grobinson-grafana grobinson-grafana added backport v9.1.x Bot will automatically open backport PR and removed no-backport Skip backport of PR labels Sep 19, 2022
@grobinson-grafana grobinson-grafana modified the milestones: 9.1.6, 9.1.7 Sep 20, 2022
Copy link
Contributor

@yuri-tceretian yuri-tceretian left a comment

Choose a reason for hiding this comment

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

LGTM. We need the same for Classic condition as well

@grobinson-grafana grobinson-grafana merged commit 7d20766 into main Sep 21, 2022
@grobinson-grafana grobinson-grafana deleted the grobinson/fix-55085-2 branch September 21, 2022 09:01
grafanabot pushed a commit that referenced this pull request Sep 21, 2022
This commit fixes a bug where queries from datasources such as InfluxDB that returned no data would not create a DatasourceNoData alert, but instead an error "can only reduce type series, got type noData".

(cherry picked from commit 7d20766)
grobinson-grafana added a commit that referenced this pull request Sep 21, 2022
This commit fixes a bug where queries from datasources such as InfluxDB that returned no data would not create a DatasourceNoData alert, but instead an error "can only reduce type series, got type noData".

(cherry picked from commit 7d20766)

Co-authored-by: George Robinson <george.robinson@grafana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Grafana 9.1.4 NoData reduce problem
4 participants