Skip to content

Commit bb09c45

Browse files
committed
Simplify cache metrics and switch proto to master branch
Remove manual AtomicUsize cache size tracking in favor of gauge increment/set. Drop cache_cleaned_total metric, unused parking_lot dep, and tokio full feature. Switch helium-proto to master and CI to cargo test.
1 parent 0e4565e commit bb09c45

File tree

7 files changed

+11
-49
lines changed

7 files changed

+11
-49
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ jobs:
112112
key: tests-base-${{ needs.compute-base-build-tag.outputs.image_tag }}-${{ hashFiles('**/Cargo.lock') }}
113113
restore-keys: |
114114
tests-base-${{ needs.compute-base-build-tag.outputs.image_tag }}-
115-
- name: Install nextest
116-
run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
117115
- name: Run tests
118-
run: cargo nextest run
116+
run: cargo test
119117

120118
build-package:
121119
if: startsWith(github.ref, 'refs/tags/')

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ humantime-serde = "1.1"
1313
metrics = "0.24"
1414
metrics-exporter-prometheus = "0.18"
1515
serde = { version = "1.0", features = ["derive"] }
16-
tokio = { version = "1.50", features = ["full"] }
16+
tokio = { version = "1.50" }
1717
tonic = "0.14"
1818
tracing = "0.1"
1919
triggered = "0.1"
2020

2121
# Oracles
2222
custom-tracing = { git = "https://github.com/helium/oracles.git", branch = "main" }
23-
helium-proto = { git = "https://github.com/helium/proto.git", branch = "macpie/multibuy2.0", features = [
23+
helium-proto = { git = "https://github.com/helium/proto.git", branch = "master", features = [
2424
"services",
2525
] }
2626
task-manager = { git = "https://github.com/helium/oracles", branch = "main" }

src/cache.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use dashmap::mapref::entry::Entry;
22
use dashmap::DashMap;
3-
use std::sync::atomic::{AtomicUsize, Ordering};
43
use std::time::Instant;
54

65
#[derive(Debug, Clone)]
@@ -9,33 +8,18 @@ pub(crate) struct CacheValue {
98
pub(crate) created_at: Instant,
109
}
1110

11+
#[derive(Default)]
1212
pub struct Cache {
1313
map: DashMap<String, CacheValue>,
14-
pub size: AtomicUsize,
15-
}
16-
17-
impl Default for Cache {
18-
fn default() -> Self {
19-
Self::new()
20-
}
2114
}
2215

2316
impl Cache {
2417
pub fn new() -> Self {
2518
Self {
2619
map: DashMap::new(),
27-
size: AtomicUsize::new(0),
2820
}
2921
}
3022

31-
pub fn len(&self) -> usize {
32-
self.size.load(Ordering::Relaxed)
33-
}
34-
35-
pub fn is_empty(&self) -> bool {
36-
self.len() == 0
37-
}
38-
3923
pub fn inc(&self, key: String) -> u32 {
4024
match self.map.entry(key) {
4125
Entry::Occupied(mut entry) => {
@@ -48,8 +32,7 @@ impl Cache {
4832
count: 1,
4933
created_at: Instant::now(),
5034
});
51-
self.size.fetch_add(1, Ordering::Relaxed);
52-
crate::metrics::set_cache_size(self.len() as f64);
35+
crate::metrics::inc_cache_size();
5336
1
5437
}
5538
}
@@ -60,7 +43,7 @@ impl Cache {
6043
self.map.retain(|_, v| v.created_at.elapsed() < max_age);
6144
let after = self.map.len();
6245
let removed = before - after;
63-
self.size.store(after, Ordering::Relaxed);
46+
crate::metrics::set_cache_size(after as f64);
6447
removed
6548
}
6649
}

src/metrics/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub mod settings;
66

77
const HIT_TOTAL: &str = "multi_buy_hit_total";
88
const CACHE_SIZE: &str = "multi_buy_cache_size";
9-
const CACHE_CLEANED_TOTAL: &str = "multi_buy_cache_cleaned_total";
109
const REQUEST_DURATION: &str = "multi_buy_request_duration_ms";
1110

1211
pub fn start_metrics(settings: &Settings) -> anyhow::Result<()> {
@@ -32,8 +31,8 @@ pub fn set_cache_size(size: f64) {
3231
metrics::gauge!(CACHE_SIZE).set(size);
3332
}
3433

35-
pub fn increment_cache_cleaned(count: u64) {
36-
metrics::counter!(CACHE_CLEANED_TOTAL).increment(count);
34+
pub fn inc_cache_size() {
35+
metrics::gauge!(CACHE_SIZE).increment(1);
3736
}
3837

3938
pub fn record_request_duration(duration: std::time::Duration) {

src/tasks/cleanup.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ impl CacheCleanup {
4040
},
4141
_ = &mut batch_timer => {
4242
let removed = self.cache.remove_expired(self.cleanup_timeout);
43-
crate::metrics::set_cache_size(self.cache.len() as f64);
44-
crate::metrics::increment_cache_cleaned(removed as u64);
4543
tracing::info!("cleaned {} entries", removed);
4644

4745
batch_timer.as_mut().reset(tokio::time::Instant::now() + self.cleanup_timeout);

tests/integrations/common/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ pub async fn start_server(settings: &Settings, addr: SocketAddr) -> triggered::T
4949
.unwrap();
5050
});
5151

52-
// Give the server a moment to start
53-
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
54-
5552
trigger
5653
}
5754

@@ -86,8 +83,6 @@ pub async fn start_server_with_cleanup(
8683
cleanup.run_until(shutdown_clone).await.unwrap();
8784
});
8885

89-
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
90-
9186
trigger
9287
}
9388

0 commit comments

Comments
 (0)