Skip to content

Commit 81d71b3

Browse files
authored
Add improvements to default server metrics (#4548)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> ## Description <!--- Describe your changes in detail --> Add success metric to default server metrics, align naming, add method for disabling outstanding_requests metric. ## Testing <!--- Please describe in detail how you tested your changes --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [ ] For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "client," "server," or both in the `applies_to` key. - [ ] For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "aws-sdk-rust" in the `applies_to` key. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent f401052 commit 81d71b3

File tree

6 files changed

+67
-34
lines changed

6 files changed

+67
-34
lines changed

CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/codegen-server/ @smithy-lang/smithy-rs-server
66
/rust-runtime/aws-smithy-http-server/ @smithy-lang/smithy-rs-server
77
/rust-runtime/aws-smithy-legacy-http-server/ @smithy-lang/smithy-rs-server
8+
/rust-runtime/aws-smithy-http-server-metrics @smithy-lang/smithy-rs-server
9+
/rust-runtime/aws-smithy-http-server-metrics-macro @smithy-lang/smithy-rs-server
810

911
# Python Server
1012
/codegen-server-test/python/ @smithy-lang/smithy-rs-server

examples/pokemon-service/tests/snapshots/metrics_test__metrics_content_via_tcp.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
source: pokemon-service/tests/metrics_test.rs
33
expression: metrics_output
44
---
5-
{"_aws":{"CloudWatchMetrics":[{"Namespace":"Ns","Dimensions":[[]],"Metrics":[{"Name":"found"},{"Name":"outstanding_requests"},{"Name":"http_status_code"},{"Name":"error"},{"Name":"fault"},{"Name":"operation_time","Unit":"Milliseconds"}]}],"Timestamp":"[timestamp]},"found":1,"outstanding_requests":1,"http_status_code":200,"error":0,"fault":0,"operation_time":"[operation_time],"test_request_metric":"test request metric","test_response_metric":"test response metric","requested_pokemon_name":"pikachu","service":"PokemonService","service_version":"2024-03-18","operation":"GetPokemonSpecies","request_id":"[request_id]}
6-
{"_aws":{"CloudWatchMetrics":[{"Namespace":"Ns","Dimensions":[[]],"Metrics":[{"Name":"authenticated"},{"Name":"outstanding_requests"},{"Name":"http_status_code"},{"Name":"error"},{"Name":"fault"},{"Name":"operation_time","Unit":"Milliseconds"}]}],"Timestamp":"[timestamp]},"authenticated":0,"outstanding_requests":1,"http_status_code":401,"error":1,"fault":0,"operation_time":"[operation_time],"test_request_metric":"test request metric","test_response_metric":"test response metric","user":"ash","service":"PokemonService","service_version":"2024-03-18","operation":"GetStorage","request_id":"[request_id]}
7-
{"_aws":{"CloudWatchMetrics":[{"Namespace":"Ns","Dimensions":[[]],"Metrics":[{"Name":"supported_region"},{"Name":"outstanding_requests"},{"Name":"http_status_code"},{"Name":"error"},{"Name":"fault"},{"Name":"operation_time","Unit":"Milliseconds"}]}],"Timestamp":"[timestamp]},"supported_region":0,"outstanding_requests":1,"http_status_code":500,"error":0,"fault":1,"operation_time":"[operation_time],"test_request_metric":"test request metric","test_response_metric":"test response metric","requested_region":"trigger500","service":"PokemonService","service_version":"2024-03-18","operation":"CapturePokemon","request_id":"[request_id]}
5+
{"_aws":{"CloudWatchMetrics":[{"Namespace":"Ns","Dimensions":[[]],"Metrics":[{"Name":"found"},{"Name":"outstanding_requests"},{"Name":"success"},{"Name":"client_error"},{"Name":"server_error"},{"Name":"operation_time","Unit":"Milliseconds"}]}],"Timestamp":"[timestamp]},"found":1,"outstanding_requests":1,"success":1,"client_error":0,"server_error":0,"operation_time":"[operation_time],"test_request_metric":"test request metric","test_response_metric":"test response metric","requested_pokemon_name":"pikachu","service":"PokemonService","service_version":"2024-03-18","operation":"GetPokemonSpecies","request_id":"[request_id],"http_status_code":"200"}
6+
{"_aws":{"CloudWatchMetrics":[{"Namespace":"Ns","Dimensions":[[]],"Metrics":[{"Name":"authenticated"},{"Name":"outstanding_requests"},{"Name":"success"},{"Name":"client_error"},{"Name":"server_error"},{"Name":"operation_time","Unit":"Milliseconds"}]}],"Timestamp":"[timestamp]},"authenticated":0,"outstanding_requests":1,"success":0,"client_error":1,"server_error":0,"operation_time":"[operation_time],"test_request_metric":"test request metric","test_response_metric":"test response metric","user":"ash","service":"PokemonService","service_version":"2024-03-18","operation":"GetStorage","request_id":"[request_id],"http_status_code":"401"}
7+
{"_aws":{"CloudWatchMetrics":[{"Namespace":"Ns","Dimensions":[[]],"Metrics":[{"Name":"supported_region"},{"Name":"outstanding_requests"},{"Name":"success"},{"Name":"client_error"},{"Name":"server_error"},{"Name":"operation_time","Unit":"Milliseconds"}]}],"Timestamp":"[timestamp]},"supported_region":0,"outstanding_requests":1,"success":0,"client_error":0,"server_error":1,"operation_time":"[operation_time],"test_request_metric":"test request metric","test_response_metric":"test response metric","requested_region":"trigger500","service":"PokemonService","service_version":"2024-03-18","operation":"CapturePokemon","request_id":"[request_id],"http_status_code":"500"}

rust-runtime/aws-smithy-http-server-metrics/src/default.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ pub struct DefaultRequestMetrics {
7474
#[metrics]
7575
#[derive(Default, Debug)]
7676
pub struct DefaultResponseMetrics {
77-
pub(crate) http_status_code: Option<u16>,
77+
pub(crate) http_status_code: Option<String>,
78+
/// Success indicator (1 if 2xx status code, 0 otherwise)
79+
pub(crate) success: Option<bool>,
7880
/// Client error indicator (1 if 4xx status code, 0 otherwise)
79-
pub(crate) error: Option<u64>,
80-
/// Server fault indicator (1 if 5xx status code, 0 otherwise)
81-
pub(crate) fault: Option<u64>,
81+
pub(crate) client_error: Option<bool>,
82+
/// Server error indicator (1 if 5xx status code, 0 otherwise)
83+
pub(crate) server_error: Option<bool>,
8284
/// Wallclock time from pre-deserialization of the model input to post-serialization of the model output
8385
pub(crate) operation_time: Option<Duration>,
8486
}
@@ -103,8 +105,9 @@ pub struct DefaultRequestMetricsConfig {
103105
pub struct DefaultResponseMetricsConfig {
104106
pub(crate) disable_all: bool,
105107
pub(crate) disable_http_status_code: bool,
106-
pub(crate) disable_error: bool,
107-
pub(crate) disable_fault: bool,
108+
pub(crate) disable_success: bool,
109+
pub(crate) disable_client_error: bool,
110+
pub(crate) disable_server_error: bool,
108111
pub(crate) disable_operation_time: bool,
109112
}
110113

rust-runtime/aws-smithy-http-server-metrics/src/layer/builder.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,62 @@ macro_rules! impl_disable_methods {
4444
self
4545
}
4646

47-
/// Disable the `request_id` metric
47+
/// Disable the default `outstanding_requests` metric
48+
pub fn disable_default_outstanding_requests_metric(mut self) -> Self {
49+
self.default_req_metrics_config.disable_outstanding_requests = true;
50+
self
51+
}
52+
53+
/// Disable the default `request_id` metric
4854
pub fn disable_default_request_id_metric(mut self) -> Self {
4955
self.default_req_metrics_config.disable_request_id = true;
5056
self
5157
}
5258

53-
/// Disable the `operation_name` metric
59+
/// Disable the default `operation_name` metric
5460
pub fn disable_default_operation_metric(mut self) -> Self {
5561
self.default_req_metrics_config.disable_operation = true;
5662
self
5763
}
5864

59-
/// Disable the `service_name` metric
65+
/// Disable the default `service_name` metric
6066
pub fn disable_default_service_metric(mut self) -> Self {
6167
self.default_req_metrics_config.disable_service = true;
6268
self
6369
}
6470

65-
/// Disable the `service_version` metric
71+
/// Disable the default `service_version` metric
6672
pub fn disable_default_service_version_metric(mut self) -> Self {
6773
self.default_req_metrics_config.disable_service_version = true;
6874
self
6975
}
7076

71-
/// Disable the `http_status_code` metric
77+
/// Disable the default `http_status_code` metric
7278
pub fn disable_default_http_status_code_metric(mut self) -> Self {
7379
self.default_res_metrics_config.disable_http_status_code = true;
7480
self
7581
}
7682

77-
/// Disable the `error` metric
78-
pub fn disable_error_metric(mut self) -> Self {
79-
self.default_res_metrics_config.disable_error = true;
83+
/// Disable the default `success` metric
84+
pub fn disable_default_success_metric(mut self) -> Self {
85+
self.default_res_metrics_config.disable_success = true;
86+
self
87+
}
88+
89+
/// Disable the default `client_error` metric
90+
pub fn disable_default_client_error_metric(mut self) -> Self {
91+
self.default_res_metrics_config.disable_client_error = true;
8092
self
8193
}
8294

83-
/// Disable the `fault` metric
84-
pub fn disable_fault_metric(mut self) -> Self {
85-
self.default_res_metrics_config.disable_fault = true;
95+
/// Disable the default `server_error` metric
96+
pub fn disable_default_server_error_metric(mut self) -> Self {
97+
self.default_res_metrics_config.disable_server_error = true;
8698
self
8799
}
88100

89-
/// Disable the `operation_time` metric
90-
pub fn disable_operation_time_metric(mut self) -> Self {
101+
/// Disable the default `operation_time` metric
102+
pub fn disable_default_operation_time_metric(mut self) -> Self {
91103
self.default_res_metrics_config.disable_operation_time = true;
92104
self
93105
}

rust-runtime/aws-smithy-http-server-metrics/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@
173173
//! | Metric | Description |
174174
//! |--------|-------------|
175175
//! | `http_status_code` | HTTP status code of the response |
176-
//! | `error` | Client error indicator (4xx status code) |
177-
//! | `fault` | Server fault indicator (5xx status code) |
176+
//! | `success` | Success indicator (2xx status code) |
177+
//! | `client_error` | Client error indicator (4xx status code) |
178+
//! | `server_error` | Server error indicator (5xx status code) |
178179
//! | `operation_time` | Timestamp that denotes operation time from pre-deserialization to post-serialization |
179180
//!
180181
//! # Platform support

rust-runtime/aws-smithy-http-server-metrics/src/plugin.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,30 @@ fn get_default_response_metrics(
307307
operation_time: Option<Duration>,
308308
) -> DefaultResponseMetrics {
309309
let status = res.status();
310-
let status_code = status.as_u16();
311310

312-
let error = if (400..500).contains(&status_code) {
313-
Some(1)
311+
let success = if status.is_success() {
312+
Some(true)
314313
} else {
315-
Some(0)
314+
Some(false)
316315
};
317316

318-
let fault = if status_code >= 500 { Some(1) } else { Some(0) };
317+
let client_error = if status.is_client_error() {
318+
Some(true)
319+
} else {
320+
Some(false)
321+
};
322+
323+
let server_error = if status.is_server_error() {
324+
Some(true)
325+
} else {
326+
Some(false)
327+
};
319328

320329
DefaultResponseMetrics {
321-
http_status_code: Some(status_code),
322-
error,
323-
fault,
330+
http_status_code: Some(status.as_str().into()),
331+
success,
332+
client_error,
333+
server_error,
324334
operation_time,
325335
}
326336
}
@@ -361,8 +371,13 @@ fn configure_default_response_metrics(
361371
http_status_code: metrics
362372
.http_status_code
363373
.filter(|_| !config.disable_http_status_code),
364-
error: metrics.error.filter(|_| !config.disable_error),
365-
fault: metrics.fault.filter(|_| !config.disable_fault),
374+
success: metrics.success.filter(|_| !config.disable_success),
375+
client_error: metrics
376+
.client_error
377+
.filter(|_| !config.disable_client_error),
378+
server_error: metrics
379+
.server_error
380+
.filter(|_| !config.disable_server_error),
366381
operation_time: metrics
367382
.operation_time
368383
.filter(|_| !config.disable_operation_time),

0 commit comments

Comments
 (0)