|
1 | | -use super::super_agent::TEST_CLUSTER_NAME; |
| 1 | +use crate::common::retry::retry; |
2 | 2 | use crate::common::runtime::tokio_runtime; |
3 | 3 | use newrelic_super_agent::k8s::client::SyncK8sClient; |
4 | | -use newrelic_super_agent::k8s::store::K8sStore; |
5 | | -use newrelic_super_agent::opamp::instance_id; |
6 | | -use newrelic_super_agent::opamp::instance_id::getter::{ |
7 | | - InstanceIDGetter, InstanceIDWithIdentifiersGetter, |
8 | | -}; |
| 4 | +use newrelic_super_agent::k8s::store::{K8sStore, STORE_KEY_INSTANCE_ID}; |
| 5 | +use newrelic_super_agent::opamp::instance_id::getter::DataStored; |
9 | 6 | use newrelic_super_agent::opamp::instance_id::InstanceID; |
10 | 7 | use newrelic_super_agent::super_agent::config::AgentID; |
11 | 8 | use std::sync::Arc; |
| 9 | +use std::time::Duration; |
12 | 10 |
|
13 | 11 | pub fn get_instance_id(namespace: &str, agent_id: &AgentID) -> InstanceID { |
14 | 12 | let k8s_client = |
15 | 13 | Arc::new(SyncK8sClient::try_new(tokio_runtime(), namespace.to_string()).unwrap()); |
16 | | - let instance_id_getter = InstanceIDWithIdentifiersGetter::new_k8s_instance_id_getter( |
17 | | - Arc::new(K8sStore::new(k8s_client)), |
18 | | - instance_id::get_identifiers(TEST_CLUSTER_NAME.to_string(), "".to_string()), |
19 | | - ); |
20 | | - instance_id_getter.get(agent_id).unwrap() |
| 14 | + let store = K8sStore::new(k8s_client); |
| 15 | + |
| 16 | + let mut id = InstanceID::create(); |
| 17 | + |
| 18 | + retry(60, Duration::from_secs(1), || { |
| 19 | + let data: Option<DataStored> = store.get_opamp_data(agent_id, STORE_KEY_INSTANCE_ID)?; |
| 20 | + id = data |
| 21 | + .ok_or(format!("agent_id={} Instance ID not found", agent_id))? |
| 22 | + .instance_id; |
| 23 | + Ok(()) |
| 24 | + }); |
| 25 | + id |
21 | 26 | } |
0 commit comments