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

Cast volume response on receive. #11197

Closed
Closed
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions pkg/querier/queryrange/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package queryrange

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

Expand Down Expand Up @@ -48,18 +49,23 @@ func NewVolumeMiddleware() queryrangebase.Middleware {
}
})

type f func(context.Context) (time.Time, definitions.Response, error)
type f func(context.Context) (time.Time, *VolumeResponse, error)
var jobs []f

for bucket, req := range reqs {
b, r := bucket, req
jobs = append(jobs, f(func(ctx context.Context) (time.Time, definitions.Response, error) {
jobs = append(jobs, f(func(ctx context.Context) (time.Time, *VolumeResponse, error) {
resp, err := next.Do(ctx, r)
if err != nil {
return b, nil, err
}

return b, resp, nil
volumeResponse, ok := resp.(*VolumeResponse)
if !ok {
return b, nil, fmt.Errorf("unexpected response type: want (*VolumeResponse), got (%T)", resp)
}

return b, volumeResponse, nil
}))
}

Expand All @@ -80,7 +86,7 @@ func NewVolumeMiddleware() queryrangebase.Middleware {
}

collector <- &bucketedVolumeResponse{
bucket, resp.(*VolumeResponse),
bucket, resp,
}
return err
})
Expand Down
28 changes: 28 additions & 0 deletions pkg/util/marshal/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,34 @@ func Test_WriteSeriesResponseJSON(t *testing.T) {
require.NoError(t, err)

require.JSONEqf(t, tc.expected, b.String(), "Series Test %d failed", i)

})
}
}

func Test_WriteVolumeResponseJSON(t *testing.T) {
for _, tc := range []struct {
name string
input *logproto.VolumeResponse
expected string
}{
{
name: "empty",
input: &logproto.VolumeResponse{Volumes: []logproto.Volume{}},
expected: `{"volumes":[]}`,
},
} {
t.Run(tc.name, func(t *testing.T) {
var b bytes.Buffer
err := WriteVolumeResponseJSON(tc.input, &b)
require.NoError(t, err)

require.JSONEq(t, tc.expected, b.String())

var resp logproto.VolumeResponse
err = json.Unmarshal([]byte(tc.expected), &resp)
require.NoError(t, err)
require.Equal(t, tc.input, &resp)
})
}
}
Expand Down
Loading