WatchLogs implements runtimev1.RuntimeServiceServer
(req *runtimev1.WatchLogsRequest, srv runtimev1.RuntimeService_WatchLogsServer)
| 240 | |
| 241 | // WatchLogs implements runtimev1.RuntimeServiceServer |
| 242 | func (s *Server) WatchLogs(req *runtimev1.WatchLogsRequest, srv runtimev1.RuntimeService_WatchLogsServer) error { |
| 243 | ctx := srv.Context() |
| 244 | s.addInstanceRequestAttributes(ctx, req.InstanceId) |
| 245 | observability.AddRequestAttributes(ctx, |
| 246 | attribute.String("args.instance_id", req.InstanceId), |
| 247 | attribute.Bool("args.replay", req.Replay), |
| 248 | attribute.Int("args.replay_limit", int(req.ReplayLimit)), |
| 249 | attribute.String("args.level", req.Level.String()), |
| 250 | ) |
| 251 | |
| 252 | if !auth.GetClaims(ctx, req.InstanceId).Can(runtime.ReadObjects) { |
| 253 | return ErrForbidden |
| 254 | } |
| 255 | |
| 256 | lvl := req.Level |
| 257 | if lvl == runtimev1.LogLevel_LOG_LEVEL_UNSPECIFIED { |
| 258 | lvl = runtimev1.LogLevel_LOG_LEVEL_INFO // backward compatibility |
| 259 | } |
| 260 | |
| 261 | logBuffer, err := s.runtime.InstanceLogs(ctx, req.InstanceId) |
| 262 | if err != nil { |
| 263 | return err |
| 264 | } |
| 265 | if req.Replay { |
| 266 | for _, l := range logBuffer.GetLogs(true, int(req.ReplayLimit), lvl) { |
| 267 | err := srv.Send(&runtimev1.WatchLogsResponse{Log: l}) |
| 268 | if err != nil { |
| 269 | return err |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | return logBuffer.WatchLogs(srv.Context(), func(item *runtimev1.Log) { |
| 275 | err := srv.Send(&runtimev1.WatchLogsResponse{Log: item}) |
| 276 | if err != nil { |
| 277 | s.logger.Info("failed to send log event", zap.Error(err), observability.ZapCtx(ctx)) |
| 278 | } |
| 279 | }, lvl) |
| 280 | } |
| 281 | |
| 282 | func (s *Server) ReloadConfig(ctx context.Context, req *runtimev1.ReloadConfigRequest) (*runtimev1.ReloadConfigResponse, error) { |
| 283 | observability.AddRequestAttributes(ctx, |
no test coverage detected