-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add app_metrics2 reporting to hoghooks (#23931)
- Loading branch information
1 parent
c6db8e6
commit 5199105
Showing
10 changed files
with
653 additions
and
140 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 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,61 @@ | ||
use chrono::{DateTime, Utc}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::{deserialize_datetime, serialize_datetime}; | ||
|
||
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum Source { | ||
Hoghooks, | ||
} | ||
|
||
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum Kind { | ||
Success, | ||
Failure, | ||
} | ||
|
||
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)] | ||
pub struct AppMetric2 { | ||
pub team_id: u32, | ||
#[serde( | ||
serialize_with = "serialize_datetime", | ||
deserialize_with = "deserialize_datetime" | ||
)] | ||
pub timestamp: DateTime<Utc>, | ||
pub app_source: Source, | ||
pub app_source_id: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub instance_id: Option<String>, | ||
pub metric_kind: Kind, | ||
pub metric_name: String, | ||
pub count: u32, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_app_metric2_serialization() { | ||
use chrono::prelude::*; | ||
|
||
let app_metric = AppMetric2 { | ||
team_id: 123, | ||
timestamp: Utc.with_ymd_and_hms(2023, 12, 14, 12, 2, 0).unwrap(), | ||
app_source: Source::Hoghooks, | ||
app_source_id: "hog-function-1".to_owned(), | ||
instance_id: Some("hash".to_owned()), | ||
metric_kind: Kind::Success, | ||
metric_name: "fetch".to_owned(), | ||
count: 456, | ||
}; | ||
|
||
let serialized_json = serde_json::to_string(&app_metric).unwrap(); | ||
|
||
let expected_json = r#"{"team_id":123,"timestamp":"2023-12-14 12:02:00","app_source":"hoghooks","app_source_id":"hog-function-1","instance_id":"hash","metric_kind":"success","metric_name":"fetch","count":456}"#; | ||
|
||
assert_eq!(serialized_json, expected_json); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod app_metrics; | ||
pub mod app_metrics2; | ||
pub mod plugin_logs; | ||
|
||
use chrono::{DateTime, NaiveDateTime, Utc}; | ||
|
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
Oops, something went wrong.