Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new request_origin to metrics baggage #600

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/communication.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use core::fmt;
use policy_evaluator::admission_response::AdmissionResponse;
use policy_evaluator::policy_evaluator::ValidateRequest;
use std::collections::HashMap;
Expand All @@ -13,6 +14,15 @@ pub(crate) enum RequestOrigin {
Audit,
}

impl fmt::Display for RequestOrigin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
RequestOrigin::Validate => write!(f, "validate"),
RequestOrigin::Audit => write!(f, "audit"),
}
}
}

#[derive(Debug)]
pub(crate) struct EvalRequest {
pub policy_id: String,
Expand Down
2 changes: 2 additions & 0 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct PolicyEvaluation {
pub(crate) resource_request_operation: String,
pub(crate) accepted: bool,
pub(crate) mutated: bool,
pub(crate) request_origin: String,
pub(crate) error_code: Option<u16>,
}

Expand All @@ -50,6 +51,7 @@ impl Into<Vec<KeyValue>> for &PolicyEvaluation {
),
KeyValue::new("accepted", self.accepted),
KeyValue::new("mutated", self.mutated),
KeyValue::new("request_origin", self.request_origin.clone()),
];
if let Some(resource_namespace) = &self.resource_namespace {
baggage.append(&mut vec![KeyValue::new(
Expand Down
1 change: 1 addition & 0 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl Worker {
resource_request_operation: adm_req.clone().operation,
accepted,
mutated,
request_origin: req.request_origin.to_string(),
error_code,
};
metrics::record_policy_latency(policy_evaluation_duration, &policy_evaluation);
Expand Down
Loading