Skip to content

Commit 628de39

Browse files
committed
Improved log messages for AdmissionWebhook request failures
1 parent 4a57459 commit 628de39

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

src/projects/modules/access_control/access_controller.cpp

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,25 @@ std::tuple<AccessController::VerificationResult, std::shared_ptr<const Admission
196196
[&request_info](const ov::String &control_server_url_address,
197197
const std::shared_ptr<const ov::SocketAddress> &client_address,
198198
const std::shared_ptr<const AdmissionWebhooks> &admission_webhooks) {
199-
logti("AdmissionWebhooks queried %s whether client %s could access %s. (Result : %s Elapsed : %u ms)",
200-
control_server_url_address.CStr(),
201-
client_address->ToString(false).CStr(),
202-
request_info->GetRequestedUrl()->ToUrlString().CStr(),
203-
(admission_webhooks->GetErrCode() == AdmissionWebhooks::ErrCode::ALLOWED) ? "Allow" : "Reject",
204-
admission_webhooks->GetElapsedTime());
199+
if (admission_webhooks->GetErrCode() == AdmissionWebhooks::ErrCode::ALLOWED ||
200+
admission_webhooks->GetErrCode() == AdmissionWebhooks::ErrCode::DENIED)
201+
{
202+
logti("AdmissionWebhook queried %s for client %s accessing %s (Result: %s, Elapsed: %u ms)",
203+
control_server_url_address.CStr(),
204+
client_address->ToString(false).CStr(),
205+
request_info->GetRequestedUrl()->ToUrlString().CStr(),
206+
admission_webhooks->GetErrCodeString().CStr(),
207+
admission_webhooks->GetElapsedTime());
208+
}
209+
else
210+
{
211+
logtw("Failed to query AdmissionWebhook %s for client %s accessing %s (Result: %s, Elapsed: %u ms)",
212+
control_server_url_address.CStr(),
213+
client_address->ToString(false).CStr(),
214+
request_info->GetRequestedUrl()->ToUrlString().CStr(),
215+
admission_webhooks->GetErrCodeString().CStr(),
216+
admission_webhooks->GetElapsedTime());
217+
}
205218
});
206219
}
207220

@@ -229,12 +242,25 @@ std::tuple<AccessController::VerificationResult, std::shared_ptr<const Admission
229242
[&request_info](const ov::String &control_server_url_address,
230243
const std::shared_ptr<const ov::SocketAddress> &client_address,
231244
const std::shared_ptr<const AdmissionWebhooks> &admission_webhooks) {
232-
logti("AdmissionWebhooks notified %s that client %s has closed the connection to %s. (Response : %s Elapsed : %u ms)",
233-
control_server_url_address.CStr(),
234-
client_address->ToString(false).CStr(),
235-
request_info->GetRequestedUrl()->ToUrlString().CStr(),
236-
(admission_webhooks->GetErrCode() == AdmissionWebhooks::ErrCode::ALLOWED) ? "Allow" : "Reject",
237-
admission_webhooks->GetElapsedTime());
245+
if (admission_webhooks->GetErrCode() == AdmissionWebhooks::ErrCode::ALLOWED ||
246+
admission_webhooks->GetErrCode() == AdmissionWebhooks::ErrCode::DENIED)
247+
{
248+
logti("AdmissionWebhook notified %s that client %s closed the connection to %s (Result: %s, Elapsed: %u ms)",
249+
control_server_url_address.CStr(),
250+
client_address->ToString(false).CStr(),
251+
request_info->GetRequestedUrl()->ToUrlString().CStr(),
252+
admission_webhooks->GetErrCodeString().CStr(),
253+
admission_webhooks->GetElapsedTime());
254+
}
255+
else
256+
{
257+
logtw("Failed to notify AdmissionWebhook %s that client %s closed the connection to %s (Result: %s, Elapsed: %u ms)",
258+
control_server_url_address.CStr(),
259+
client_address->ToString(false).CStr(),
260+
request_info->GetRequestedUrl()->ToUrlString().CStr(),
261+
admission_webhooks->GetErrCodeString().CStr(),
262+
admission_webhooks->GetElapsedTime());
263+
}
238264
});
239265
}
240266

src/projects/modules/access_control/admission_webhooks/admission_webhooks.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ AdmissionWebhooks::ErrCode AdmissionWebhooks::GetErrCode() const
4747
return _err_code;
4848
}
4949

50+
ov::String AdmissionWebhooks::GetErrCodeString() const
51+
{
52+
switch (_err_code)
53+
{
54+
case ErrCode::ALLOWED:
55+
return "Allowed";
56+
case ErrCode::DENIED:
57+
return "Denied";
58+
case ErrCode::INVALID_DATA_FORMAT:
59+
return "InvalidDataFormat";
60+
case ErrCode::INVALID_STATUS_CODE:
61+
return "InvalidStatusCode";
62+
case ErrCode::INTERNAL_ERROR:
63+
return "InternalError";
64+
default:
65+
return "Unknown";
66+
}
67+
}
68+
5069
ov::String AdmissionWebhooks::GetErrReason() const
5170
{
5271
return _err_reason;

src/projects/modules/access_control/admission_webhooks/admission_webhooks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class AdmissionWebhooks
5454
const Status::Code status);
5555

5656
ErrCode GetErrCode() const;
57+
ov::String GetErrCodeString() const;
5758
ov::String GetErrReason() const;
5859
std::shared_ptr<ov::Url> GetNewURL() const;
5960
uint64_t GetLifetime() const;

0 commit comments

Comments
 (0)