Skip to content

Commit

Permalink
chore: adding crud action and model name for analytics (integration-o…
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez authored Jul 10, 2024
1 parent 44eb2ee commit 11e6135
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions integrationos-api/src/endpoints/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub async fn process_request(
.extractor_caller
.send_to_destination_unified(
connection.clone(),
action,
action.clone(),
include_passthrough,
state.config.environment,
headers,
Expand Down Expand Up @@ -303,7 +303,7 @@ pub async fn process_request(
}
};

let metric = Metric::unified(connection.clone());
let metric = Metric::unified(connection.clone(), action);
if let Err(e) = state.metric_tx.send(metric).await {
error!("Could not send metric to receiver: {e}");
}
Expand Down
14 changes: 11 additions & 3 deletions integrationos-api/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use chrono::{DateTime, Datelike, Utc};
use http::HeaderValue;
use integrationos_domain::{event_access::EventAccess, ownership::Ownership, Connection};
use integrationos_domain::{
destination::Action, event_access::EventAccess, ownership::Ownership, Connection,
};
use segment::message::{Track, User};
use serde::Deserialize;
use serde_json::json;
Expand Down Expand Up @@ -39,27 +41,31 @@ impl MetricType {
pub struct Metric {
pub metric_type: MetricType,
pub date: DateTime<Utc>,
pub action: Option<Action>,
}

impl Metric {
pub fn passthrough(connection: Arc<Connection>) -> Self {
Self {
metric_type: MetricType::Passthrough(connection),
date: Utc::now(),
action: None,
}
}

pub fn unified(connection: Arc<Connection>) -> Self {
pub fn unified(connection: Arc<Connection>, action: Action) -> Self {
Self {
metric_type: MetricType::Unified(connection),
date: Utc::now(),
action: Some(action),
}
}

pub fn rate_limited(event_access: Arc<EventAccess>, key: Option<HeaderValue>) -> Self {
Self {
metric_type: MetricType::RateLimited(event_access, key),
date: Utc::now(),
action: None,
}
}

Expand Down Expand Up @@ -123,7 +129,9 @@ impl Metric {
"platform": self.platform(),
"platformVersion": &conn.platform_version,
"clientId": self.ownership().client_id,
"version": &conn.record_metadata.version
"version": &conn.record_metadata.version,
"commonModel": self.action.as_ref().map(|a| a.name()),
"action": self.action.as_ref().map(|a| a.action()),
}),
..Default::default()
},
Expand Down
16 changes: 16 additions & 0 deletions integrationos-domain/src/domain/pipeline/destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ pub enum Action {
},
}

impl Action {
pub fn name(&self) -> &str {
match self {
Action::Passthrough { path, .. } => path,
Action::Unified { name, .. } => name,
}
}

pub fn action(&self) -> Option<&CrudAction> {
match self {
Action::Passthrough { .. } => None,
Action::Unified { action, .. } => Some(action),
}
}
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
#[serde(rename_all = "camelCase")]
Expand Down

0 comments on commit 11e6135

Please sign in to comment.