mrproliu commented on code in PR #1213:
URL:
https://github.com/apache/skywalking-banyandb/pull/1213#discussion_r3559029667
##########
banyand/liaison/grpc/bydbql.go:
##########
@@ -143,6 +166,79 @@ func (b *bydbQLService) Query(ctx context.Context, req
*bydbqlv1.QueryRequest) (
return resp, nil
}
+// topKDumper tracks the top cache-miss and slow queries and, on a supervised
+// goroutine, periodically logs the cumulative top-K. All methods are
nil-safe, so the
+// call sites need no guards when the top-K log is disabled (the dumper is
nil).
+type topKDumper struct {
+ miss *topK
+ slow *topK
+ l *logger.Logger
+ cancel context.CancelFunc
+}
+
+// newTopKDumper starts the trackers and the dump goroutine; a non-positive
interval
+// disables the feature and returns nil.
+func newTopKDumper(interval time.Duration, l *logger.Logger) *topKDumper {
+ if interval <= 0 {
+ return nil
+ }
+ ctx, cancel := context.WithCancel(context.Background())
+ d := &topKDumper{miss: newTopK(bydbqlTopKSize), slow:
newTopK(bydbqlTopKSize), l: l, cancel: cancel}
+ run.Go(ctx, "liaison.grpc.bydbql.topk-dump", l, func(ctx
context.Context) {
+ ticker := time.NewTicker(interval)
+ defer ticker.Stop()
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ case <-ticker.C:
+ d.dump()
+ }
+ }
+ })
+ return d
+}
+
+func (d *topKDumper) observeMiss(query string) {
+ if d != nil {
+ d.miss.observe(query, 0)
+ }
+}
+
+func (d *topKDumper) observeSlow(query string, dur time.Duration) {
+ if d != nil {
+ d.slow.observe(query, dur)
+ }
+}
+
+func (d *topKDumper) close() {
+ if d != nil && d.cancel != nil {
+ d.cancel()
+ }
+}
+
+func (d *topKDumper) dump() {
+ d.logTopK(d.miss, "top bydbql cache-miss queries", func(s topKSlot)
string {
Review Comment:
I have changed the top-K to `128` and the logger filters only with `count >=
2`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]