Skip to content
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

History request types #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion include/metricq/history_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,22 @@ class HistoryResponseAggregateView;
class HistoryClient : public Connection
{
public:
enum class Type
{
AGGREGATE_TIMELINE,
AGGREGATE,
LAST_VALUE,
FLEX_TIMELINE
};

HistoryClient(const std::string& token, bool add_uuid = true);

// We have to do this because of the ConnectionHandler forward declaration
~HistoryClient();

// shall NOT be used before on_history_ready() was called
std::string history_request(const std::string& id, TimePoint begin, TimePoint end,
Duration interval);
Duration interval, Type request_type = Type::FLEX_TIMELINE);

protected:
virtual void on_history_response(const std::string& id, const HistoryResponse& response);
Expand Down
20 changes: 16 additions & 4 deletions src/history_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@

using namespace std::placeholders;

static_assert(static_cast<int>(metricq::HistoryClient::Type::FLEX_TIMELINE) ==
metricq::HistoryRequest::FLEX_TIMELINE,
"Someone broke the protobuf ABI");
static_assert(static_cast<int>(metricq::HistoryClient::Type::AGGREGATE_TIMELINE) ==
metricq::HistoryRequest::AGGREGATE_TIMELINE,
"Someone broke the protobuf ABI");
static_assert(static_cast<int>(metricq::HistoryClient::Type::AGGREGATE) ==
metricq::HistoryRequest::AGGREGATE,
"Someone broke the protobuf ABI");
static_assert(static_cast<int>(metricq::HistoryClient::Type::LAST_VALUE) ==
metricq::HistoryRequest::LAST_VALUE,
"Someone broke the protobuf ABI");

namespace metricq
{
HistoryClient::HistoryClient(const std::string& token, bool add_uuid) : Connection(token, add_uuid)
Expand Down Expand Up @@ -79,14 +92,13 @@ void HistoryClient::setup_history_consumer(const std::string& name, int message_
}

std::string HistoryClient::history_request(const std::string& id, TimePoint begin, TimePoint end,
Duration interval)
Duration interval, Type request_type)
{
HistoryRequest request;
request.set_start_time(begin.time_since_epoch().count());
request.set_end_time(end.time_since_epoch().count());
request.set_interval_max(interval.count());
// TODO expose the request type to the user. For now it's fine.
request.set_type(HistoryRequest::FLEX_TIMELINE);
request.set_type(HistoryRequest::RequestType(static_cast<int>(request_type)));

auto correlation_id = std::string("metricq-history-") + token() + "-" + uuid();

Expand Down Expand Up @@ -130,7 +142,7 @@ void HistoryClient::config(const metricq::json& config)
history_exchange_ = config["historyExchange"].get<std::string>();
history_queue_ = config["historyQueue"].get<std::string>();

on_history_config(config["config"]);
on_history_config(config.count("config") ? config["config"] : json::object());

setup_history_queue();

Expand Down
Loading