-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove log line with less than 3 tokens and start working on pr…
…uning old sample
- Loading branch information
1 parent
a66f18b
commit 44eb1c8
Showing
6 changed files
with
209 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pattern | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-kit/log/level" | ||
"github.com/grafana/loki/v3/pkg/util" | ||
"github.com/prometheus/common/model" | ||
) | ||
|
||
func (i *Ingester) initFlushQueues() { | ||
i.flushQueuesDone.Add(i.cfg.ConcurrentFlushes) | ||
for j := 0; j < i.cfg.ConcurrentFlushes; j++ { | ||
i.flushQueues[j] = util.NewPriorityQueue(i.metrics.flushQueueLength) | ||
// for now we don't flush only prune old samples. | ||
// go i.flushLoop(j) | ||
} | ||
} | ||
|
||
func (i *Ingester) Flush() { | ||
i.flush(true) | ||
} | ||
|
||
func (i *Ingester) flush(mayRemoveStreams bool) { | ||
i.sweepUsers(true, mayRemoveStreams) | ||
|
||
// Close the flush queues, to unblock waiting workers. | ||
for _, flushQueue := range i.flushQueues { | ||
flushQueue.Close() | ||
} | ||
|
||
i.flushQueuesDone.Wait() | ||
level.Debug(i.logger).Log("msg", "flush queues have drained") | ||
} | ||
|
||
type flushOp struct { | ||
from model.Time | ||
userID string | ||
fp model.Fingerprint | ||
immediate bool | ||
} | ||
|
||
func (o *flushOp) Key() string { | ||
return fmt.Sprintf("%s-%s-%v", o.userID, o.fp, o.immediate) | ||
} | ||
|
||
func (o *flushOp) Priority() int64 { | ||
return -int64(o.from) | ||
} | ||
|
||
// sweepUsers periodically schedules series for flushing and garbage collects users with no series | ||
func (i *Ingester) sweepUsers(immediate, mayRemoveStreams bool) { | ||
instances := i.getInstances() | ||
|
||
for _, instance := range instances { | ||
i.sweepInstance(instance, immediate, mayRemoveStreams) | ||
} | ||
} | ||
|
||
func (i *Ingester) sweepInstance(instance *instance, _, mayRemoveStreams bool) { | ||
_ = instance.streams.ForEach(func(s *stream) (bool, error) { | ||
if mayRemoveStreams { | ||
instance.streams.WithLock(func() { | ||
if s.prune() { | ||
instance.removeStream(s) | ||
} | ||
}) | ||
} | ||
return true, nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package pattern | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
type ingesterMetrics struct { | ||
flushQueueLength prometheus.Gauge | ||
} | ||
|
||
func newIngesterMetrics(r prometheus.Registerer, metricsNamespace string) *ingesterMetrics { | ||
return &ingesterMetrics{ | ||
flushQueueLength: promauto.With(r).NewGauge(prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: "pattern_ingester", | ||
Name: "flush_queue_length", | ||
Help: "The total number of series pending in the flush queue.", | ||
}), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters