CreateTrigger implements runtimev1.RuntimeServiceServer
(ctx context.Context, req *runtimev1.CreateTriggerRequest)
| 342 | |
| 343 | // CreateTrigger implements runtimev1.RuntimeServiceServer |
| 344 | func (s *Server) CreateTrigger(ctx context.Context, req *runtimev1.CreateTriggerRequest) (*runtimev1.CreateTriggerResponse, error) { |
| 345 | s.addInstanceRequestAttributes(ctx, req.InstanceId) |
| 346 | resourceNames := make([]string, len(req.Resources)) |
| 347 | for i, r := range req.Resources { |
| 348 | resourceNames[i] = r.Kind + "/" + r.Name |
| 349 | } |
| 350 | modelNames := make([]string, len(req.Models)) |
| 351 | for i, m := range req.Models { |
| 352 | modelNames[i] = m.Model |
| 353 | } |
| 354 | observability.AddRequestAttributes(ctx, |
| 355 | attribute.String("args.instance_id", req.InstanceId), |
| 356 | attribute.StringSlice("args.resources", resourceNames), |
| 357 | attribute.StringSlice("args.models", modelNames), |
| 358 | attribute.Bool("args.parser", req.Parser), |
| 359 | attribute.Bool("args.all", req.All), |
| 360 | attribute.Bool("args.all_full", req.AllFull), |
| 361 | ) |
| 362 | |
| 363 | if !auth.GetClaims(ctx, req.InstanceId).Can(runtime.EditTrigger) { |
| 364 | return nil, ErrForbidden |
| 365 | } |
| 366 | |
| 367 | ctrl, err := s.runtime.Controller(ctx, req.InstanceId) |
| 368 | if err != nil { |
| 369 | return nil, err |
| 370 | } |
| 371 | |
| 372 | // Build refresh trigger spec |
| 373 | spec := &runtimev1.RefreshTriggerSpec{ |
| 374 | Resources: req.Resources, |
| 375 | Models: req.Models, |
| 376 | } |
| 377 | |
| 378 | // Handle the convenience flag for the project parser. |
| 379 | if req.Parser { |
| 380 | spec.Resources = append(spec.Resources, runtime.GlobalProjectParserName) |
| 381 | } |
| 382 | |
| 383 | // Handle the convenience flags for all (user-facing) resources. |
| 384 | // In practice, we only refresh the major user declared resources that impact serving. |
| 385 | // For example, we don't currently trigger alerts or reports. |
| 386 | if req.All || req.AllFull { |
| 387 | kinds := []string{ |
| 388 | runtime.ResourceKindProjectParser, |
| 389 | runtime.ResourceKindConnector, |
| 390 | runtime.ResourceKindModel, |
| 391 | runtime.ResourceKindMetricsView, |
| 392 | runtime.ResourceKindExplore, |
| 393 | runtime.ResourceKindComponent, |
| 394 | runtime.ResourceKindCanvas, |
| 395 | } |
| 396 | for _, kind := range kinds { |
| 397 | rs, err := ctrl.List(ctx, kind, "", false) |
| 398 | if err != nil { |
| 399 | return nil, fmt.Errorf("failed to list resources of kind %q: %w", kind, err) |
| 400 | } |
| 401 | for _, r := range rs { |