Browse Source

random cleanup - trying to keep warnings down

master
Jonathan Strong 7 years ago
parent
commit
60c7aa8421
3 changed files with 33 additions and 33 deletions
  1. +2
    -0
      justfile
  2. +4
    -7
      src/influx.rs
  3. +27
    -26
      src/warnings.rs

+ 2
- 0
justfile View File

@@ -0,0 +1,2 @@
bench NAME='':
RUSTFLAGS="-C target-cpu=native" cargo bench {{NAME}}

+ 4
- 7
src/influx.rs View File

@@ -225,9 +225,6 @@ pub fn serialize_owned(measurement: &OwnedMeasurement, line: &mut String) {
} }
} }





pub fn writer(warnings: Sender<Warning>) -> thread::JoinHandle<()> { pub fn writer(warnings: Sender<Warning>) -> thread::JoinHandle<()> {
thread::spawn(move || { thread::spawn(move || {
let _ = fs::create_dir("/tmp/mm"); let _ = fs::create_dir("/tmp/mm");
@@ -262,14 +259,14 @@ pub fn writer(warnings: Sender<Warning>) -> thread::JoinHandle<()> {


Ok(mut resp) => { Ok(mut resp) => {
resp.read_to_string(&mut server_resp); //.unwrap_or(0); resp.read_to_string(&mut server_resp); //.unwrap_or(0);
warnings.send(
let _ = warnings.send(
Warning::Error( Warning::Error(
format!("Influx server: {}", server_resp))); format!("Influx server: {}", server_resp)));
server_resp.clear(); server_resp.clear();
} }


Err(why) => { Err(why) => {
warnings.send(
let _ = warnings.send(
Warning::Error( Warning::Error(
format!("Influx write error: {}", why))); format!("Influx write error: {}", why)));
} }
@@ -292,7 +289,7 @@ pub enum OwnedValue {
Boolean(bool) Boolean(bool)
} }


#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct OwnedMeasurement { pub struct OwnedMeasurement {
pub key: &'static str, pub key: &'static str,
pub timestamp: Option<i64>, pub timestamp: Option<i64>,
@@ -482,7 +479,7 @@ impl InfluxWriter {


impl Drop for InfluxWriter { impl Drop for InfluxWriter {
fn drop(&mut self) { fn drop(&mut self) {
self.kill_switch.send(());
let _ = self.kill_switch.send(()).unwrap();
if let Some(thread) = self.thread.take() { if let Some(thread) = self.thread.take() {
let _ = thread.join(); let _ = thread.join();
} }


+ 27
- 26
src/warnings.rs View File

@@ -26,7 +26,7 @@ const N_WARNINGS: usize = 500;
macro_rules! confirmed { macro_rules! confirmed {
($warnings:ident, $($args:tt)*) => ( ($warnings:ident, $($args:tt)*) => (
{ {
$warnings.send(Warning::Confirmed( ( format!($($args)*) ) ) ).unwrap();
$let _ = warnings.send(Warning::Confirmed( ( format!($($args)*) ) ) ).unwrap();
} }
) )
} }
@@ -136,51 +136,52 @@ impl Warning {
} }
} }


pub fn category(&self, f: &mut Formatter) {
match self {
&Warning::Notice(_) => {
write!(f, "[ Notice ]");
pub fn category(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Warning::Notice(_) => {
write!(f, "[ Notice ]")
} }


&Warning::Error(_) => {
Warning::Error(_) => {
write!(f, "{yellow}[{title}]{reset}", write!(f, "{yellow}[{title}]{reset}",
yellow = Fg(color::LightYellow), yellow = Fg(color::LightYellow),
title = " Error--", title = " Error--",
reset = Fg(color::Reset));
reset = Fg(color::Reset))
} }
&Warning::Critical(_) => {

Warning::Critical(_) => {
write!(f, "{bg}{fg}{title}{resetbg}{resetfg}", write!(f, "{bg}{fg}{title}{resetbg}{resetfg}",
bg = Bg(color::Red), bg = Bg(color::Red),
fg = Fg(color::White), fg = Fg(color::White),
title = " CRITICAL ", title = " CRITICAL ",
resetbg = Bg(color::Reset), resetbg = Bg(color::Reset),
resetfg = Fg(color::Reset));
resetfg = Fg(color::Reset))
} }


&Warning::Awesome(_) => {
Warning::Awesome(_) => {
write!(f, "{color}[{title}]{reset}", write!(f, "{color}[{title}]{reset}",
color = Fg(color::Green), color = Fg(color::Green),
title = "Awesome!", title = "Awesome!",
reset = Fg(color::Reset));
reset = Fg(color::Reset))
} }


&Warning::DegradedService(_) => {
Warning::DegradedService(_) => {
write!(f, "{color}[{title}] {reset}", write!(f, "{color}[{title}] {reset}",
color = Fg(color::Blue), color = Fg(color::Blue),
title = "Degraded Service ", title = "Degraded Service ",
reset = Fg(color::Reset));
reset = Fg(color::Reset))
} }
&Warning::Confirmed(_) => {

Warning::Confirmed(_) => {
write!(f, "{bg}{fg}{title}{resetbg}{resetfg}", write!(f, "{bg}{fg}{title}{resetbg}{resetfg}",
bg = Bg(color::Blue), bg = Bg(color::Blue),
fg = Fg(color::White), fg = Fg(color::White),
title = "Confirmed ", title = "Confirmed ",
resetbg = Bg(color::Reset), resetbg = Bg(color::Reset),
resetfg = Fg(color::Reset));
resetfg = Fg(color::Reset))
} }



_ => {}
_ => Ok(())
} }
} }
} }
@@ -394,7 +395,7 @@ impl<D: Drain> Drain for WarningsDrain<D> {
record.kv().serialize(record, &mut ser); record.kv().serialize(record, &mut ser);
let msg = record.msg().to_string(); let msg = record.msg().to_string();
if let Ok(lock) = self.tx.lock() { if let Ok(lock) = self.tx.lock() {
lock.send(Warning::Log {
let _ = lock.send(Warning::Log {
level: record.level(), level: record.level(),
module: record.module(), module: record.module(),
function: record.function(), function: record.function(),
@@ -450,7 +451,7 @@ impl WarningsManager {
meas.add_field("msg", InfluentValue::String(msg.as_ref())); meas.add_field("msg", InfluentValue::String(msg.as_ref()));
meas.add_tag("category", level.as_short_str()); meas.add_tag("category", level.as_short_str());
influx::serialize(&meas, &mut buf); influx::serialize(&meas, &mut buf);
socket.send_str(&buf, 0);
let _ = socket.send_str(&buf, 0);
buf.clear(); buf.clear();
// and don't push to warnings // and don't push to warnings
// bc it's debug // bc it's debug
@@ -463,7 +464,7 @@ impl WarningsManager {
{ {
let m = rec.to_measurement(measurement_name); let m = rec.to_measurement(measurement_name);
influx::serialize(&m, &mut buf); influx::serialize(&m, &mut buf);
socket.send_str(&buf, 0);
let _ = socket.send_str(&buf, 0);
buf.clear(); buf.clear();
} }
if let Ok(mut lock) = warnings.write() { if let Ok(mut lock) = warnings.write() {
@@ -486,7 +487,7 @@ impl WarningsManager {


impl Drop for WarningsManager { impl Drop for WarningsManager {
fn drop(&mut self) { fn drop(&mut self) {
self.tx.send(Warning::Terminate);
let _ = self.tx.send(Warning::Terminate);
if let Some(thread) = self.thread.take() { if let Some(thread) = self.thread.take() {
thread.join(); thread.join();
} }
@@ -552,7 +553,7 @@ impl<D> Drain for ZmqDrain<D>
values.serialize(record, &mut kv_ser); values.serialize(record, &mut kv_ser);
} }


self.socket.send(&buf, 0);
let _ = self.socket.send(&buf, 0);
buf.clear(); buf.clear();
} }
self.drain.log(record, values) self.drain.log(record, values)
@@ -588,12 +589,12 @@ impl Write for ZmqIo {
fn flush(&mut self) -> io::Result<()> { fn flush(&mut self) -> io::Result<()> {
match self.buf.pop() { match self.buf.pop() {
Some(b'\n') => { Some(b'\n') => {
self.socket.send(&self.buf, 0);
let _ = self.socket.send(&self.buf, 0);
} }


Some(other) => { Some(other) => {
self.buf.push(other); self.buf.push(other);
self.socket.send(&self.buf, 0);
let _ = self.socket.send(&self.buf, 0);
} }


None => { None => {
@@ -759,9 +760,9 @@ mod tests {
let tx = Arc::new(Mutex::new(tx)); let tx = Arc::new(Mutex::new(tx));
b.iter(|| { b.iter(|| {
let lock = tx.lock().unwrap(); let lock = tx.lock().unwrap();
lock.send(Msg::Val(1));
let _ = lock.send(Msg::Val(1));
}); });
tx.lock().unwrap().send(Msg::Terminate);
let _ = tx.lock().unwrap().send(Msg::Terminate);
let len = worker.join().unwrap(); let len = worker.join().unwrap();
//println!("{}", len); //println!("{}", len);




Loading…
Cancel
Save