-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
DynamoDB: Log stats for partition id per operation #147
Changes from 2 commits
6695db2
46732a4
3eca229
9ed557d
6532da8
1a3197f
ae1e2e7
5887f69
a2fd649
3891f85
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
#include "dynamo_request_parser.h" | ||
|
||
#include "common/json/json_loader.h" | ||
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. nit: include goes below envoy headers, separated by new line 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. Fixed. |
||
#include "envoy/http/filter.h" | ||
#include "envoy/runtime/runtime.h" | ||
#include "envoy/stats/stats.h" | ||
|
@@ -44,9 +45,9 @@ class DynamoFilter : public Http::StreamFilter { | |
void chargeBasicStats(uint64_t status); | ||
void chargeStatsPerEntity(const std::string& entity, const std::string& entity_type, | ||
uint64_t status); | ||
void chargeFailureSpecificStats(const std::string& body); | ||
void chargeUnProcessedKeysStats(const std::string& body); | ||
void chargeTablePartitionIdStats(const std::string& body); | ||
void chargeFailureSpecificStats(const Json::Object& json_body); | ||
void chargeUnProcessedKeysStats(const Json::Object& json_body); | ||
void chargeTablePartitionIdStats(const Json::Object& json_body); | ||
|
||
Runtime::Loader& runtime_; | ||
std::string stat_prefix_; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#include "dynamo_request_parser.h" | ||
|
||
#include "common/common/utility.h" | ||
#include "common/json/json_loader.h" | ||
|
||
namespace Dynamo { | ||
|
||
|
@@ -60,60 +59,47 @@ std::string RequestParser::parseOperation(const Http::HeaderMap& headerMap) { | |
} | ||
|
||
RequestParser::TableDescriptor RequestParser::parseTable(const std::string& operation, | ||
const std::string& data) { | ||
const Json::Object& json_data) { | ||
TableDescriptor table{"", true}; | ||
|
||
// Simple operations on a single table, have "TableName" explicitly specified. | ||
if (find(SINGLE_TABLE_OPERATIONS.begin(), SINGLE_TABLE_OPERATIONS.end(), operation) != | ||
SINGLE_TABLE_OPERATIONS.end()) { | ||
Json::StringLoader json(data); | ||
if (json.hasObject("TableName")) { | ||
table.table_name = json.getString("TableName"); | ||
} | ||
table.table_name = json_data.getString("TableName", ""); | ||
} else if (find(BATCH_OPERATIONS.begin(), BATCH_OPERATIONS.end(), operation) != | ||
BATCH_OPERATIONS.end()) { | ||
Json::StringLoader json(data); | ||
if (json.hasObject("RequestItems")) { | ||
Json::Object tables = json.getObject("RequestItems"); | ||
tables.iterate([&table](const std::string& key, const Json::Object&) { | ||
if (table.table_name.empty()) { | ||
table.table_name = key; | ||
} else { | ||
if (table.table_name != key) { | ||
table.table_name = ""; | ||
table.is_single_table = false; | ||
return false; | ||
} | ||
Json::Object tables = json_data.getObject("RequestItems", true); | ||
tables.iterate([&table](const std::string& key, const Json::Object&) { | ||
if (table.table_name.empty()) { | ||
table.table_name = key; | ||
} else { | ||
if (table.table_name != key) { | ||
table.table_name = ""; | ||
table.is_single_table = false; | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
return table; | ||
} | ||
std::vector<std::string> RequestParser::parseBatchUnProcessedKeys(const std::string& data) { | ||
std::vector<std::string> RequestParser::parseBatchUnProcessedKeys(const Json::Object& json_data) { | ||
std::vector<std::string> unprocessed_tables; | ||
Json::StringLoader json(data); | ||
if (json.hasObject("UnprocessedKeys")) { | ||
Json::Object tables = json.getObject("UnprocessedKeys"); | ||
tables.iterate([&unprocessed_tables](const std::string& key, const Json::Object&) { | ||
unprocessed_tables.emplace_back(key); | ||
return true; | ||
}); | ||
} | ||
Json::Object tables = json_data.getObject("UnprocessedKeys", true); | ||
tables.iterate([&unprocessed_tables](const std::string& key, const Json::Object&) { | ||
unprocessed_tables.emplace_back(key); | ||
return true; | ||
}); | ||
|
||
return unprocessed_tables; | ||
} | ||
std::string RequestParser::parseErrorType(const std::string& data) { | ||
Json::StringLoader json(data); | ||
|
||
if (json.hasObject("__type")) { | ||
std::string error_type = json.getString("__type"); | ||
for (const std::string& supported_error_type : SUPPORTED_ERROR_TYPES) { | ||
if (StringUtil::endsWith(error_type, supported_error_type)) { | ||
return supported_error_type; | ||
} | ||
std::string RequestParser::parseErrorType(const Json::Object& json_data) { | ||
std::string error_type = json_data.getString("__type", ""); | ||
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. if __type is not set on the json, we'll iterate though all supported_error_types. we could early exit if __type is missing or if error_type after json_data.getString("__type", ""); is empty. 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. Fixed. |
||
for (const std::string& supported_error_type : SUPPORTED_ERROR_TYPES) { | ||
if (StringUtil::endsWith(error_type, supported_error_type)) { | ||
return supported_error_type; | ||
} | ||
} | ||
|
||
|
@@ -126,13 +112,11 @@ bool RequestParser::isBatchOperation(const std::string& operation) { | |
} | ||
|
||
std::vector<RequestParser::PartitionDescriptor> | ||
RequestParser::parsePartitions(const std::string& data) { | ||
Json::StringLoader json(data); | ||
RequestParser::parsePartitions(const Json::Object& json_data) { | ||
std::vector<RequestParser::PartitionDescriptor> partition_descriptors; | ||
|
||
Json::Object consumed_capacity = json.getObject("ConsumedCapacity", true); | ||
Json::Object partitions = consumed_capacity.getObject("Partitions", true); | ||
|
||
Json::Object partitions = | ||
json_data.getObject("ConsumedCapacity", true).getObject("Partitions", true); | ||
partitions.iterate([&partition_descriptors, &partitions](const std::string& key, | ||
const Json::Object&) { | ||
// For a given partition id, the amount of capacity used is returned in the body as a double. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#pragma once | ||
|
||
#include "common/json/json_loader.h" | ||
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. nit: header ordering 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. Fixed. |
||
#include "envoy/http/header_map.h" | ||
|
||
namespace Dynamo { | ||
|
@@ -47,7 +48,7 @@ class RequestParser { | |
* | ||
* @throw Json::Exception if data is not in valid Json format. | ||
*/ | ||
static TableDescriptor parseTable(const std::string& operation, const std::string& data); | ||
static TableDescriptor parseTable(const std::string& operation, const Json::Object& json_data); | ||
|
||
/** | ||
* Parse error details which might be provided for a given response code. | ||
|
@@ -59,14 +60,14 @@ class RequestParser { | |
* | ||
* @throw Json::Exception if data is not in valid Json format. | ||
*/ | ||
static std::string parseErrorType(const std::string& data); | ||
static std::string parseErrorType(const Json::Object& json_data); | ||
|
||
/** | ||
* Parse unprocessed keys for batch operation results. | ||
* @return empty set if there are no unprocessed keys or a set of table names that did not get | ||
* processed in the batch operation. | ||
*/ | ||
static std::vector<std::string> parseBatchUnProcessedKeys(const std::string& data); | ||
static std::vector<std::string> parseBatchUnProcessedKeys(const Json::Object& json_data); | ||
|
||
/** | ||
* @return true if the operation is in the set of supported BATCH_OPERATIONS | ||
|
@@ -80,7 +81,7 @@ class RequestParser { | |
* | ||
* @throw Json::Exception if data is not in valid Json format. | ||
*/ | ||
static std::vector<PartitionDescriptor> parsePartitions(const std::string& data); | ||
static std::vector<PartitionDescriptor> parsePartitions(const Json::Object& json_data); | ||
|
||
private: | ||
static const Http::LowerCaseString X_AMZ_TARGET; | ||
|
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.
if (body.empty()) {
return;
}