MCPcopy Index your code
hub / github.com/rilldata/rill / DeleteAlert

Method DeleteAlert

admin/server/alerts.go:407–463  ·  view source on GitHub ↗
(ctx context.Context, req *adminv1.DeleteAlertRequest)

Source from the content-addressed store, hash-verified

405}
406
407func (s *Server) DeleteAlert(ctx context.Context, req *adminv1.DeleteAlertRequest) (*adminv1.DeleteAlertResponse, error) {
408 observability.AddRequestAttributes(ctx,
409 attribute.String("args.organization", req.Org),
410 attribute.String("args.project", req.Project),
411 attribute.String("args.name", req.Name),
412 )
413
414 proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project)
415 if err != nil {
416 return nil, err
417 }
418
419 claims := auth.GetClaims(ctx)
420 permissions := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID)
421 if !permissions.ReadProd {
422 return nil, status.Error(codes.PermissionDenied, "does not have permission to read project repo")
423 }
424
425 if proj.PrimaryDeploymentID == nil {
426 return nil, status.Error(codes.FailedPrecondition, "project does not have a production deployment")
427 }
428
429 depl, err := s.admin.DB.FindDeployment(ctx, *proj.PrimaryDeploymentID)
430 if err != nil {
431 return nil, err
432 }
433
434 spec, err := s.admin.LookupAlert(ctx, depl, req.Name)
435 if err != nil {
436 return nil, fmt.Errorf("could not get alert: %w", err)
437 }
438 annotations := parseAlertAnnotations(spec.Annotations)
439
440 if !annotations.AdminManaged {
441 return nil, status.Error(codes.FailedPrecondition, "can't edit alert because it was not created from the UI")
442 }
443
444 isOwner := claims.OwnerType() == auth.OwnerTypeUser && annotations.AdminOwnerUserID == claims.OwnerID()
445 if !permissions.ManageAlerts && !isOwner {
446 return nil, status.Error(codes.PermissionDenied, "does not have permission to edit alert")
447 }
448
449 err = s.admin.DB.UpdateVirtualFileDeleted(ctx, proj.ID, "prod", virtualFilePathForManagedAlert(req.Name))
450 if err != nil {
451 return nil, fmt.Errorf("failed to delete virtual file: %w", err)
452 }
453
454 err = s.admin.TriggerParserAndAwaitResource(ctx, depl, req.Name, runtime.ResourceKindAlert)
455 if err != nil {
456 if errors.Is(err, context.DeadlineExceeded) {
457 return nil, status.Error(codes.DeadlineExceeded, "timed out waiting for alert to be deleted")
458 }
459 return nil, fmt.Errorf("failed to reconcile alert: %w", err)
460 }
461
462 return &adminv1.DeleteAlertResponse{}, nil
463}
464

Callers

nothing calls this directly

Calls 15

AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
parseAlertAnnotationsFunction · 0.85
LookupAlertMethod · 0.80
StringMethod · 0.65
FindProjectByNameMethod · 0.65
ProjectPermissionsMethod · 0.65
FindDeploymentMethod · 0.65
ErrorfMethod · 0.65
OwnerTypeMethod · 0.65

Tested by

no test coverage detected