1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-08-10 21:52:01 +02:00

Added hack support for logs streaming cruft

This commit is contained in:
Milos Gajdos
2019-11-30 12:39:29 +00:00
parent 7f1dea72f2
commit ecdadef633
5 changed files with 112 additions and 24 deletions

View File

@@ -59,27 +59,52 @@ func (d *Debug) Logs(ctx context.Context, req *proto.LogRequest, stream proto.De
options = append(options, log.Count(count))
}
if req.Stream {
stop := make(chan bool)
defer close(stop)
// TODO: figure out how to close log stream
// It seems when the client disconnects,
// the connection stays open until some timeout expires
// or something like that; that means the map of streams
// might end up bloating if not cleaned up properly
records := d.log.Stream(stop)
for record := range records {
if err := d.sendRecord(record, stream); err != nil {
return err
}
}
// done streaming, return
return nil
}
// get the log records
records := d.log.Read(options...)
// TODO: figure out the stream
// send all the logs downstream
for _, record := range records {
metadata := make(map[string]string)
for k, v := range record.Metadata {
metadata[k] = v
}
recLog := &proto.Log{
Timestamp: record.Timestamp.UnixNano(),
Value: record.Value.(string),
Metadata: metadata,
}
if err := stream.Send(recLog); err != nil {
if err := d.sendRecord(record, stream); err != nil {
return err
}
}
return nil
}
func (d *Debug) sendRecord(record log.Record, stream proto.Debug_LogsStream) error {
metadata := make(map[string]string)
for k, v := range record.Metadata {
metadata[k] = v
}
recLog := &proto.Log{
Timestamp: record.Timestamp.UnixNano(),
Value: record.Value.(string),
Metadata: metadata,
}
if err := stream.Send(recLog); err != nil {
return err
}
return nil
}