The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/storage/unified/sqlstash/watch.go

62 lines
1.2 KiB

12 months ago
package sqlstash
import (
"context"
12 months ago
"time"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/storage/unified/resource"
12 months ago
)
func (s *sqlResourceStore) Watch(context.Context, *resource.WatchRequest) (chan *resource.WatchEvent, error) {
return nil, ErrNotImplementedYet
12 months ago
}
func (s *sqlResourceStore) poller(stream chan *resource.WatchEvent) {
12 months ago
var err error
since := int64(0)
interval := 1 * time.Second
t := time.NewTicker(interval)
defer t.Stop()
for {
select {
case <-s.ctx.Done():
return
case <-t.C:
since, err = s.poll(since, stream)
if err != nil {
s.log.Error("watch error", "err", err)
}
t.Reset(interval)
}
}
}
func (s *sqlResourceStore) poll(since int64, out chan *resource.WatchEvent) (int64, error) {
12 months ago
ctx, span := s.tracer.Start(s.ctx, "storage_server.poll")
defer span.End()
ctxLogger := s.log.FromContext(log.WithContextualAttributes(ctx, []any{"method", "poll"}))
for hasmore := true; hasmore; {
err := func() error {
if false {
// TODO
out <- &resource.WatchEvent{}
12 months ago
}
// TODO, copy from entity store
hasmore = false
return nil
}()
if err != nil {
ctxLogger.Error("poll error", "error", err)
return since, err
}
}
return since, nil
}