Skip to content

Commit e0775c1

Browse files
authored
Merge pull request #600 from viccuad/feat-request-origin
feat: Add new `request_origin` to metrics baggage
2 parents 17a6122 + 02fbfd8 commit e0775c1

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/communication.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::Result;
2+
use core::fmt;
23
use policy_evaluator::admission_response::AdmissionResponse;
34
use policy_evaluator::policy_evaluator::ValidateRequest;
45
use std::collections::HashMap;
@@ -13,6 +14,15 @@ pub(crate) enum RequestOrigin {
1314
Audit,
1415
}
1516

17+
impl fmt::Display for RequestOrigin {
18+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19+
match self {
20+
RequestOrigin::Validate => write!(f, "validate"),
21+
RequestOrigin::Audit => write!(f, "audit"),
22+
}
23+
}
24+
}
25+
1626
#[derive(Debug)]
1727
pub(crate) struct EvalRequest {
1828
pub policy_id: String,

src/metrics/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct PolicyEvaluation {
3232
pub(crate) resource_request_operation: String,
3333
pub(crate) accepted: bool,
3434
pub(crate) mutated: bool,
35+
pub(crate) request_origin: String,
3536
pub(crate) error_code: Option<u16>,
3637
}
3738

@@ -50,6 +51,7 @@ impl Into<Vec<KeyValue>> for &PolicyEvaluation {
5051
),
5152
KeyValue::new("accepted", self.accepted),
5253
KeyValue::new("mutated", self.mutated),
54+
KeyValue::new("request_origin", self.request_origin.clone()),
5355
];
5456
if let Some(resource_namespace) = &self.resource_namespace {
5557
baggage.append(&mut vec![KeyValue::new(

src/worker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ impl Worker {
227227
resource_request_operation: adm_req.clone().operation,
228228
accepted,
229229
mutated,
230+
request_origin: req.request_origin.to_string(),
230231
error_code,
231232
};
232233
metrics::record_policy_latency(policy_evaluation_duration, &policy_evaluation);

0 commit comments

Comments
 (0)