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

fix: Store validateArgs wrongfully overwriting start, end unix time #24741

Open
wants to merge 3 commits into
base: main-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions v1/services/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ func (s *Store) validateArgs(orgID, bucketID uint64, start, end int64) (string,
return "", "", 0, 0, errors.New("invalid retention policy")
}

if start <= 0 {
if start <= models.MinNanoTime {
start = models.MinNanoTime
}
if end <= 0 {
if end >= models.MaxNanoTime {
end = models.MaxNanoTime
}
return database, rp, start, end, nil
Expand Down
65 changes: 65 additions & 0 deletions v1/services/storage/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,75 @@ import (
"testing"
"time"

"github.com/influxdata/influxdb/v2/internal"
"github.com/influxdata/influxdb/v2/models"
"github.com/influxdata/influxdb/v2/v1/services/meta"
"github.com/stretchr/testify/require"
)

func TestValidateArgs(t *testing.T) {
type inputParams struct {
orgID uint64
bucketID uint64
start int64
end int64
}

type outputParams struct {
database string
rp string
start int64
end int64
err error
}

testCases := []struct {
desc string
store *Store
input inputParams
expected outputParams
}{
{
desc: "start not < models.MinNanoTime and end not > models.MaxNanoTime",
store: NewStore(nil, &internal.MetaClientMock{
DatabaseFn: func(name string) *meta.DatabaseInfo {
return &meta.DatabaseInfo{
Name: name,
RetentionPolicies: []meta.RetentionPolicyInfo{
{
Name: meta.DefaultRetentionPolicyName,
},
},
}
},
}),
input: inputParams{
orgID: 1,
bucketID: 2,
start: models.MinNanoTime - 1,
end: models.MaxNanoTime + 1,
},
expected: outputParams{
database: "0000000000000002",
rp: meta.DefaultRetentionPolicyName,
start: models.MinNanoTime,
end: models.MaxNanoTime,
},
},
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
database, rp, start, end, err := tC.store.validateArgs(tC.input.orgID, tC.input.bucketID, tC.input.start, tC.input.end)

require.Equal(t, tC.expected.database, database)
require.Equal(t, tC.expected.rp, rp)
require.Equal(t, tC.expected.start, start)
require.Equal(t, tC.expected.end, end)
require.Equal(t, tC.expected.err, err)
})
}
}

func TestGroupShardsByTime(t *testing.T) {
tests := []struct {
name string
Expand Down