-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(callhome): add protobuf event message
Signed-off-by: Vandana Varakantham <[email protected]>
- Loading branch information
Vandana Varakantham
committed
Jul 12, 2023
1 parent
ae78761
commit 8b38932
Showing
8 changed files
with
168 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
tonic_build::configure() | ||
.type_attribute(".", "#[derive(serde::Deserialize, serde::Serialize)]") | ||
.extern_path(".google.protobuf.Timestamp", "::prost_wkt_types::Timestamp") | ||
.compile(&["protobuf/v1/event.proto"], &["protobuf/"]) | ||
.unwrap_or_else(|e| panic!("event v1 protobuf compilation failed: {e}")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
syntax = "proto3"; | ||
|
||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "google/protobuf/timestamp.proto"; | ||
|
||
package v1.event; | ||
|
||
// Event Message | ||
message EventMessage { | ||
// Event category | ||
EventCategory category = 1; | ||
// Event action | ||
EventAction action = 2; | ||
// Target id for the category against which action is performed | ||
string target = 3; | ||
// Event meta data | ||
EventMeta metadata = 4; | ||
} | ||
|
||
// Event Category | ||
enum EventCategory { | ||
UnknownCategory = 0; | ||
Pool = 1; | ||
Volume = 2; | ||
} | ||
|
||
// Event Action | ||
enum EventAction { | ||
UnknownAction = 0; | ||
Create = 1; | ||
Delete = 2; | ||
} | ||
|
||
// Event meta data | ||
message EventMeta { | ||
// Something that uniquely identifies events. UUIDv4. GUID. | ||
string id = 1; | ||
EventSource source = 2; | ||
// Event timestamp | ||
google.protobuf.Timestamp timestamp = 3; | ||
// Version of the event message | ||
Version version = 4; | ||
} | ||
|
||
// Event source | ||
message EventSource { | ||
// Io-engine or core-agent | ||
Component component = 1; | ||
// Node name | ||
string node = 2; | ||
} | ||
|
||
// Source Component | ||
enum Component { | ||
UnknownComponent = 0; | ||
CoreAgent = 1; | ||
IoEngine = 2; | ||
} | ||
|
||
// Event message version | ||
enum Version { | ||
UnknownVersion = 0; | ||
V1 = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::event::{Component, EventMessage, EventMeta, EventSource, Version}; | ||
use chrono::Utc; | ||
use once_cell::sync::OnceCell; | ||
use std::str::FromStr; | ||
|
||
/// Once cell static variable to store the component field of the event source. | ||
static COMPONENT: OnceCell<Component> = OnceCell::new(); | ||
|
||
/// Initialize the event source component with the service name. | ||
pub fn initilize_source_component(comp: &str) { | ||
COMPONENT.get_or_init(|| Component::from_str(comp).unwrap_or_default()); | ||
} | ||
|
||
impl EventMeta { | ||
/// New event metadata with default values. | ||
pub fn new() -> Self { | ||
Self { | ||
id: uuid::Uuid::new_v4().to_string(), | ||
source: Some(EventSource::new("".to_string())), | ||
timestamp: Some(Utc::now().into()), | ||
version: Version::V1.into(), | ||
} | ||
} | ||
} | ||
|
||
impl EventSource { | ||
/// New event source with default values. | ||
pub fn new(node: String) -> Self { | ||
let component = COMPONENT.get().cloned().unwrap_or_default().into(); | ||
Self { component, node } | ||
} | ||
} | ||
|
||
impl EventMessage { | ||
/// Generate the event trace with event message. | ||
pub fn generate(&self) { | ||
let event_data = serde_json::to_string(&self).unwrap_or_default(); | ||
tracing::event!(target: "target-mbus", tracing::Level::INFO, event_data); | ||
} | ||
} | ||
|
||
// Get Component from service name. | ||
impl FromStr for Component { | ||
type Err = String; | ||
fn from_str(c: &str) -> Result<Self, Self::Err> { | ||
match c { | ||
"agent-core" => Ok(Self::CoreAgent), | ||
"io-engine" => Ok(Self::IoEngine), | ||
_ => Err(format!("Received event from unknown component {c}")), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.