RunForwarder drains the log buffer and forwards logs to coderd. It blocks until ctx is canceled.
(ctx context.Context, sender Reporter)
| 98 | // RunForwarder drains the log buffer and forwards logs to coderd. |
| 99 | // It blocks until ctx is canceled. |
| 100 | func (s *Server) RunForwarder(ctx context.Context, sender Reporter) error { |
| 101 | s.logger.Debug(ctx, "boundary log forwarder started") |
| 102 | |
| 103 | for { |
| 104 | select { |
| 105 | case <-ctx.Done(): |
| 106 | return ctx.Err() |
| 107 | case req := <-s.logs: |
| 108 | _, err := sender.ReportBoundaryLogs(ctx, req) |
| 109 | if err != nil { |
| 110 | s.logger.Warn(ctx, "failed to forward boundary logs", |
| 111 | slog.Error(err), |
| 112 | slog.F("log_count", len(req.Logs))) |
| 113 | s.metrics.batchesDropped.WithLabelValues(droppedReasonForwardFailed).Inc() |
| 114 | s.metrics.logsDropped.WithLabelValues(droppedReasonForwardFailed).Add(float64(len(req.Logs))) |
| 115 | // Continue forwarding other logs. The current batch is lost, |
| 116 | // but the socket stays alive. |
| 117 | continue |
| 118 | } |
| 119 | s.metrics.batchesForwarded.Inc() |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | func (s *Server) acceptLoop(ctx context.Context) { |
| 125 | defer s.wg.Done() |