11use std:: sync:: Arc ;
22
33use crate :: agent_control:: agent_id:: AgentID ;
4+ use crate :: agent_control:: defaults:: { STORE_KEY_LOCAL_DATA_CONFIG , STORE_KEY_OPAMP_DATA_CONFIG } ;
45use crate :: on_host:: file_store:: FileStore ;
56use crate :: opamp:: remote_config:: hash:: ConfigState ;
67use crate :: values:: config:: { Config , RemoteConfig } ;
6566 #[ tracing:: instrument( skip_all, err) ]
6667 fn load_local ( & self , agent_id : & AgentID ) -> Result < Option < Config > , ConfigRepositoryError > {
6768 self . file_store
68- . get_local_data :: < YAMLConfig > ( agent_id)
69+ . get_local_data :: < YAMLConfig > ( agent_id, STORE_KEY_LOCAL_DATA_CONFIG )
6970 . map_err ( |err| ConfigRepositoryError :: LoadError ( format ! ( "loading local config: {err}" ) ) )
7071 . map ( |opt_yaml| opt_yaml. map ( |yc| Config :: LocalConfig ( yc. into ( ) ) ) )
7172 }
8081 Ok ( None )
8182 } else {
8283 self . file_store
83- . get_opamp_data :: < RemoteConfig > ( agent_id)
84+ . get_opamp_data :: < RemoteConfig > ( agent_id, STORE_KEY_OPAMP_DATA_CONFIG )
8485 . map_err ( |err| {
8586 ConfigRepositoryError :: LoadError ( format ! ( "loading remote config: {err}" ) )
8687 } )
9798 debug ! ( agent_id = agent_id. to_string( ) , "saving remote config" ) ;
9899
99100 self . file_store
100- . set_opamp_data ( agent_id, remote_config)
101+ . set_opamp_data ( agent_id, STORE_KEY_OPAMP_DATA_CONFIG , remote_config)
101102 . map_err ( |e| ConfigRepositoryError :: StoreError ( format ! ( "storing remote config: {}" , e) ) )
102103 }
103104
@@ -106,7 +107,7 @@ where
106107 agent_id : & AgentID ,
107108 ) -> Result < Option < RemoteConfig > , ConfigRepositoryError > {
108109 self . file_store
109- . get_opamp_data :: < RemoteConfig > ( agent_id)
110+ . get_opamp_data :: < RemoteConfig > ( agent_id, STORE_KEY_OPAMP_DATA_CONFIG )
110111 . map_err ( |e| {
111112 ConfigRepositoryError :: LoadError ( format ! ( "getting remote config hash: {}" , e) )
112113 } )
@@ -124,15 +125,19 @@ where
124125
125126 let maybe_config = self
126127 . file_store
127- . get_opamp_data :: < RemoteConfig > ( agent_id)
128+ . get_opamp_data :: < RemoteConfig > ( agent_id, STORE_KEY_OPAMP_DATA_CONFIG )
128129 . map_err ( |e| {
129130 ConfigRepositoryError :: LoadError ( format ! ( "updating remote config state: {e}" ) )
130131 } ) ?;
131132
132133 match maybe_config {
133134 Some ( remote_config) => self
134135 . file_store
135- . set_opamp_data ( agent_id, & remote_config. with_state ( state) )
136+ . set_opamp_data (
137+ agent_id,
138+ STORE_KEY_OPAMP_DATA_CONFIG ,
139+ & remote_config. with_state ( state) ,
140+ )
136141 . map_err ( |err| {
137142 ConfigRepositoryError :: StoreError ( format ! (
138143 "updating remote config state: {err}"
@@ -151,9 +156,11 @@ where
151156 fn delete_remote ( & self , agent_id : & AgentID ) -> Result < ( ) , ConfigRepositoryError > {
152157 debug ! ( agent_id = agent_id. to_string( ) , "deleting remote config" ) ;
153158
154- self . file_store . delete_opamp_data ( agent_id) . map_err ( |e| {
155- ConfigRepositoryError :: DeleteError ( format ! ( "deleting remote config: {}" , e) )
156- } )
159+ self . file_store
160+ . delete_opamp_data ( agent_id, STORE_KEY_OPAMP_DATA_CONFIG )
161+ . map_err ( |e| {
162+ ConfigRepositoryError :: DeleteError ( format ! ( "deleting remote config: {}" , e) )
163+ } )
157164 }
158165}
159166
@@ -206,9 +213,9 @@ state: applied
206213 let remote_dir_path = RemoteDir :: from ( PathBuf :: from ( "some/remote/path/" ) ) ;
207214 let local_dir_path = LocalDir :: from ( PathBuf :: from ( "some/local/path/" ) ) ;
208215 let test_path = if remote_enabled {
209- remote_dir_path. get_remote_values_file_path ( & agent_id)
216+ remote_dir_path. get_remote_file_path ( & agent_id, STORE_KEY_OPAMP_DATA_CONFIG )
210217 } else {
211- local_dir_path. get_local_values_file_path ( & agent_id)
218+ local_dir_path. get_local_file_path ( & agent_id, STORE_KEY_LOCAL_DATA_CONFIG )
212219 } ;
213220
214221 // Expectations
@@ -247,8 +254,9 @@ state: applied
247254 let dir_manager = MockDirectoryManager :: new ( ) ;
248255 let remote_dir_path = RemoteDir :: from ( PathBuf :: from ( "some/remote/path/" ) ) ;
249256 let local_dir_path = LocalDir :: from ( PathBuf :: from ( "some/local/path/" ) ) ;
250- let remote_path = remote_dir_path. get_remote_values_file_path ( & agent_id) ;
251- let local_path = local_dir_path. get_local_values_file_path ( & agent_id) ;
257+ let remote_path =
258+ remote_dir_path. get_remote_file_path ( & agent_id, STORE_KEY_OPAMP_DATA_CONFIG ) ;
259+ let local_path = local_dir_path. get_local_file_path ( & agent_id, STORE_KEY_LOCAL_DATA_CONFIG ) ;
252260
253261 // Expectations
254262 file_rw. should_not_read_file_not_found ( & remote_path, "some_error_message" . to_string ( ) ) ;
@@ -285,7 +293,7 @@ state: applied
285293 let dir_manager = MockDirectoryManager :: new ( ) ;
286294 let remote_dir_path = PathBuf :: from ( "some/remote/path/" ) ;
287295 let local_dir_path = LocalDir :: from ( PathBuf :: from ( "some/local/path/" ) ) ;
288- let local_path = local_dir_path. get_local_values_file_path ( & agent_id) ;
296+ let local_path = local_dir_path. get_local_file_path ( & agent_id, STORE_KEY_LOCAL_DATA_CONFIG ) ;
289297
290298 // Expectations
291299 file_rw. should_not_read_file_not_found ( & local_path, "some message" . to_string ( ) ) ;
@@ -313,8 +321,10 @@ state: applied
313321 let dir_manager = MockDirectoryManager :: new ( ) ;
314322 let remote_dir_path = RemoteDir :: from ( PathBuf :: from ( "some/remote/path/" ) ) ;
315323 let local_dir_path = LocalDir :: from ( PathBuf :: from ( "some/local/path/" ) ) ;
316- let remote_test_path = remote_dir_path. get_remote_values_file_path ( & agent_id) ;
317- let local_test_path = local_dir_path. get_local_values_file_path ( & agent_id) ;
324+ let remote_test_path =
325+ remote_dir_path. get_remote_file_path ( & agent_id, STORE_KEY_OPAMP_DATA_CONFIG ) ;
326+ let local_test_path =
327+ local_dir_path. get_local_file_path ( & agent_id, STORE_KEY_LOCAL_DATA_CONFIG ) ;
318328
319329 // Expectations
320330 if remote_enabled {
@@ -348,7 +358,8 @@ state: applied
348358 let mut dir_manager = MockDirectoryManager :: new ( ) ;
349359 let remote_dir_path = RemoteDir :: from ( PathBuf :: from ( "some/remote/path/" ) ) ;
350360 let local_dir_path = LocalDir :: from ( PathBuf :: from ( "some/local/path/" ) ) ;
351- let remote_path = remote_dir_path. get_remote_values_file_path ( & agent_id) ;
361+ let remote_path =
362+ remote_dir_path. get_remote_file_path ( & agent_id, STORE_KEY_OPAMP_DATA_CONFIG ) ;
352363
353364 // Expectations
354365 dir_manager. should_create ( remote_path. parent ( ) . unwrap ( ) ) ;
@@ -381,7 +392,8 @@ state: applied
381392 let mut dir_manager = MockDirectoryManager :: new ( ) ;
382393 let remote_dir_path = RemoteDir :: from ( PathBuf :: from ( "some/remote/path/" ) ) ;
383394 let local_dir_path = LocalDir :: from ( PathBuf :: from ( "some/local/path/" ) ) ;
384- let remote_path = remote_dir_path. get_remote_values_file_path ( & agent_id) ;
395+ let remote_path =
396+ remote_dir_path. get_remote_file_path ( & agent_id, STORE_KEY_OPAMP_DATA_CONFIG ) ;
385397
386398 // Expectations
387399 dir_manager. should_not_create (
@@ -413,7 +425,8 @@ state: applied
413425 let mut dir_manager = MockDirectoryManager :: new ( ) ;
414426 let remote_dir_path = RemoteDir :: from ( PathBuf :: from ( "some/remote/path/" ) ) ;
415427 let local_dir_path = LocalDir :: from ( PathBuf :: from ( "some/local/path/" ) ) ;
416- let remote_path = remote_dir_path. get_remote_values_file_path ( & agent_id) ;
428+ let remote_path =
429+ remote_dir_path. get_remote_file_path ( & agent_id, STORE_KEY_OPAMP_DATA_CONFIG ) ;
417430
418431 // Expectations
419432 dir_manager. should_create ( remote_path. parent ( ) . unwrap ( ) ) ;
0 commit comments