Skip to content

Commit

Permalink
Show warnings in query frontend (thanos-io#7289)
Browse files Browse the repository at this point in the history
* Show warnings in query frontend

QFE currently does not parse warnings from downstream queriers.
This commit fixes that by adding the field to proto messages and
modifies the merge function to take warnings into account.

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>

* Add CHANGELOG entry

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>

* Omit empty warnings

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>

---------

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski authored and jnyi committed Jun 3, 2024
1 parent e84ef4e commit 6b1dc58
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#7244](https://github.com/thanos-io/thanos/pull/7244) Query: Fix Internal Server Error unknown targetHealth: "unknown" when trying to open the targets page.
- [#7248](https://github.com/thanos-io/thanos/pull/7248) Receive: Fix RemoteWriteAsync was sequentially executed causing high latency in the ingestion path.
- [#7271](https://github.com/thanos-io/thanos/pull/7271) Query: fixing dedup iterator when working on mixed sample types.
- [#7289](https://github.com/thanos-io/thanos/pull/7289) Query Frontend: show warnings from downstream queries.

### Added

Expand Down
15 changes: 10 additions & 5 deletions internal/cortex/querier/queryrange/query_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,17 @@ func (prometheusCodec) MergeResponse(_ Request, responses ...Response) (Response
// Merge the responses.
sort.Sort(byFirstTime(promResponses))

analyzes := make([]*Analysis, 0, len(responses))
var (
analyzes = make([]*Analysis, 0, len(responses))
warnings []string = nil
)
for i := range promResponses {
if promResponses[i].Data.GetAnalysis() == nil {
continue
if promResponses[i].Data.GetAnalysis() != nil {
analyzes = append(analyzes, promResponses[i].Data.GetAnalysis())
}
if len(promResponses[i].Warnings) > 0 {
warnings = append(warnings, promResponses[i].Warnings...)
}

analyzes = append(analyzes, promResponses[i].Data.GetAnalysis())
}

seriesStatsCounters := make([]*SeriesStatsCounter, 0, len(responses))
Expand All @@ -297,6 +301,7 @@ func (prometheusCodec) MergeResponse(_ Request, responses ...Response) (Response
Stats: StatsMerge(responses),
Analysis: AnalyzesMerge(analyzes...),
},
Warnings: warnings,
}
if len(seriesStatsCounters) > 0 {
response.Data.SeriesStatsCounter = SeriesStatsCounterMerge(seriesStatsCounters...)
Expand Down
110 changes: 110 additions & 0 deletions internal/cortex/querier/queryrange/queryrange.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/cortex/querier/queryrange/queryrange.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ message PrometheusResponse {
string ErrorType = 3 [(gogoproto.jsontag) = "errorType,omitempty"];
string Error = 4 [(gogoproto.jsontag) = "error,omitempty"];
repeated PrometheusResponseHeader Headers = 5 [(gogoproto.jsontag) = "-"];
repeated string Warnings = 6 [(gogoproto.jsontag) = "warnings,omitempty"];
}

message PrometheusData {
Expand All @@ -58,6 +59,7 @@ message PrometheusInstantQueryResponse {
string ErrorType = 3 [(gogoproto.jsontag) = "errorType,omitempty"];
string Error = 4 [(gogoproto.jsontag) = "error,omitempty"];
repeated PrometheusResponseHeader Headers = 5 [(gogoproto.jsontag) = "-"];
repeated string Warnings = 6 [(gogoproto.jsontag) = "warnings,omitempty"];
}

message PrometheusInstantQueryData {
Expand Down
7 changes: 5 additions & 2 deletions internal/cortex/querier/queryrange/results_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func (PrometheusResponseExtractor) Extract(start, end int64, from Response) Resp
Stats: extractStats(start, end, promRes.Data.Stats),
Analysis: promRes.Data.Analysis,
},
Headers: promRes.Headers,
Headers: promRes.Headers,
Warnings: promRes.Warnings,
}
}

Expand All @@ -115,6 +116,7 @@ func (PrometheusResponseExtractor) ResponseWithoutHeaders(resp Response) Respons
Stats: promRes.Data.Stats,
Analysis: promRes.Data.Analysis,
},
Warnings: promRes.Warnings,
}
}

Expand All @@ -129,7 +131,8 @@ func (PrometheusResponseExtractor) ResponseWithoutStats(resp Response) Response
Analysis: promRes.Data.Analysis,
SeriesStatsCounter: promRes.Data.SeriesStatsCounter,
},
Headers: promRes.Headers,
Headers: promRes.Headers,
Warnings: promRes.Warnings,
}
}

Expand Down
3 changes: 2 additions & 1 deletion internal/cortex/querier/queryrange/results_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
query = "/api/v1/query_range?end=1536716898&query=sum%28container_memory_rss%29+by+%28namespace%29&start=1536673680&stats=all&step=120"
responseBody = `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}],"analysis":null}}`
responseBody = `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"foo":"bar"},"values":[[1536673680,"137"],[1536673780,"137"]]}],"analysis":null},"warnings":["test-warn"]}`
histogramResponseBody = `{"status":"success","data":{"resultType":"matrix","result":[{"metric":{"fake":"histogram"},"histograms":[[1536673680,{"count":"5","sum":"18.4","buckets":[[3,"-0.001","0.001","2"],[0,"0.7071067811865475","1","1"],[0,"1","1.414213562373095","2"],[0,"2","2.82842712474619","1"],[0,"2.82842712474619","4","1"]]}]]}],"analysis":null}}`
)

Expand Down Expand Up @@ -91,6 +91,7 @@ var (
},
},
},
Warnings: []string{"test-warn"},
}
parsedHistogramResponse = &PrometheusResponse{
Status: "success",
Expand Down

0 comments on commit 6b1dc58

Please sign in to comment.