Add aggregator backfill, pulling fine+coarse buckets from collectors
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
st "git.ipng.ch/ipng/nginx-logtail/internal/store"
|
||||
pb "git.ipng.ch/ipng/nginx-logtail/proto/logtailpb"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -70,6 +71,33 @@ func peerAddr(ctx context.Context) string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
func (srv *Server) DumpSnapshots(_ *pb.DumpSnapshotsRequest, stream grpc.ServerStreamingServer[pb.Snapshot]) error {
|
||||
fine, coarse := srv.store.DumpRings()
|
||||
for _, snap := range fine {
|
||||
if err := stream.Send(storeSnapshotToProto(snap, srv.source, false)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, snap := range coarse {
|
||||
if err := stream.Send(storeSnapshotToProto(snap, srv.source, true)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func storeSnapshotToProto(snap st.Snapshot, source string, isCoarse bool) *pb.Snapshot {
|
||||
msg := &pb.Snapshot{
|
||||
Source: source,
|
||||
Timestamp: snap.Timestamp.Unix(),
|
||||
IsCoarse: isCoarse,
|
||||
}
|
||||
for _, e := range snap.Entries {
|
||||
msg.Entries = append(msg.Entries, &pb.TopNEntry{Label: e.Label, Count: e.Count})
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func (srv *Server) StreamSnapshots(req *pb.SnapshotRequest, stream grpc.ServerStreamingServer[pb.Snapshot]) error {
|
||||
ch := srv.store.Subscribe()
|
||||
defer srv.store.Unsubscribe(ch)
|
||||
|
||||
Reference in New Issue
Block a user