Skip to content

Commit a3f7a39

Browse files
authored
chore(metrics): Remove the Arc (#2357)
1 parent bd4fe1a commit a3f7a39

File tree

6 files changed

+51
-163
lines changed

6 files changed

+51
-163
lines changed

lib/runtime/examples/Cargo.lock

Lines changed: 23 additions & 110 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/runtime/examples/system_metrics/Cargo.toml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
3-
#
4-
# Licensed under the Apache License, Version 2.0 (the "License");
5-
# you may not use this file except in compliance with the License.
6-
# You may obtain a copy of the License at
7-
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
10-
# Unless required by applicable law or agreed to in writing, software
11-
# distributed under the License is distributed on an "AS IS" BASIS,
12-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
# See the License for the specific language governing permissions and
14-
# limitations under the License.
153

164
[package]
175
name = "system_metrics"
@@ -27,6 +15,7 @@ default = []
2715
integration = [] # Integration tests that require NATS
2816

2917
[dependencies]
18+
anyhow = "*"
3019
dynamo-runtime = { workspace = true }
3120

3221
# third-party

lib/runtime/examples/system_metrics/src/lib.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
//
4-
// Licensed under the Apache License, Version 2.0 (the "License");
5-
// you may not use this file except in compliance with the License.
6-
// You may obtain a copy of the License at
7-
//
8-
// http://www.apache.org/licenses/LICENSE-2.0
9-
//
10-
// Unless required by applicable law or agreed to in writing, software
11-
// distributed under the License is distributed on an "AS IS" BASIS,
12-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
// See the License for the specific language governing permissions and
14-
// limitations under the License.
153

164
use dynamo_runtime::{
175
metrics::MetricsRegistry,
@@ -39,13 +27,11 @@ pub struct MyStats {
3927
/// Custom metrics for system stats with data bytes tracking
4028
#[derive(Clone, Debug)]
4129
pub struct MySystemStatsMetrics {
42-
pub data_bytes_processed: Arc<IntCounter>,
30+
pub data_bytes_processed: IntCounter,
4331
}
4432

4533
impl MySystemStatsMetrics {
46-
pub fn from_endpoint(
47-
endpoint: &dynamo_runtime::component::Endpoint,
48-
) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
34+
pub fn from_endpoint(endpoint: &dynamo_runtime::component::Endpoint) -> anyhow::Result<Self> {
4935
let data_bytes_processed = endpoint.create_intcounter(
5036
"my_custom_bytes_processed_total",
5137
"Example of a custom metric. Total number of data bytes processed by system handler",
@@ -60,7 +46,7 @@ impl MySystemStatsMetrics {
6046

6147
#[derive(Clone)]
6248
pub struct RequestHandler {
63-
metrics: Option<Arc<MySystemStatsMetrics>>,
49+
metrics: Option<MySystemStatsMetrics>,
6450
}
6551

6652
impl RequestHandler {
@@ -70,7 +56,7 @@ impl RequestHandler {
7056

7157
pub fn with_metrics(metrics: MySystemStatsMetrics) -> Arc<Self> {
7258
Arc::new(Self {
73-
metrics: Some(Arc::new(metrics)),
59+
metrics: Some(metrics),
7460
})
7561
}
7662
}

0 commit comments

Comments
 (0)