-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TEL - Create Latency Node #127
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "latency.hpp" | ||
|
||
#include <core/wall_clock.hpp> | ||
|
||
namespace hyped::telemetry { | ||
|
||
Latency::Latency(std::shared_ptr<core::IMqtt> mqtt) | ||
{ | ||
mqtt_->subscribe(core::MqttTopic::kStateRequest); | ||
} | ||
|
||
void Latency::respond() | ||
{ | ||
const auto nextMessage = mqtt_->getMessage(); | ||
if (!nextMessage) { return; } | ||
|
||
const auto payload = nextMessage->payload; | ||
const auto topic = core::MqttTopic::kLatencyResponse; | ||
const core::MqttMessage::Header header{.timestamp = 0, | ||
.priority = core::MqttMessagePriority::kNormal}; | ||
const core::MqttMessage message{topic, header, payload}; | ||
mqtt_->publish(message, core::MqttMessageQos::kAtLeastOnce); | ||
} | ||
|
||
void Latency::run() | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
mqtt_->consume(); | ||
respond(); | ||
} | ||
|
||
core::Result Latency::startNode(const std::string &mqtt_ip, const std::uint32_t mqtt_port) | ||
{ | ||
core::WallClock wall_clock; | ||
core::Logger logger("LATENCY", core::LogLevel::kDebug, wall_clock); | ||
auto optional_mqtt = core::Mqtt::create(logger, "latency", mqtt_ip, mqtt_port); | ||
if (!optional_mqtt) { | ||
logger.log(core::LogLevel::kFatal, "Failed to create MQTT client"); | ||
return core::Result::kFailure; | ||
} | ||
auto mqtt = *optional_mqtt; | ||
Latency latency(mqtt); | ||
latency.run(); | ||
return core::Result::kSuccess; | ||
} | ||
|
||
} // namespace hyped::telemetry |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <core/mqtt.hpp> | ||
#include <core/types.hpp> | ||
|
||
namespace hyped::telemetry { | ||
|
||
class Latency { | ||
public: | ||
Latency(std::shared_ptr<core::IMqtt> mqtt); | ||
void respond(); | ||
void run(); | ||
static core::Result startNode(const std::string &mqtt_ip, const std::uint32_t mqtt_port); | ||
|
||
const std::shared_ptr<core::IMqtt> mqtt_; | ||
}; | ||
|
||
} // namespace hyped::telemetry |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,7 @@ export const PodsProvider = ({ children }: { children: React.ReactNode }) => { | |
publish( | ||
'latency/request', | ||
JSON.stringify({ | ||
latency: new Date().getTime().toString(), | ||
timestamp: new Date().getTime().toString(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here and elsewhere, are you remembering that all mqtt messages are of the format: {
header : {
timestamp: int,
priority: int
},
payload: { rest of data }
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh I see. Will need to change this throughout the telemetry code |
||
}), | ||
podId, | ||
); | ||
|
@@ -233,7 +233,7 @@ export const PodsProvider = ({ children }: { children: React.ReactNode }) => { | |
// calculate the latency | ||
const latency = | ||
new Date().getTime() - | ||
parseInt(JSON.parse(message.toString())['latency'] as string); | ||
parseInt(JSON.parse(message.toString())['timestamp'] as string); | ||
|
||
// send warning to the server if the latency is too high | ||
if (latency > POD_WARNING_LATENCY) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need a
WallClock
as a data member, then:.timestamp = time_.now().time_since_epoch().count()