Market data rate metrics reborn
This commit is contained in:
1 parent
af7e9dd3a8
commit
053c460ff6
4 files changed
+25
-14
No files matched your search
@@ -62,13 +62,27 @@ struct DatedHandle {
|
||||
|
||||
struct MDConsumerGroup {
|
||||
// probably just have to send the consumer in from outside
|
||||
MDConsumerGroup(const UserSymbol& symbol, const MDConsumer& consumer) :
|
||||
MDConsumerGroup(const UserSymbol& symbol, const MDConsumer& consumer, metrics::MetricsContainer& stats) :
|
||||
symbol(symbol),
|
||||
platform(platform_for_exchange(symbol.exchange())),
|
||||
channel(consumer.get_channel(symbol)),
|
||||
handles()
|
||||
{
|
||||
set_consumer(consumer);
|
||||
|
||||
// create and publish a stat for this group
|
||||
if (symbol.type() != SecurityType::SECURITYTYPE_SYNTHETIC) {
|
||||
std::vector<metrics::Label> labels;
|
||||
labels.push_back({ "symbol", symbol.symbol() });
|
||||
labels.push_back({ "type", SecurityType_Name(symbol.type()).substr(13) /*SECURITYTYPE_*/ });
|
||||
labels.push_back({ "exch", Venue_Name(symbol.exchange()).substr(6) /*VENUE_*/ });
|
||||
stats.publish(
|
||||
std::make_shared<metrics::LazyCounterMetric>("spark_md_book_updates", [=]() { return std::max(channel.bbo_count(), channel.depth_count()); }, labels));
|
||||
stats.publish(
|
||||
std::make_shared<metrics::LazyCounterMetric>("spark_md_security_count", [=]() { return channel.security_count(); }, labels));
|
||||
stats.publish(
|
||||
std::make_shared<metrics::LazyCounterMetric>("spark_md_trade_count", [=]() { return channel.trade_count(); }, labels));
|
||||
}
|
||||
}
|
||||
MDConsumerGroup(const MDConsumerGroup& other) = delete;
|
||||
|
||||
@@ -136,21 +150,18 @@ class QueryServerImpl : public IQueryServer {
|
||||
boost::container::flat_map<UserSymbol,shared_ptr<MDConsumerGroup>> _groups;
|
||||
|
||||
public:
|
||||
QueryServerImpl(const std::set<UserSymbol>& symbols, std::shared_ptr<api::ISyntheticSecurityService>& ss) :
|
||||
QueryServerImpl(const std::set<UserSymbol>& symbols, std::shared_ptr<api::ISyntheticSecurityService>& ss, metrics::MetricsContainer& stats) :
|
||||
_consumer(symbols, ss),
|
||||
_symbols(symbols),
|
||||
_ss(ss),
|
||||
_groups()
|
||||
{
|
||||
for (const auto& sym : symbols) {
|
||||
_groups.emplace(std::make_pair(sym, std::make_unique<MDConsumerGroup>(sym, _consumer)));
|
||||
_groups.emplace(std::make_pair(sym, std::make_unique<MDConsumerGroup>(sym, _consumer, stats)));
|
||||
}
|
||||
_groups.shrink_to_fit();
|
||||
|
||||
subscribe_securities();
|
||||
|
||||
// each symbol = new lazy metric
|
||||
// getchannel()->
|
||||
}
|
||||
|
||||
void subscribe_securities() {
|
||||
@@ -396,7 +407,7 @@ struct QueryServer {
|
||||
const bts::api::ServiceContext& ctx,
|
||||
std::shared_ptr<api::ISyntheticSecurityService>& ss,
|
||||
metrics::MetricsContainer& stats):
|
||||
db(symbols, ss),
|
||||
db(symbols, ss, stats),
|
||||
relay(db, threadpool, ctx, stats),
|
||||
security_timer(),
|
||||
health_timer()
|
||||
@@ -440,8 +451,8 @@ QueryServerPtr run_query_server(const bts::api::ServiceContext& ctx, std::shared
|
||||
return container;
|
||||
}
|
||||
|
||||
std::unique_ptr<IQueryServer> create_query_server(const std::set<UserSymbol>& symbols, std::shared_ptr<api::ISyntheticSecurityService>& ss) {
|
||||
return std::make_unique<QueryServerImpl>(symbols, ss);
|
||||
std::unique_ptr<IQueryServer> create_query_server(const std::set<UserSymbol>& symbols, std::shared_ptr<api::ISyntheticSecurityService>& ss, metrics::MetricsContainer& stats) {
|
||||
return std::make_unique<QueryServerImpl>(symbols, ss, stats);
|
||||
}
|
||||
|
||||
}}//namespace
|
||||
|
||||
@@ -19,11 +19,11 @@ struct IQueryServer {
|
||||
virtual void scan_securities() = 0;
|
||||
virtual void query(const co2::MDRequest& request, co2::MDReply* reply) const = 0;
|
||||
};
|
||||
std::unique_ptr<IQueryServer> create_query_server(const std::set<UserSymbol>&, std::shared_ptr<api::ISyntheticSecurityService>&);
|
||||
std::unique_ptr<IQueryServer> create_query_server(const std::set<UserSymbol>&, std::shared_ptr<api::ISyntheticSecurityService>&, metrics::MetricsContainer&);
|
||||
|
||||
struct QueryServer;
|
||||
typedef std::shared_ptr<QueryServer> QueryServerPtr;
|
||||
QueryServerPtr run_query_server(const bts::api::ServiceContext&, std::shared_ptr<api::ISyntheticSecurityService>&, metrics::MetricsContainer& stats);
|
||||
QueryServerPtr run_query_server(const bts::api::ServiceContext&, std::shared_ptr<api::ISyntheticSecurityService>&, metrics::MetricsContainer&);
|
||||
|
||||
}}//namespace
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "lib/utils/defer.h"
|
||||
#include "lib/utils/warn_ctrl.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
#include "server/sparkd/metrics/metrics.h"
|
||||
|
||||
#include "lib/config/protos/MarketData.pb.h"
|
||||
|
||||
@@ -1275,7 +1276,8 @@ struct Co2RelayTests {
|
||||
set<UserSymbol> symbols;
|
||||
symbols.insert(symbol);
|
||||
shared_ptr<api::ISyntheticSecurityService> empty;
|
||||
auto server = create_query_server(symbols, empty);
|
||||
metrics::MetricsContainer stats;
|
||||
auto server = create_query_server(symbols, empty, stats);
|
||||
REQUIRE(server);
|
||||
server->scan_securities();
|
||||
|
||||
|
||||
@@ -123,8 +123,6 @@ class HistogramMetric : public Metric {
|
||||
}
|
||||
void observe(double v) {
|
||||
for (size_t x = 0; x < N; ++x) {
|
||||
// >= makes more sense to me but this is what the promethius docs say
|
||||
//
|
||||
if (v <= _bucket_values[x]) {
|
||||
_buckets[x].increment();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user