Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Loki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Loki
Commits
714e5d35
Commit
714e5d35
authored
6 years ago
by
Tom Wilkie
Browse files
Options
Downloads
Patches
Plain Diff
Honor limit in ingesters
Signed-off-by:
Tom Wilkie
<
tom.wilkie@gmail.com
>
parent
f35409c7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/ingester/instance.go
+8
-4
8 additions, 4 deletions
pkg/ingester/instance.go
pkg/querier/querier.go
+6
-5
6 additions, 5 deletions
pkg/querier/querier.go
pkg/util/math.go
+8
-0
8 additions, 0 deletions
pkg/util/math.go
with
22 additions
and
9 deletions
pkg/ingester/instance.go
+
8
−
4
View file @
714e5d35
...
...
@@ -10,6 +10,7 @@ import (
"github.com/grafana/logish/pkg/logproto"
"github.com/grafana/logish/pkg/parser"
"github.com/grafana/logish/pkg/querier"
"github.com/grafana/logish/pkg/util"
)
const
queryBatchSize
=
128
...
...
@@ -80,15 +81,17 @@ func (i *instance) Query(req *logproto.QueryRequest, queryServer logproto.Querie
iterator
:=
querier
.
NewHeapIterator
(
iterators
)
defer
iterator
.
Close
()
return
sendBatches
(
iterator
,
queryServer
)
return
sendBatches
(
iterator
,
queryServer
,
req
.
Limit
)
}
func
sendBatches
(
i
querier
.
EntryIterator
,
queryServer
logproto
.
Querier_QueryServer
)
error
{
for
{
batch
,
err
:=
querier
.
ReadBatch
(
i
,
queryBatchSize
)
func
sendBatches
(
i
querier
.
EntryIterator
,
queryServer
logproto
.
Querier_QueryServer
,
limit
uint32
)
error
{
sent
:=
uint32
(
0
)
for
sent
<
limit
{
batch
,
batchSize
,
err
:=
querier
.
ReadBatch
(
i
,
util
.
MinUint32
(
queryBatchSize
,
limit
-
sent
))
if
err
!=
nil
{
return
err
}
sent
+=
batchSize
if
len
(
batch
.
Streams
)
==
0
{
return
nil
...
...
@@ -98,4 +101,5 @@ func sendBatches(i querier.EntryIterator, queryServer logproto.Querier_QueryServ
return
err
}
}
return
nil
}
This diff is collapsed.
Click to expand it.
pkg/querier/querier.go
+
6
−
5
View file @
714e5d35
...
...
@@ -104,13 +104,14 @@ func (q *Querier) Query(ctx context.Context, req *logproto.QueryRequest) (*logpr
iterator
:=
NewHeapIterator
(
iterators
)
defer
iterator
.
Close
()
return
ReadBatch
(
iterator
,
req
.
Limit
)
resp
,
_
,
err
:=
ReadBatch
(
iterator
,
req
.
Limit
)
return
resp
,
err
}
func
ReadBatch
(
i
EntryIterator
,
size
uint32
)
(
*
logproto
.
QueryResponse
,
error
)
{
func
ReadBatch
(
i
EntryIterator
,
size
uint32
)
(
*
logproto
.
QueryResponse
,
uint32
,
error
)
{
streams
:=
map
[
string
]
*
logproto
.
Stream
{}
for
respSize
:=
uint32
(
0
)
;
respSize
<
size
&&
i
.
Next
();
respSize
++
{
respSize
:=
uint32
(
0
)
for
;
respSize
<
size
&&
i
.
Next
();
respSize
++
{
labels
,
entry
:=
i
.
Labels
(),
i
.
Entry
()
stream
,
ok
:=
streams
[
labels
]
if
!
ok
{
...
...
@@ -128,7 +129,7 @@ func ReadBatch(i EntryIterator, size uint32) (*logproto.QueryResponse, error) {
for
_
,
stream
:=
range
streams
{
result
.
Streams
=
append
(
result
.
Streams
,
stream
)
}
return
&
result
,
i
.
Error
()
return
&
result
,
respSize
,
i
.
Error
()
}
// Check implements the grpc healthcheck
...
...
This diff is collapsed.
Click to expand it.
pkg/util/math.go
0 → 100644
+
8
−
0
View file @
714e5d35
package
util
func
MinUint32
(
a
,
b
uint32
)
uint32
{
if
a
<
b
{
return
a
}
return
b
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment