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

Handle unexpected response types in volume API #11196

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions pkg/querier/queryrange/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package queryrange

import (
"context"
"fmt"
"sort"
"time"

"github.com/go-kit/log/level"
"github.com/grafana/dskit/concurrency"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
Expand All @@ -17,6 +19,7 @@ import (
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase/definitions"
"github.com/grafana/loki/pkg/storage/stores/index/seriesvolume"
"github.com/grafana/loki/pkg/util"
util_log "github.com/grafana/loki/pkg/util/log"
)

func NewVolumeMiddleware() queryrangebase.Middleware {
Expand Down Expand Up @@ -84,7 +87,7 @@ func NewVolumeMiddleware() queryrangebase.Middleware {
}

collector <- &bucketedVolumeResponse{
bucket, resp.(*VolumeResponse),
bucket, resp,
}
return err
})
Expand All @@ -102,29 +105,35 @@ func NewVolumeMiddleware() queryrangebase.Middleware {

type bucketedVolumeResponse struct {
bucket time.Time
response *VolumeResponse
response queryrangebase.Response
}

func ToPrometheusResponse(respsCh chan *bucketedVolumeResponse, aggregateBySeries bool) *LokiPromResponse {
var headers []*definitions.PrometheusResponseHeader
samplesByName := make(map[string][]logproto.LegacySample)

for bucketedVolumeResponse := range respsCh {
if bucketedVolumeResponse == nil {
for response := range respsCh {
if response == nil {
continue
}

bucket, resp := bucketedVolumeResponse.bucket, bucketedVolumeResponse.response
bucket, r := response.bucket, response.response

vr, ok := r.(*VolumeResponse)
if !ok {
level.Error(util_log.Logger).Log("msg", "unexpected response type given, skipping bucket", "given", fmt.Sprintf("%T", r), "bucket", bucket.Format(time.RFC3339Nano))
continue
}

if headers == nil {
headers := make([]*definitions.PrometheusResponseHeader, len(resp.Headers))
for i, header := range resp.Headers {
headers = make([]*definitions.PrometheusResponseHeader, len(vr.Headers))
for i, header := range vr.Headers {
h := header
headers[i] = &h
}
}

for _, volume := range resp.Response.Volumes {
for _, volume := range vr.Response.Volumes {
if _, ok := samplesByName[volume.Name]; !ok {
samplesByName[volume.Name] = make([]logproto.LegacySample, 0, 1)
}
Expand Down