Interface AlertEventRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<AlertEventEntity,Long>, org.springframework.data.jpa.repository.JpaRepository<AlertEventEntity,Long>, org.springframework.data.repository.ListCrudRepository<AlertEventEntity,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<AlertEventEntity,Long>, org.springframework.data.repository.PagingAndSortingRepository<AlertEventEntity,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<AlertEventEntity>, org.springframework.data.repository.Repository<AlertEventEntity,Long>

@Repository public interface AlertEventRepository extends org.springframework.data.jpa.repository.JpaRepository<AlertEventEntity,Long>
Spring Data JPA repository for AlertEventEntity.

Supports paginated retrieval of alert events by service for the alert log UI, bulk deletion by age for the data-retention service, and fetching the N most recent events across all services for the dashboard.

Author:
Nazar Montytskyi
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    boolean
     
    org.springframework.data.domain.Page<AlertEventEntity>
    findAllByFiredAtBetweenOrderByFiredAtDesc(LocalDateTime from, LocalDateTime to, org.springframework.data.domain.Pageable pageable)
    Returns a paginated list of all alert events within a time range, newest first.
    org.springframework.data.domain.Page<AlertEventEntity>
    findAllByServiceIdAndFiredAtBetweenOrderByFiredAtDesc(Long serviceId, LocalDateTime from, LocalDateTime to, org.springframework.data.domain.Pageable pageable)
     
    org.springframework.data.domain.Page<AlertEventEntity>
    findAllByServiceIdOrderByFiredAtDesc(Long serviceId, org.springframework.data.domain.Pageable pageable)
    Returns a paginated list of all alert events for a service, newest first.
    Finds the most recent event fired for a specific alert rule.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findAllByServiceIdOrderByFiredAtDesc

      org.springframework.data.domain.Page<AlertEventEntity> findAllByServiceIdOrderByFiredAtDesc(Long serviceId, org.springframework.data.domain.Pageable pageable)
      Returns a paginated list of all alert events for a service, newest first. Used by the event log page and GET /api/alerts/events?serviceId=.
      Parameters:
      serviceId - the service identifier
      pageable - pagination and sorting parameters
      Returns:
      page of alert events
    • findAllByFiredAtBetweenOrderByFiredAtDesc

      org.springframework.data.domain.Page<AlertEventEntity> findAllByFiredAtBetweenOrderByFiredAtDesc(LocalDateTime from, LocalDateTime to, org.springframework.data.domain.Pageable pageable)
      Returns a paginated list of all alert events within a time range, newest first. Used by the REST API to support time-filtered queries.
      Parameters:
      from - start of the time window (inclusive)
      to - end of the time window (inclusive)
      pageable - pagination and sorting parameters
      Returns:
      page of alert events
    • findAllByServiceIdAndFiredAtBetweenOrderByFiredAtDesc

      org.springframework.data.domain.Page<AlertEventEntity> findAllByServiceIdAndFiredAtBetweenOrderByFiredAtDesc(Long serviceId, LocalDateTime from, LocalDateTime to, org.springframework.data.domain.Pageable pageable)
    • findTopByRuleIdOrderByFiredAtDesc

      Optional<AlertEventEntity> findTopByRuleIdOrderByFiredAtDesc(Long ruleId)
      Finds the most recent event fired for a specific alert rule. Used by AlertCooldownManager to determine whether the cooldown period has elapsed before firing another notification.
      Parameters:
      ruleId - the alert rule identifier
      Returns:
      the most recent event for this rule, if any
    • existsByRuleIdAndFiredAtAfter

      @Query("SELECT COUNT(e) > 0 FROM AlertEventEntity e WHERE e.rule.id = :ruleId AND e.firedAt >= :since") boolean existsByRuleIdAndFiredAtAfter(@Param("ruleId") Long ruleId, @Param("since") LocalDateTime since)
    • deleteByFiredAtBefore

      @Modifying @Query("DELETE FROM AlertEventEntity a WHERE a.firedAt < :threshold") int deleteByFiredAtBefore(@Param("threshold") LocalDateTime threshold)