Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support text format #12

Merged
merged 17 commits into from
Aug 23, 2016
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ examples:
cargo build --example example_hyper
cp target/debug/examples/* bin/

.PHONY: all
.PHONY: all examples
2 changes: 1 addition & 1 deletion examples/example_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() {
thread::spawn(move || {
for _ in 0..10 {
thread::sleep(Duration::from_millis(500));
c2.inc_by(3.14159265358979323846264338327).unwrap();
c2.inc();
}
});

Expand Down
2 changes: 1 addition & 1 deletion examples/example_hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() {
thread::spawn(move || {
loop {
thread::sleep(Duration::from_millis(300));
c2.inc_by(3.14159265358979323846264338327).unwrap();
c2.inc();
}
});

Expand Down
30 changes: 16 additions & 14 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::sync::{Arc, RwLock};
use std::collections::HashMap;
use std::collections::hash_map::Entry::Vacant;
use std::collections::hash_map::Entry;

use proto;
use metrics::Collector;
Expand Down Expand Up @@ -69,20 +69,23 @@ impl RegistryCore {
let mut mf_by_name = HashMap::new();

for c in self.colloctors_by_id.values() {
let mf = c.collect();
let mut mf = c.collect();
let name = mf.get_name().to_owned();
if let Vacant(entry) = mf_by_name.entry(name.clone()) {
entry.insert(mf);
continue;
}

let mut existent_mf = mf_by_name.get_mut(&name).unwrap();
let mut existent_metrics = existent_mf.mut_metric();

// TODO: check type.
// TODO: check consistency.
for metric in mf.get_metric() {
existent_metrics.push(metric.clone())
match mf_by_name.entry(name) {
Entry::Vacant(entry) => {
entry.insert(mf);
}
Entry::Occupied(mut entry) => {
let mut existent_mf = entry.get_mut();
let mut existent_metrics = existent_mf.mut_metric();

// TODO: check type.
// TODO: check consistency.
for metric in mf.take_metric().into_iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use extend instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existent_metrics is a protobuf::RepeatedField, unfortunately it does not support extend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

existent_metrics.push(metric);
}
}
}
}

Expand Down Expand Up @@ -126,7 +129,6 @@ impl Registry {
}
}


#[cfg(test)]
mod tests {
use std::thread;
Expand Down