MCPcopy Create free account
hub / github.com/rilldata/rill / WatchLogs

Method WatchLogs

runtime/server/instances.go:242–280  ·  view source on GitHub ↗

WatchLogs implements runtimev1.RuntimeServiceServer

(req *runtimev1.WatchLogsRequest, srv runtimev1.RuntimeService_WatchLogsServer)

Source from the content-addressed store, hash-verified

240
241// WatchLogs implements runtimev1.RuntimeServiceServer
242func (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
282func (s *Server) ReloadConfig(ctx context.Context, req *runtimev1.ReloadConfigRequest) (*runtimev1.ReloadConfigResponse, error) {
283 observability.AddRequestAttributes(ctx,

Callers 1

SSEHandlerMethod · 0.95

Calls 13

AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
ZapCtxFunction · 0.92
CanMethod · 0.80
InstanceLogsMethod · 0.80
InfoMethod · 0.80
ContextMethod · 0.65
StringMethod · 0.65
GetLogsMethod · 0.65
SendMethod · 0.65
WatchLogsMethod · 0.65

Tested by

no test coverage detected