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

[dbnode/query] Limit docs per query #2415

Merged
merged 43 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c76d60f
doc limit enforcement 1
rallen090 Jun 16, 2020
30a39f7
doc limit enforcement 2
rallen090 Jun 16, 2020
20ea1f8
doc limit enforcement 3
rallen090 Jun 16, 2020
7ab9871
doc limit enforcement 4
rallen090 Jun 16, 2020
9a83aad
doc limit enforcement 5
rallen090 Jun 16, 2020
cfa5ce6
doc limit enforcement 6
rallen090 Jun 16, 2020
6e67cca
doc limit enforcement 7
rallen090 Jun 16, 2020
e6e21ea
doc limit enforcement 8
rallen090 Jun 16, 2020
931d708
doc limit enforcement 9
rallen090 Jun 16, 2020
c69ecc8
doc limit enforcement 10
rallen090 Jun 16, 2020
3f40c43
test cases 1
rallen090 Jun 16, 2020
fd40408
test cases 2
rallen090 Jun 16, 2020
66e42a7
test cases 3
rallen090 Jun 16, 2020
c8b0c31
feedback 1
rallen090 Jun 17, 2020
0a3fc89
feedback 2
rallen090 Jun 17, 2020
fdf37fc
Merge remote-tracking branch 'origin/master' into ra/limit-per-query-…
rallen090 Jun 17, 2020
dad0ac6
test fixes 1
rallen090 Jun 17, 2020
5750876
added back rpc mock
rallen090 Jun 17, 2020
63e670c
added back rpc mock
rallen090 Jun 17, 2020
739d767
Merge branch 'master' into ra/limit-per-query-blocks
rallen090 Jun 22, 2020
05ef04f
field names to test cases
rallen090 Jun 22, 2020
d33111d
redundant arg type
rallen090 Jun 22, 2020
e61695f
return docsCount along with size when adding documents
rallen090 Jun 22, 2020
30b9bb2
return docsCount along with size when adding documents 2
rallen090 Jun 22, 2020
0539c5c
return docsCount along with size when adding documents 3
rallen090 Jun 22, 2020
1fec340
track docs count in agg query path
rallen090 Jun 22, 2020
a124ca8
fix doubling counting exhaustive err metric
rallen090 Jun 22, 2020
8647dcb
gen
rallen090 Jun 22, 2020
958fcbd
gen 2
rallen090 Jun 22, 2020
aa97398
fix series check OR condition
rallen090 Jun 22, 2020
d4a6690
missing places for changing docs and series limits
rallen090 Jun 22, 2020
7bdc86d
missing places for changing docs and series limits 2
rallen090 Jun 22, 2020
cd59d74
missing places for changing docs and series limits 3
rallen090 Jun 22, 2020
fd93c86
missing places for changing docs and series limits 4
rallen090 Jun 22, 2020
3115d0a
missing places for changing docs and series limits 5
rallen090 Jun 22, 2020
3ff1997
missing places for changing docs and series limits 6
rallen090 Jun 22, 2020
d9c3d04
misc test/build fixes 1
rallen090 Jun 22, 2020
15726a5
allow doclimit query param
rallen090 Jun 22, 2020
eb39ac9
allow doclimit query param 2
rallen090 Jun 22, 2020
3a35c82
gen fix
rallen090 Jun 22, 2020
529dc3f
Merge remote-tracking branch 'origin/master' into ra/limit-per-query-…
rallen090 Jun 23, 2020
bd8f954
remove prints
rallen090 Jun 23, 2020
451828a
test case for both limits
rallen090 Jun 23, 2020
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/go-playground/locales v0.12.2-0.20190430153329-630ebbb60284 // indirect
github.com/go-playground/universal-translator v0.16.1-0.20170327191703-71201497bace // indirect
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129
github.com/golang/mock v1.4.3
github.com/golang/protobuf v1.3.3
github.com/golang/snappy v0.0.1
github.com/google/go-cmp v0.4.0
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129 h1:tT8iWCYw4uOem71yYA3htfH+LNopJvcqZQshm56G5L4=
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -904,6 +906,7 @@ golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down Expand Up @@ -1033,6 +1036,8 @@ k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
Expand Down
12 changes: 9 additions & 3 deletions src/cmd/services/m3query/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ var (

defaultCarbonIngesterAggregationType = aggregation.Mean

defaultStorageQueryLimit = 10000
defaultStorageQuerySeriesLimit = 10000
defaultStorageQueryDocsLimit = 0 // Default OFF.
)

// Configuration is the configuration for the query service.
Expand Down Expand Up @@ -308,6 +309,9 @@ type PerQueryLimitsConfiguration struct {
// MaxFetchedSeries limits the number of time series returned by a storage node.
MaxFetchedSeries int `yaml:"maxFetchedSeries"`

// MaxFetchedDocs limits the number of index documents matched by a query.
MaxFetchedDocs int `yaml:"maxFetchedDocs"`

// RequireExhaustive results in an error if the query exceeds the series limit.
RequireExhaustive bool `yaml:"requireExhaustive"`
}
Expand All @@ -323,13 +327,15 @@ func (l *PerQueryLimitsConfiguration) AsLimitManagerOptions() cost.LimitManagerO
func (l *PerQueryLimitsConfiguration) AsFetchOptionsBuilderOptions() handleroptions.FetchOptionsBuilderOptions {
if l.MaxFetchedSeries <= 0 {
rallen090 marked this conversation as resolved.
Show resolved Hide resolved
return handleroptions.FetchOptionsBuilderOptions{
Limit: defaultStorageQueryLimit,
SeriesLimit: defaultStorageQuerySeriesLimit,
DocsLimit: defaultStorageQueryDocsLimit,
RequireExhaustive: l.RequireExhaustive,
}
}

return handleroptions.FetchOptionsBuilderOptions{
Limit: int(l.MaxFetchedSeries),
SeriesLimit: int(l.MaxFetchedSeries),
DocsLimit: int(l.MaxFetchedDocs),
RequireExhaustive: l.RequireExhaustive,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/dbnode/generated/thrift/rpc.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct FetchTaggedRequest {
6: optional i64 limit
7: optional TimeType rangeTimeType = TimeType.UNIX_SECONDS
8: optional bool requireExhaustive = false
9: optional i64 docsLimit
}

struct FetchTaggedResult {
Expand Down
46 changes: 46 additions & 0 deletions src/dbnode/generated/thrift/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,7 @@ func (p *Segment) String() string {
// - Limit
// - RangeTimeType
// - RequireExhaustive
// - DocsLimit
type FetchTaggedRequest struct {
NameSpace []byte `thrift:"nameSpace,1,required" db:"nameSpace" json:"nameSpace"`
Query []byte `thrift:"query,2,required" db:"query" json:"query"`
Expand All @@ -3059,6 +3060,7 @@ type FetchTaggedRequest struct {
Limit *int64 `thrift:"limit,6" db:"limit" json:"limit,omitempty"`
RangeTimeType TimeType `thrift:"rangeTimeType,7" db:"rangeTimeType" json:"rangeTimeType,omitempty"`
RequireExhaustive bool `thrift:"requireExhaustive,8" db:"requireExhaustive" json:"requireExhaustive,omitempty"`
DocsLimit *int64 `thrift:"docsLimit,9" db:"docsLimit" json:"docsLimit,omitempty"`
}

func NewFetchTaggedRequest() *FetchTaggedRequest {
Expand Down Expand Up @@ -3107,6 +3109,15 @@ var FetchTaggedRequest_RequireExhaustive_DEFAULT bool = false
func (p *FetchTaggedRequest) GetRequireExhaustive() bool {
return p.RequireExhaustive
}

var FetchTaggedRequest_DocsLimit_DEFAULT int64

func (p *FetchTaggedRequest) GetDocsLimit() int64 {
if !p.IsSetDocsLimit() {
return FetchTaggedRequest_DocsLimit_DEFAULT
}
return *p.DocsLimit
}
func (p *FetchTaggedRequest) IsSetLimit() bool {
return p.Limit != nil
}
Expand All @@ -3119,6 +3130,10 @@ func (p *FetchTaggedRequest) IsSetRequireExhaustive() bool {
return p.RequireExhaustive != FetchTaggedRequest_RequireExhaustive_DEFAULT
}

func (p *FetchTaggedRequest) IsSetDocsLimit() bool {
return p.DocsLimit != nil
}

func (p *FetchTaggedRequest) Read(iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
Expand Down Expand Up @@ -3176,6 +3191,10 @@ func (p *FetchTaggedRequest) Read(iprot thrift.TProtocol) error {
if err := p.ReadField8(iprot); err != nil {
return err
}
case 9:
if err := p.ReadField9(iprot); err != nil {
return err
}
default:
if err := iprot.Skip(fieldTypeId); err != nil {
return err
Expand Down Expand Up @@ -3279,6 +3298,15 @@ func (p *FetchTaggedRequest) ReadField8(iprot thrift.TProtocol) error {
return nil
}

func (p *FetchTaggedRequest) ReadField9(iprot thrift.TProtocol) error {
if v, err := iprot.ReadI64(); err != nil {
return thrift.PrependError("error reading field 9: ", err)
} else {
p.DocsLimit = &v
}
return nil
}

func (p *FetchTaggedRequest) Write(oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin("FetchTaggedRequest"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
Expand Down Expand Up @@ -3308,6 +3336,9 @@ func (p *FetchTaggedRequest) Write(oprot thrift.TProtocol) error {
if err := p.writeField8(oprot); err != nil {
return err
}
if err := p.writeField9(oprot); err != nil {
return err
}
}
if err := oprot.WriteFieldStop(); err != nil {
return thrift.PrependError("write field stop error: ", err)
Expand Down Expand Up @@ -3428,6 +3459,21 @@ func (p *FetchTaggedRequest) writeField8(oprot thrift.TProtocol) (err error) {
return err
}

func (p *FetchTaggedRequest) writeField9(oprot thrift.TProtocol) (err error) {
if p.IsSetDocsLimit() {
if err := oprot.WriteFieldBegin("docsLimit", thrift.I64, 9); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 9:docsLimit: ", p), err)
}
if err := oprot.WriteI64(int64(*p.DocsLimit)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.docsLimit (9) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 9:docsLimit: ", p), err)
}
}
return err
}

func (p *FetchTaggedRequest) String() string {
if p == nil {
return "<nil>"
Expand Down
Loading