Skeptic fix

This commit is contained in:
Francis Lalonde 2018-10-18 10:10:23 -04:00
parent 0b61c01550
commit 851463b193
14 changed files with 31 additions and 50 deletions

View File

@ -15,7 +15,7 @@ CARGO_BUILD_FLAGS ?=
# 'test' is a friendly alias for 'unit_test'
test:
$(CARGO_CMD) test
$(CARGO_CMD) test --features="skeptic"
examples:
$(CARGO_CMD) build --examples

View File

@ -44,7 +44,7 @@ Here's a basic aggregating & auto-publish counter metric:
```$rust,skt-run
let bucket = Bucket::new();
bucket.set_target(Text::output(io::stdout()));
bucket.set_target(Stream::stdout());
bucket.flush_every(Duration::from_secs(3));
let counter = bucket.counter("counter_a");
counter.count(8)
@ -53,12 +53,13 @@ counter.count(8)
Persistent apps wanting to declare static metrics will prefer using the `metrics!` macro:
```$rust,skt-run
metrics! { METRICS = "my_app" =>
pub COUNTER: Counter = "my_counter";
metrics! { METRICS = "my_app" => {
pub COUNTER: Counter = "my_counter";
}
}
fn main() {
METRICS.set_target(Graphite::output("graphite.com:2003").unwrap());
METRICS.set_target(Graphite::send_to("graphite.com:2003").unwrap().input());
COUNTER.count(32);
}
```

View File

@ -3,8 +3,10 @@ Templates
Use `cargo test --features="skeptic"` to run the examples in the README using the `skeptic` crate.
```rust,skt-run
#[macro_use]
extern crate dipstick;
use dipstick::*;
use std::time::Duration;
fn main() {{
{}
@ -14,8 +16,8 @@ fn main() {{
```rust,skt-fail
extern crate dipstick;
use dipstick::*;
use dipstick::error::Error;
use std::result::Result;
use std::time::Duration;
fn main() {{
run().ok();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -4,35 +4,35 @@ extern crate dipstick;
use std::thread::sleep;
use std::time::Duration;
use std::io;
use dipstick::{Proxy, Stream, InputScope, Input, Naming};
fn main() {
let root = Proxy::default();
let sub = root.add_naming("sub");
let root_proxy = Proxy::default();
let sub = root_proxy.add_naming("sub");
let count1 = root.counter("counter_a");
let count1 = root_proxy.counter("counter_a");
let count2 = sub.counter("counter_b");
loop {
root.set_target(Stream::write_to(io::stdout()).input());
let stdout = Stream::stdout().input();
root_proxy.set_target(stdout.clone());
count1.count(1);
count2.count(2);
// route every metric from the root to stdout with prefix "root"
root.set_target(Stream::write_to(io::stdout()).add_naming("root").input());
root_proxy.set_target(stdout.add_naming("root"));
count1.count(3);
count2.count(4);
// route metrics from "sub" to stdout with prefix "mutant"
sub.set_target(Stream::write_to(io::stdout()).add_naming("mutant").input());
sub.set_target(stdout.add_naming("mutant"));
count1.count(5);
count2.count(6);
// clear root metrics route, "sub" still appears
root.unset_target();
root_proxy.unset_target();
count1.count(7);
count2.count(8);
@ -42,7 +42,7 @@ fn main() {
count2.count(10);
// go back to initial single un-prefixed route
root.set_target(Stream::write_to(io::stdout()).input());
root_proxy.set_target(stdout.clone());
count1.count(11);
count2.count(12);

View File

@ -1,23 +1,18 @@
//! A sample application asynchronously printing metrics to stdout.
#[macro_use]
extern crate dipstick;
use std::thread::sleep;
use std::time::Duration;
use dipstick::{Proxy, Stream, Counter, InputScope, Input, Formatting, AppLabel,
use dipstick::{Stream, InputScope, Input, Formatting, AppLabel,
Name, Kind, LineTemplate, LineFormat, LineOp, LabelOp};
metrics!{
COUNTER: Counter = "counter_a";
}
struct MyFormat;
impl LineFormat for MyFormat {
fn template(&self, name: &Name, _kind: Kind) -> LineTemplate {
vec![
LineOp::Literal(format!("{} ", name.join("."))),
LineOp::Literal(format!("{} ", name.join(".")).into()),
LineOp::ValueAsText,
LineOp::Literal(" ".into()),
LineOp::LabelExists("abc".into(),
@ -29,11 +24,11 @@ impl LineFormat for MyFormat {
}
fn main() {
Proxy::set_default_target(Stream::stderr().formatting(MyFormat).input());
let counter = Stream::stderr().formatting(MyFormat).input().counter("counter_a");
AppLabel::set("abc", "xyz");
loop {
// report some metric values from our "application" loop
COUNTER.count(11);
counter.count(11);
sleep(Duration::from_millis(500));
}

View File

@ -191,8 +191,8 @@ pub mod test {
#[test]
fn context_labels() {
AppLabel::set("abc".into(), "456".into());
ThreadLabel::set("abc".into(), "123".into());
AppLabel::set("abc", "456");
ThreadLabel::set("abc", "123");
assert_eq!(Arc::new("123".into()), labels!().lookup("abc").unwrap());
ThreadLabel::unset("abc");
assert_eq!(Arc::new("456".into()), labels!().lookup("abc").unwrap());
@ -213,8 +213,8 @@ pub mod test {
#[test]
fn value_labels() {
AppLabel::set("abc".into(), "456".into());
ThreadLabel::set("abc".into(), "123".into());
AppLabel::set("abc", "456");
ThreadLabel::set("abc", "123");
let mut labels = labels!{
"abc" => "789",
};

View File

@ -164,7 +164,7 @@ mod test {
use core::proxy::Proxy;
metrics!{TEST: Proxy = "test_prefix" => {
M1: Marker = "failed";
pub M1: Marker = "failed";
C1: Counter = "failed";
G1: Gauge = "failed";
T1: Timer = "failed";

View File

@ -9,7 +9,7 @@ use std::sync::Arc;
/// Print commands are steps in the execution of output templates.
pub enum LineOp {
/// Print a string.
Literal(String),
Literal(Vec<u8>),
/// Lookup and print label value for key, if it exists.
LabelExists(String, Vec<LabelOp>),
/// Print metric value as text.
@ -23,7 +23,7 @@ pub enum LineOp {
/// Print commands are steps in the execution of output templates.
pub enum LabelOp {
/// Print a string.
Literal(String),
Literal(Vec<u8>),
/// Print the label key.
LabelKey,
/// Print the label value.
@ -101,7 +101,7 @@ impl LineFormat for SimpleFormat {
header.push(' ');
LineTemplate {
ops: vec![
Literal(header),
Literal(header.into_bytes()),
ValueAsText,
NewLine,
]
@ -109,23 +109,6 @@ impl LineFormat for SimpleFormat {
}
}
//enum Parsed {
// Literal(String),
// Name()
// Value(Value),
// StaticLabel(String),
// DynamicLabel(String),
//}
//
//struct TemplateFormat {
// tokens: Vec<LineToken>
//}
//
//fn parse(template: &str) -> TemplateFormat {
//
//}
#[cfg(test)]
pub mod test {
use super::*;
@ -141,7 +124,7 @@ pub mod test {
header.push(' ');
LineTemplate {
ops: vec![
Literal(header),
Literal(header.into()),
ValueAsText,
Literal(" ".into()),
ScaledValueAsText(1000),