|
| 1 | +use lazy_static::lazy_static; |
| 2 | +use opentelemetry::AttributeSet; |
| 3 | +use opentelemetry::{ |
| 4 | + metrics::{Counter, MeterProvider as _}, |
| 5 | + KeyValue, |
| 6 | +}; |
| 7 | +use opentelemetry_sdk::metrics::{ManualReader, SdkMeterProvider}; |
| 8 | +use rand::{rngs::SmallRng, Rng, SeedableRng}; |
| 9 | +use std::borrow::Cow; |
| 10 | + |
| 11 | +mod throughput; |
| 12 | + |
| 13 | +lazy_static! { |
| 14 | + static ref PROVIDER: SdkMeterProvider = SdkMeterProvider::builder() |
| 15 | + .with_reader(ManualReader::builder().build()) |
| 16 | + .build(); |
| 17 | + static ref ATTRIBUTE_VALUES: [&'static str; 10] = [ |
| 18 | + "value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", |
| 19 | + "value10" |
| 20 | + ]; |
| 21 | + static ref COUNTER: Counter<u64> = PROVIDER |
| 22 | + .meter(<&str as Into<Cow<'static, str>>>::into("test")) |
| 23 | + .u64_counter("hello") |
| 24 | + .init(); |
| 25 | + static ref ATTRIBUTE_SETS: Vec<AttributeSet> = { |
| 26 | + let mut vec = Vec::new(); |
| 27 | + for i0 in 0..ATTRIBUTE_VALUES.len() { |
| 28 | + for i1 in 0..ATTRIBUTE_VALUES.len() { |
| 29 | + for i2 in 0..ATTRIBUTE_VALUES.len() { |
| 30 | + vec.push(AttributeSet::from(&[ |
| 31 | + KeyValue::new("attribute1", ATTRIBUTE_VALUES[i0]), |
| 32 | + KeyValue::new("attribute2", ATTRIBUTE_VALUES[i1]), |
| 33 | + KeyValue::new("attribute3", ATTRIBUTE_VALUES[i2]), |
| 34 | + ])) |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + vec |
| 40 | + }; |
| 41 | +} |
| 42 | + |
| 43 | +fn main() { |
| 44 | + throughput::test_throughput(test_counter); |
| 45 | +} |
| 46 | + |
| 47 | +fn test_counter() { |
| 48 | + let mut rng = SmallRng::from_entropy(); |
| 49 | + let len = ATTRIBUTE_SETS.len(); |
| 50 | + let index = rng.gen_range(0..len); |
| 51 | + |
| 52 | + COUNTER.add(1, ATTRIBUTE_SETS[index].clone()); |
| 53 | +} |
0 commit comments