You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by "kirbyzhou (via GitHub)" <gi...@apache.org> on 2023/12/27 11:03:45 UTC
Re: [PR] feat(new_metrics): take snapshot of each entity as json format [incubator-pegasus]
kirbyzhou commented on code in PR #1258:
URL: https://github.com/apache/incubator-pegasus/pull/1258#discussion_r1436955381
##########
src/utils/metrics.h:
##########
@@ -222,6 +225,95 @@ class metric_entity : public ref_counter
using metric_entity_ptr = ref_ptr<metric_entity>;
+// This struct includes a set of filters for both entities and metrics requested by client.
+struct metric_filters
+{
+ using metric_fields_type = std::unordered_set<std::string>;
+ using entity_types_type = std::vector<std::string>;
+ using entity_ids_type = std::unordered_set<std::string>;
+ using entity_attrs_type = std::vector<std::string>;
+ using entity_metrics_type = std::vector<std::string>;
+
+// NOTICE: empty `white_list` means every field is required by client.
+#define RETURN_MATCHED_WITH_EMPTY_WHITE_LIST(white_list) \
+ do { \
+ if (white_list.empty()) { \
+ return true; \
+ } \
+ } while (0)
+
+#define DEFINE_SIMPLE_MATCHER(name) \
+ template <typename T> \
+ inline bool match_##name(const T &candidate) const \
+ { \
+ return match(candidate, name##s); \
+ }
+
+ static inline bool match(const char *candidate, const std::vector<std::string> &white_list)
+ {
+ RETURN_MATCHED_WITH_EMPTY_WHITE_LIST(white_list);
+ // Will use `bool operator==(const string &lhs, const char *rhs);` to compare each element
+ // in `white_list` with `candidate`.
+ return std::find(white_list.begin(), white_list.end(), candidate) != white_list.end();
+ }
+
+ static inline bool match(const std::string &candidate,
+ const std::unordered_set<std::string> &white_list)
+ {
+ RETURN_MATCHED_WITH_EMPTY_WHITE_LIST(white_list);
+ return white_list.find(candidate) != white_list.end();
+ }
+
+ // According to the parameters requested by client, this function will filter metric
+ // fields that will be put in the response.
+ DEFINE_SIMPLE_MATCHER(with_metric_field)
+
+ DEFINE_SIMPLE_MATCHER(entity_type)
+
+ DEFINE_SIMPLE_MATCHER(entity_id)
+
+ bool match_entity_attrs(const metric_entity::attr_map &candidates) const
+ {
+ RETURN_MATCHED_WITH_EMPTY_WHITE_LIST(entity_attrs);
+
+ // The size of container must be divisible by 2, since attribute name always pairs
+ // with value in it.
+ CHECK_EQ(entity_attrs.size() & 1, 0);
+
+ for (entity_attrs_type::size_type i = 0; i < entity_attrs.size(); i += 2) {
+ metric_entity::attr_map::const_iterator iter = candidates.find(entity_attrs[i]);
Review Comment:
"const auto& iter = ..." will get a const iterator, not a const_iterator, which is different.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org