Skip to content

Commit

Permalink
chore: [IC-272] add storing canister_log_records to canister's system…
Browse files Browse the repository at this point in the history
…_state
  • Loading branch information
maksymar committed Feb 13, 2024
1 parent b31be67 commit accf7f4
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 6 deletions.
3 changes: 1 addition & 2 deletions rs/execution_environment/src/query_handler.rs
Expand Up @@ -358,9 +358,8 @@ fn fetch_canister_logs(
)),
}?;

// TODO(IC-272): temporarily return empty logs until full implementation is ready.
let response = FetchCanisterLogsResponse {
canister_log_records: Vec::new(),
canister_log_records: canister.system_state.canister_log_records.clone(),
};
Ok(WasmResult::Reply(Encode!(&response).unwrap()))
}
Expand Down
Expand Up @@ -300,6 +300,12 @@ enum LogVisibility {
LOG_VISIBILITY_PUBLIC = 2;
}

message CanisterLogRecord {
uint64 idx = 1;
uint64 timestamp_nanos = 2;
bytes content = 3;
}

message CanisterStateBits {
reserved 1;
reserved "controller";
Expand Down Expand Up @@ -370,4 +376,6 @@ message CanisterStateBits {
TotalQueryStats total_query_stats = 41;
// Log visibility for the canister.
LogVisibility log_visibility = 42;
// Log records of the canister.
repeated CanisterLogRecord canister_log_records = 43;
}
13 changes: 13 additions & 0 deletions rs/protobuf/src/gen/state/state.canister_state_bits.v1.rs
Expand Up @@ -526,6 +526,16 @@ pub struct WasmChunkStoreMetadata {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CanisterLogRecord {
#[prost(uint64, tag = "1")]
pub idx: u64,
#[prost(uint64, tag = "2")]
pub timestamp_nanos: u64,
#[prost(bytes = "vec", tag = "3")]
pub content: ::prost::alloc::vec::Vec<u8>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CanisterStateBits {
#[prost(uint64, tag = "2")]
pub last_full_execution_round: u64,
Expand Down Expand Up @@ -606,6 +616,9 @@ pub struct CanisterStateBits {
/// Log visibility for the canister.
#[prost(enumeration = "LogVisibility", tag = "42")]
pub log_visibility: i32,
/// Log records of the canister.
#[prost(message, repeated, tag = "43")]
pub canister_log_records: ::prost::alloc::vec::Vec<CanisterLogRecord>,
#[prost(oneof = "canister_state_bits::CanisterStatus", tags = "11, 12, 13")]
pub canister_status: ::core::option::Option<canister_state_bits::CanisterStatus>,
}
Expand Down
8 changes: 7 additions & 1 deletion rs/replicated_state/src/canister_state/system_state.rs
Expand Up @@ -12,7 +12,7 @@ pub use call_context_manager::{CallContext, CallContextAction, CallContextManage
use ic_base_types::NumSeconds;
use ic_logger::{error, ReplicaLogger};
use ic_management_canister_types::{
CanisterChange, CanisterChangeDetails, CanisterChangeOrigin, LogVisibility,
CanisterChange, CanisterChangeDetails, CanisterChangeOrigin, CanisterLogRecord, LogVisibility,
};
use ic_protobuf::{
proxy::{try_from_option_field, ProxyDecodeError},
Expand Down Expand Up @@ -336,6 +336,9 @@ pub struct SystemState {

/// Log visibility of the canister.
pub log_visibility: LogVisibility,

/// Log records of the canister.
pub canister_log_records: Vec<CanisterLogRecord>,
}

/// A wrapper around the different canister statuses.
Expand Down Expand Up @@ -706,6 +709,7 @@ impl SystemState {
canister_history: CanisterHistory::default(),
wasm_chunk_store,
log_visibility: LogVisibility::default(),
canister_log_records: Vec::new(),
}
}

Expand Down Expand Up @@ -750,6 +754,7 @@ impl SystemState {
wasm_chunk_store_data: PageMap,
wasm_chunk_store_metadata: WasmChunkStoreMetadata,
log_visibility: LogVisibility,
canister_log_records: Vec<CanisterLogRecord>,
) -> Self {
Self {
controllers,
Expand All @@ -773,6 +778,7 @@ impl SystemState {
wasm_chunk_store_metadata,
),
log_visibility,
canister_log_records,
}
}

Expand Down
15 changes: 13 additions & 2 deletions rs/state_layout/src/state_layout.rs
Expand Up @@ -4,7 +4,7 @@ use crate::utils::do_copy;
use ic_base_types::{NumBytes, NumSeconds};
use ic_config::flag_status::FlagStatus;
use ic_logger::{error, info, warn, ReplicaLogger};
use ic_management_canister_types::LogVisibility;
use ic_management_canister_types::{CanisterLogRecord, LogVisibility};
use ic_metrics::{buckets::decimal_buckets, MetricsRegistry};
use ic_protobuf::{
proxy::{try_from_option_field, ProxyDecodeError},
Expand Down Expand Up @@ -164,6 +164,7 @@ pub struct CanisterStateBits {
pub wasm_chunk_store_metadata: WasmChunkStoreMetadata,
pub total_query_stats: TotalQueryStats,
pub log_visibility: LogVisibility,
pub canister_log_records: Vec<CanisterLogRecord>,
}

/// This struct contains bits of the `CanisterSnapshot` that are not already
Expand Down Expand Up @@ -1790,6 +1791,11 @@ impl From<CanisterStateBits> for pb_canister_state_bits::CanisterStateBits {
wasm_chunk_store_metadata: Some((&item.wasm_chunk_store_metadata).into()),
total_query_stats: Some((&item.total_query_stats).into()),
log_visibility: item.log_visibility.into(),
canister_log_records: item
.canister_log_records
.into_iter()
.map(|record| record.into())
.collect(),
}
}
}
Expand Down Expand Up @@ -1909,7 +1915,12 @@ impl TryFrom<pb_canister_state_bits::CanisterStateBits> for CanisterStateBits {
"CanisterStateBits::total_query_stats",
)
.unwrap_or_default(),
log_visibility: LogVisibility::from(value.log_visibility),
log_visibility: value.log_visibility.into(),
canister_log_records: value
.canister_log_records
.into_iter()
.map(|record| record.into())
.collect(),
})
}
}
Expand Down
1 change: 1 addition & 0 deletions rs/state_layout/src/state_layout/tests.rs
Expand Up @@ -53,6 +53,7 @@ fn default_canister_state_bits() -> CanisterStateBits {
wasm_chunk_store_metadata: WasmChunkStoreMetadata::default(),
total_query_stats: TotalQueryStats::default(),
log_visibility: LogVisibility::default(),
canister_log_records: Vec::new(),
}
}

Expand Down
1 change: 1 addition & 0 deletions rs/state_manager/src/checkpoint.rs
Expand Up @@ -410,6 +410,7 @@ pub fn load_canister_state<P: ReadPolicy>(
wasm_chunk_store_data,
canister_state_bits.wasm_chunk_store_metadata,
canister_state_bits.log_visibility,
canister_state_bits.canister_log_records,
);

let canister_state = CanisterState {
Expand Down
1 change: 1 addition & 0 deletions rs/state_manager/src/tip.rs
Expand Up @@ -995,6 +995,7 @@ fn serialize_canister_to_tip(
.clone(),
total_query_stats: canister_state.scheduler_state.total_query_stats.clone(),
log_visibility: canister_state.system_state.log_visibility,
canister_log_records: canister_state.system_state.canister_log_records.clone(),
}
.into(),
)?;
Expand Down
22 changes: 21 additions & 1 deletion rs/types/management_canister_types/src/lib.rs
Expand Up @@ -2323,7 +2323,7 @@ impl FetchCanisterLogsRequest {
/// content: blob;
/// }
/// ```
#[derive(Default, Clone, CandidType, Deserialize, Debug, PartialEq)]
#[derive(Default, Clone, CandidType, Deserialize, Debug, PartialEq, Eq)]
pub struct CanisterLogRecord {
pub idx: u64,
pub timestamp_nanos: u64,
Expand All @@ -2333,6 +2333,26 @@ pub struct CanisterLogRecord {

impl Payload<'_> for CanisterLogRecord {}

impl From<pb_canister_state_bits::CanisterLogRecord> for CanisterLogRecord {
fn from(item: pb_canister_state_bits::CanisterLogRecord) -> Self {
Self {
idx: item.idx,
timestamp_nanos: item.timestamp_nanos,
content: item.content,
}
}
}

impl From<CanisterLogRecord> for pb_canister_state_bits::CanisterLogRecord {
fn from(item: CanisterLogRecord) -> Self {
Self {
idx: item.idx,
timestamp_nanos: item.timestamp_nanos,
content: item.content,
}
}
}

/// `CandidType` for `FetchCanisterLogsResponse`
/// ```text
/// record {
Expand Down

0 comments on commit accf7f4

Please sign in to comment.