Add username to shell latency metric and have it go to nan when shell is not connected

This commit is contained in:
Eric Harding committed 2018-07-25 13:20:24 -04:00
1 parent 4d0a9ab56e
commit 8fe151bdb9
4 files changed
+15 -6

No files matched your search

@@ -16,12 +16,14 @@ namespace bts.perf {
readonly ShellLatencyService _service;
readonly string _hostname;
readonly string _version;
readonly string _username;
IDisposable _subs;
[ImportingConstructor]
public ShellLatencyDaemon(ShellLatencyService service) {
public ShellLatencyDaemon(ShellLatencyService service, [Import("username")] string user) {
_service = service;
_version = Configuration.get<bts.config.System>().version;
_username = user;
_hostname = Environment.MachineName;
_subs = _service.subscribei_clock().Subscribe(on_tick);
}
@@ -32,6 +34,7 @@ namespace bts.perf {
_service.report_async(new Report() {
HostName = _hostname,
Version = _version,
User = _username,
Timestamp = tick.Timestamp
});
}
@@ -12,6 +12,7 @@ message Tick {
message Report {
string host_name = 1;
string version = 2;
string user = 3;
uint64 timestamp = 10;
}
+4 -2
View File
@@ -69,8 +69,10 @@ class AutoResetMetric : public AtomicCounterMetric<int64_t> {
AutoResetMetric(const std::string& name, const std::vector<Label>& labels) : AtomicCounterMetric(name, labels) {}
~AutoResetMetric(){}
void print(std::ostream& out) const override {
out << name << labels << " " << _val << std::endl;
const_cast<AutoResetMetric*>(this)->set(0);
if (_val > 0) {
out << name << labels << " " << _val << std::endl;
const_cast<AutoResetMetric*>(this)->set(0);
}
}
void max(int64_t val) {
_val = std::max(val, _val.load());
@@ -8,7 +8,7 @@ ShellLatencyServer::ShellLatencyServer(bts::api::ServiceContext& ctx, metrics::M
ShellLatencyServiceBase(ctx),
_counter(0),
_pub(make_clock_stateful_publisher()),
_timer(utils::DispatcherTimer(d, 2500, [=]() { tick(); })),
_timer(utils::DispatcherTimer(d, 1000, [=]() { tick(); })),
_mc(mc),
_metrics()
{
@@ -39,10 +39,13 @@ void ShellLatencyServer::report(
auto key = request.host_name() + "-" + request.version();
auto iter = _metrics.find(key);
std::shared_ptr<AutoResetMetric> metric;
auto delta = (utils::TimeStamp::now() - utils::TimeStamp(request.timestamp())).milliseconds();
// report at least 1ms because the metric will not report anything if it's 0
auto delta = std::max(1l, (utils::TimeStamp::now() - utils::TimeStamp(request.timestamp())).milliseconds());
if (iter == _metrics.end()) {
// create metric
auto metric = std::make_shared<AutoResetMetric>("spark_shell_latency", std::vector<Label>({{"shell",key}}));
auto metric =
std::make_shared<AutoResetMetric>("spark_shell_latency",
std::vector<Label>({{"shell",key}, {"user", request.user()}}));
_metrics.insert(std::make_pair(key, metric));
metric->max(delta);
_mc.publish(metric);