Skip to content

Commit

Permalink
Merge pull request #40 from Overmuse/SR/remove_reporting
Browse files Browse the repository at this point in the history
factor out reporting layer
  • Loading branch information
SebRollen authored Jul 16, 2021
2 parents 955e203 + 41d92c9 commit bd497aa
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 112 deletions.
25 changes: 1 addition & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "order-manager"
version = "6.1.7"
version = "7.0.0"
authors = ["Sebastian Rollen <seb@overmu.se>"]
edition = "2018"

Expand All @@ -14,9 +14,7 @@ config = "0.10.1"
dotenv = "0.15.0"
futures = "0.3.15"
kafka-settings = {git = "ssh://git@github.com/Overmuse/kafka-settings.git", tag = "v0.3.1" }
lazy_static = "1.4.0"
num-traits = "0.2.14"
prometheus = "0.12.0"
rdkafka = { version = "0.26.0", features = ["ssl-vendored"] }
refinery = { version = "0.5.0", features = ["tokio-postgres"] }
rust_decimal = { version = "1.14.1", features = ["tokio-pg"] }
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use tracing::error;
mod db;
mod intent_scheduler;
pub mod manager;
mod metrics;
mod order_sender;
mod settings;
pub mod types;
Expand Down
14 changes: 1 addition & 13 deletions src/manager/order_updates.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::OrderManager;
use crate::db;
use crate::metrics::{GROSS_TRADE_AMOUNT, NET_INVESTMENT_AMOUNT, NUM_TRADES};
use crate::types::{split_lot, Allocation, Lot, Owner};
use crate::types::{split_lot, Allocation, Lot};
use alpaca::{Event, OrderEvent, Side};
use anyhow::{anyhow, Context, Result};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -33,10 +32,6 @@ impl OrderManager {
price, timestamp, ..
} => {
debug!("Order filled");
NUM_TRADES.with_label_values(&[&ticker]).inc();
GROSS_TRADE_AMOUNT
.with_label_values(&[&ticker])
.inc_by((qty * price).abs().to_f64().unwrap());
let new_lot = self
.make_lot(&id, ticker, timestamp, price, qty)
.await
Expand Down Expand Up @@ -141,13 +136,6 @@ impl OrderManager {
.context("Failed to get claim")?;
let allocations = split_lot(&claims, &lot);
for allocation in allocations {
let owner = match allocation.owner {
Owner::House => "house",
Owner::Strategy(ref strat, _) => &strat,
};
NET_INVESTMENT_AMOUNT
.with_label_values(&[owner, &allocation.ticker])
.add(allocation.basis.to_f64().unwrap_or(0.0));
self.adjust_claim(&allocation)
.await
.context("Failed to adjust claim")?;
Expand Down
31 changes: 0 additions & 31 deletions src/metrics.rs

This file was deleted.

41 changes: 1 addition & 40 deletions src/webserver.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::db;
use crate::metrics::{register_custom_metrics, REGISTRY};
use crate::types::Owner;
use std::convert::Infallible;
use std::net::{Ipv4Addr, SocketAddrV4};
use std::sync::Arc;
use tokio_postgres::Client;
use tracing::warn;
use uuid::Uuid;
use warp::reply::{json, Reply};
use warp::{any, body, get, path, put, reject, serve, Filter, Rejection};
Expand Down Expand Up @@ -48,43 +46,8 @@ async fn get_pending_orders(db: Db) -> Result<impl Reply, Rejection> {
Ok(json(&pending_orders))
}

async fn metrics_handler() -> Result<impl Reply, Rejection> {
use prometheus::Encoder;
let encoder = prometheus::TextEncoder::new();

let mut buffer = Vec::new();
if let Err(e) = encoder.encode(&REGISTRY.gather(), &mut buffer) {
warn!("could not encode custom metrics: {}", e);
};
let mut res = match String::from_utf8(buffer.clone()) {
Ok(v) => v,
Err(e) => {
warn!("custom metrics could not be from_utf8'd: {}", e);
String::default()
}
};
buffer.clear();

let mut buffer = Vec::new();
if let Err(e) = encoder.encode(&prometheus::gather(), &mut buffer) {
warn!("could not encode prometheus metrics: {}", e);
};
let res_custom = match String::from_utf8(buffer.clone()) {
Ok(v) => v,
Err(e) => {
warn!("prometheus metrics could not be from_utf8'd: {}", e);
String::default()
}
};
buffer.clear();

res.push_str(&res_custom);
Ok(res)
}

#[tracing::instrument(skip(db))]
pub async fn run(port: u16, db: Db) {
register_custom_metrics();
let health = path!("health").map(|| "");
let get_allocations = path("allocations")
.and(get())
Expand All @@ -107,15 +70,13 @@ pub async fn run(port: u16, db: Db) {
.and(get())
.and(with_db(db.clone()))
.and_then(get_pending_orders);
let metrics = path("metrics").and_then(metrics_handler);
let routes = get()
.and(health)
.or(get_allocations)
.or(set_allocation_owner)
.or(lots)
.or(claims)
.or(pending_orders)
.or(metrics);
.or(pending_orders);
let address = SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), port);
serve(routes).run(address).await
}

0 comments on commit bd497aa

Please sign in to comment.