Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated tracing logging #16

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/private/sources/cache/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ impl Cache for GetPolicyOutputCache {
policy_updates.insert(policy_id.clone(), CacheChange::Updated);
}
}

debug!("Policy Cache Pending Updates: policy_updates={policy_updates:?}");

policy_updates
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/private/sources/policy/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ impl Load for ListPolicies {
for policy in policies {
if let Some(policy_id) = policy.policy_id.as_ref() {
policy_ids_map.insert(PolicyId(policy_id.to_string()), policy.clone());
debug!("Loaded Policy from Policy Store: policy_id={policy_id:?}");
}
}
}
}
debug!(
"Loaded all Policies from Policy Store: policy_ids={:?}",
policy_ids_map.keys().collect::<Vec<_>>()
);
Ok(policy_ids_map)
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/private/sources/template/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ impl Load for ListPolicyTemplates {
TemplateId(template_id.to_string()),
policy_template_item.clone(),
);
debug!(
"Loaded Template from Policy Store: policy_template_id={template_id:?}"
);
}
}
}
}

debug!(
"Loaded all Templates from Policy Store: policy_template_ids={:?}",
policy_template_ids_map.keys().collect::<Vec<_>>()
);
Ok(policy_template_ids_map)
}
}
Expand Down
1 change: 0 additions & 1 deletion src/private/translator/avp_to_cedar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ fn update_entity_map(
let entity_name = EntityTypeName::from_str(identifier_type.as_str())?;
let entity_id = EntityId::from_str(identifier_id.as_str())?;
let entity = EntityUid::from_type_name_and_id(entity_name, entity_id);
debug!("Set Principal and Resource to the Entity Map: entity_name={identifier_type:?}: entity_id={identifier_id:?}");
entity_map.insert(slot_id, entity);
}
Ok(())
Expand Down
15 changes: 13 additions & 2 deletions src/public/entity_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use thiserror::Error;
use tokio::runtime::Handle;
use tokio::sync::{Mutex, RwLock};
use tokio::task;
use tracing::error;
use tracing::{debug, error, info, instrument};

use cedar_local_agent::public::{
EntityProviderError, SimpleEntityProvider, UpdateProviderData, UpdateProviderDataError,
Expand Down Expand Up @@ -90,6 +90,7 @@ impl EntityProvider {
///
/// Can error if the builder is incorrect or if the `new` constructor fails to gather the
/// applicable data on initialization.
#[instrument(skip(verified_permissions_client), err(Debug))]
pub fn from_client(
policy_store_id: String,
verified_permissions_client: Client,
Expand All @@ -104,6 +105,7 @@ impl EntityProvider {
)
}

#[instrument(skip(config), err(Debug))]
fn new(config: Config) -> Result<Self, ProviderError> {
let Config {
policy_store_id,
Expand Down Expand Up @@ -135,6 +137,9 @@ impl EntityProvider {
entities: RwLock::new(Arc::new(schema.action_entities()?)),
})
} else {
debug!(
"No Schema defined at Policy Store: policy_store_id={policy_store_id:?}"
);
Ok(Self {
policy_store_id,
schema_source,
Expand Down Expand Up @@ -162,13 +167,15 @@ impl EntityProvider {

#[async_trait]
impl SimpleEntityProvider for EntityProvider {
#[instrument(skip_all, err(Debug))]
async fn get_entities(&self, _: &Request) -> Result<Arc<Entities>, EntityProviderError> {
Ok(self.entities.read().await.clone())
}
}

#[async_trait]
impl UpdateProviderData for EntityProvider {
#[instrument(skip(self), err(Debug))]
async fn update_provider_data(&self) -> Result<(), UpdateProviderDataError> {
let fetch_schema_result = self
.schema_source
Expand All @@ -187,6 +194,10 @@ impl UpdateProviderData for EntityProvider {
.action_entities()
.map_err(|e| UpdateProviderDataError::General(Box::new(e)))?
} else {
debug!(
"No Schema defined at Policy Store: policy_store_id={:?}",
self.policy_store_id.clone()
);
Entities::empty()
}
}
Expand All @@ -206,7 +217,7 @@ impl UpdateProviderData for EntityProvider {
let mut entities_data = self.entities.write().await;
*entities_data = Arc::new(entities);
}

info!("Updated Entity Provider");
Ok(())
}
}
8 changes: 6 additions & 2 deletions src/public/policy_set_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use thiserror::Error;
use tokio::runtime::Handle;
use tokio::sync::{Mutex, RwLock};
use tokio::task;
use tracing::error;
use tracing::{error, info, instrument};

use cedar_local_agent::public::{
PolicySetProviderError, SimplePolicySetProvider, UpdateProviderData, UpdateProviderDataError,
Expand Down Expand Up @@ -106,6 +106,7 @@ impl PolicySetProvider {
///
/// Can error if the builder is incorrect or if the `new` constructor fails to gather the
/// applicable data on initialization.
#[instrument(skip(verified_permissions_client), err(Debug))]
pub fn from_client(
policy_store_id: String,
verified_permissions_client: Client,
Expand All @@ -123,6 +124,7 @@ impl PolicySetProvider {
)
}

#[instrument(skip(config), err(Debug))]
fn new(config: Config) -> Result<Self, ProviderError> {
let Config {
policy_store_id,
Expand Down Expand Up @@ -186,13 +188,15 @@ impl PolicySetProvider {

#[async_trait]
impl SimplePolicySetProvider for PolicySetProvider {
#[instrument(skip_all, err(Debug))]
async fn get_policy_set(&self, _: &Request) -> Result<Arc<PolicySet>, PolicySetProviderError> {
Ok(self.policy_set.read().await.clone())
}
}

#[async_trait]
impl UpdateProviderData for PolicySetProvider {
#[instrument(skip(self), err(Debug))]
async fn update_provider_data(&self) -> Result<(), UpdateProviderDataError> {
let templates;
{
Expand Down Expand Up @@ -246,7 +250,7 @@ impl UpdateProviderData for PolicySetProvider {
let mut policy_set = self.policy_set.write().await;
*policy_set = Arc::new(policy_set_data);
}

info!("Updated Policy Set Provider");
Ok(())
}
}