@@ -56,13 +56,14 @@ use crate::alerts::alert_traits::{AlertManagerTrait, AlertTrait};
5656use crate :: alerts:: alert_types:: ThresholdAlert ;
5757use crate :: alerts:: target:: { NotificationConfig , TARGETS } ;
5858use crate :: handlers:: http:: fetch_schema;
59+ use crate :: metastore:: MetastoreError ;
5960// use crate::handlers::http::query::create_streams_for_distributed;
6061// use crate::option::Mode;
6162use crate :: parseable:: { PARSEABLE , StreamNotFound } ;
6263use crate :: query:: { QUERY_SESSION , resolve_stream_names} ;
6364use crate :: rbac:: map:: SessionKey ;
6465use crate :: storage;
65- use crate :: storage:: { ALERTS_ROOT_DIRECTORY , ObjectStorageError } ;
66+ use crate :: storage:: ObjectStorageError ;
6667use crate :: sync:: alert_runtime;
6768use crate :: utils:: user_auth_for_query;
6869
@@ -103,10 +104,7 @@ pub fn create_default_alerts_manager() -> Alerts {
103104
104105impl AlertConfig {
105106 /// Migration function to convert v1 alerts to v2 structure
106- pub async fn migrate_from_v1 (
107- alert_json : & JsonValue ,
108- store : & dyn crate :: storage:: ObjectStorage ,
109- ) -> Result < AlertConfig , AlertError > {
107+ pub async fn migrate_from_v1 ( alert_json : & JsonValue ) -> Result < AlertConfig , AlertError > {
110108 let basic_fields = Self :: parse_basic_fields ( alert_json) ?;
111109 let alert_info = format ! ( "Alert '{}' (ID: {})" , basic_fields. title, basic_fields. id) ;
112110
@@ -138,7 +136,7 @@ impl AlertConfig {
138136 } ;
139137
140138 // Save the migrated alert back to storage
141- store . put_alert ( basic_fields . id , & migrated_alert) . await ?;
139+ PARSEABLE . metastore . put_alert ( & migrated_alert) . await ?;
142140
143141 Ok ( migrated_alert)
144142 }
@@ -950,6 +948,8 @@ pub enum AlertError {
950948 Unimplemented ( String ) ,
951949 #[ error( "{0}" ) ]
952950 ValidationFailure ( String ) ,
951+ #[ error( transparent) ]
952+ MetastoreError ( #[ from] MetastoreError ) ,
953953}
954954
955955impl actix_web:: ResponseError for AlertError {
@@ -977,6 +977,7 @@ impl actix_web::ResponseError for AlertError {
977977 Self :: ArrowError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
978978 Self :: Unimplemented ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
979979 Self :: NotPresentInOSS ( _) => StatusCode :: BAD_REQUEST ,
980+ Self :: MetastoreError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
980981 }
981982 }
982983
@@ -991,19 +992,10 @@ impl actix_web::ResponseError for AlertError {
991992impl AlertManagerTrait for Alerts {
992993 /// Loads alerts from disk, blocks
993994 async fn load ( & self ) -> anyhow:: Result < ( ) > {
994- let mut map = self . alerts . write ( ) . await ;
995- let store = PARSEABLE . storage . get_object_store ( ) ;
996-
997995 // Get alerts path and read raw bytes for migration handling
998- let relative_path = relative_path :: RelativePathBuf :: from ( ALERTS_ROOT_DIRECTORY ) ;
996+ let raw_objects = PARSEABLE . metastore . get_alerts ( ) . await ? ;
999997
1000- let raw_objects = store
1001- . get_objects (
1002- Some ( & relative_path) ,
1003- Box :: new ( |file_name| file_name. ends_with ( ".json" ) ) ,
1004- )
1005- . await
1006- . unwrap_or_default ( ) ;
998+ let mut map = self . alerts . write ( ) . await ;
1007999
10081000 for raw_bytes in raw_objects {
10091001 // First, try to parse as JSON Value to check version
@@ -1022,7 +1014,7 @@ impl AlertManagerTrait for Alerts {
10221014 || json_value. get ( "stream" ) . is_some ( )
10231015 {
10241016 // This is a v1 alert that needs migration
1025- match AlertConfig :: migrate_from_v1 ( & json_value, store . as_ref ( ) ) . await {
1017+ match AlertConfig :: migrate_from_v1 ( & json_value) . await {
10261018 Ok ( migrated) => migrated,
10271019 Err ( e) => {
10281020 error ! ( "Failed to migrate v1 alert: {e}" ) ;
@@ -1042,7 +1034,7 @@ impl AlertManagerTrait for Alerts {
10421034 } else {
10431035 // No version field, assume v1 and migrate
10441036 warn ! ( "Found alert without version field, assuming v1 and migrating" ) ;
1045- match AlertConfig :: migrate_from_v1 ( & json_value, store . as_ref ( ) ) . await {
1037+ match AlertConfig :: migrate_from_v1 ( & json_value) . await {
10461038 Ok ( migrated) => migrated,
10471039 Err ( e) => {
10481040 error ! ( "Failed to migrate alert without version: {e}" ) ;
@@ -1253,8 +1245,6 @@ impl AlertManagerTrait for Alerts {
12531245 alert_id : Ulid ,
12541246 new_notification_state : NotificationState ,
12551247 ) -> Result < ( ) , AlertError > {
1256- // let store = PARSEABLE.storage.get_object_store();
1257-
12581248 // read and modify alert
12591249 let mut write_access = self . alerts . write ( ) . await ;
12601250 let mut alert: Box < dyn AlertTrait > = if let Some ( alert) = write_access. get ( & alert_id) {
0 commit comments