You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/05/14 14:55:42 UTC
[GitHub] [incubator-doris] xinghuayu007 opened a new pull request #5824: [Metric][Http Interface] Aggregate metric for any metric label
xinghuayu007 opened a new pull request #5824:
URL: https://github.com/apache/incubator-doris/pull/5824
## Proposed changes
Tablet has 5 metrics to record read/write statistic data.
IntCounter* query_scan_bytes;
IntCounter* query_scan_rows;
IntCounter* query_scan_count;
IntCounter* flush_bytes;
IntCounter* flush_count;
It is meaningful to get these read/write data to find zero-read/write or hot-read/write table and partition. But in these metrics, it has tablet id information, but no table id/partition id information. Therefore this PR add table id/partition id for these 5 metrics. On the other side, there are maybe hundred thousands of tablet. It is difficult to get these metrics directly by http interface. There this patch provide a aggregate http interface. It can aggregate metric data according to metric label.
It is diffcult to write some unit tests to test this patch. Therefore, it is only be tested in offline running system.
Usage:
http://localshot:8040/metrics?type=aggregate&entity_type=tablet&metric_name=query_scan_bytes&aggregate_label=table_id
type: json/prometheus/aggregate
entity_type: tablet/server
metric_name: the name of one metric, like `flush_count`
aggregate_lable: aggregate metric by which metric label
## Types of changes
What types of changes does your code introduce to Doris?
_Put an `x` in the boxes that apply_
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation Update (if none of the other choices apply)
- [ ] Code refactor (Modify the code structure, format the code, etc...)
## Checklist
_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
- [ ] I have created an issue on (Fix #ISSUE) and described the bug/feature there in detail
- [ ] Compiling and unit tests pass locally with my changes
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] If these changes need document changes, I have updated the document
- [ ] Any dependent changes have been merged
## Further comments
If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] acelyc111 commented on pull request #5824: [Metric][Http Interface] Aggregate metric for any metric label
Posted by GitBox <gi...@apache.org>.
acelyc111 commented on pull request #5824:
URL: https://github.com/apache/incubator-doris/pull/5824#issuecomment-841785894
> Usage:
http://localshot:8040/metrics?type=aggregate&entity_type=tablet&metric_name=query_scan_bytes&aggregate_label=table_id
If I want to collect all the 5 metrics, I have to request 5 times?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] xinghuayu007 commented on pull request #5824: [Metric][Http Interface] Aggregate metric for any metric label
Posted by GitBox <gi...@apache.org>.
xinghuayu007 commented on pull request #5824:
URL: https://github.com/apache/incubator-doris/pull/5824#issuecomment-841966758
> > Usage:
> > http://localshot:8040/metrics?type=aggregate&entity_type=tablet&metric_name=query_scan_bytes&aggregate_label=table_id
>
> If I want to collect all the 5 metrics, I have to request 5 times?
Yes, this http interface supports to aggregate the label of one metric, not the metric self.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] acelyc111 commented on pull request #5824: [Metric][Http Interface] Aggregate metric for any metric label
Posted by GitBox <gi...@apache.org>.
acelyc111 commented on pull request #5824:
URL: https://github.com/apache/incubator-doris/pull/5824#issuecomment-841971410
> > > Usage:
> > > http://localshot:8040/metrics?type=aggregate&entity_type=tablet&metric_name=query_scan_bytes&aggregate_label=table_id
> >
> >
> > If I want to collect all the 5 metrics, I have to request 5 times?
>
> Yes, this http interface supports to aggregate the label of one metric, not the metric self.
Why not aggreate all metrics whose entity is type of 'entity_type' and contains 'aggregate_label', it would be more general.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] acelyc111 commented on a change in pull request #5824: [Metric][Http Interface] Aggregate metric for any metric label
Posted by GitBox <gi...@apache.org>.
acelyc111 commented on a change in pull request #5824:
URL: https://github.com/apache/incubator-doris/pull/5824#discussion_r633060653
##########
File path: be/src/util/metrics.cpp
##########
@@ -422,4 +422,62 @@ std::string MetricRegistry::to_core_string() const {
return ss.str();
}
+std::string MetricRegistry::aggregate_metric(const std::string entity_type,
+ const std::string metric_name,
+ const std::string& aggregate_label) const {
+ rj::Document doc{rj::kArrayType};
+ rj::Document::AllocatorType &allocator = doc.GetAllocator();
+ std::lock_guard<SpinLock> l(_lock);
+ std::map<std::string, int64_t> label_map;
+ MetricEntityType metric_entity_type = MetricEntityType::kTablet;
+ if (entity_type == "tablet") {
+ metric_entity_type = MetricEntityType::kTablet;
+ } else {
+ metric_entity_type = MetricEntityType::kServer;
+ }
+ if (metric_name.empty() || aggregate_label.empty()) {
+ rj::StringBuffer strBuf;
+ rj::Writer<rj::StringBuffer> writer(strBuf);
+ doc.Accept(writer);
+ return strBuf.GetString();
+ }
+ for (const auto &entity : _entities) {
+ if (entity.first->_type != metric_entity_type) {
+ continue;
+ }
+ std::lock_guard<SpinLock> l(entity.first->_lock);
+ entity.first->trigger_hook_unlocked(false);
+ for (const auto &metric : entity.first->_metrics) {
+ if (metric.first->simple_name() != metric_name) {
+ continue;
+ }
+ for (auto& label : entity.first->_labels) {
+ if (label.first.c_str() == aggregate_label) {
+ std::string value = metric.second->to_string();
+ int64_t realValue = atoi(value.c_str());
Review comment:
How about if it's a double type?
##########
File path: be/src/util/metrics.h
##########
@@ -410,6 +410,9 @@ class MetricRegistry {
std::string to_prometheus(bool with_tablet_metrics = false) const;
std::string to_json(bool with_tablet_metrics = false) const;
std::string to_core_string() const;
+ std::string aggregate_metric(const std::string entityType,
+ const std::string metric_name,
Review comment:
```suggestion
std::string aggregate_metric(const std::string& entityType,
const std::string& metric_name,
```
##########
File path: be/src/util/metrics.cpp
##########
@@ -422,4 +422,62 @@ std::string MetricRegistry::to_core_string() const {
return ss.str();
}
+std::string MetricRegistry::aggregate_metric(const std::string entity_type,
+ const std::string metric_name,
+ const std::string& aggregate_label) const {
+ rj::Document doc{rj::kArrayType};
+ rj::Document::AllocatorType &allocator = doc.GetAllocator();
+ std::lock_guard<SpinLock> l(_lock);
+ std::map<std::string, int64_t> label_map;
+ MetricEntityType metric_entity_type = MetricEntityType::kTablet;
+ if (entity_type == "tablet") {
+ metric_entity_type = MetricEntityType::kTablet;
+ } else {
+ metric_entity_type = MetricEntityType::kServer;
+ }
+ if (metric_name.empty() || aggregate_label.empty()) {
+ rj::StringBuffer strBuf;
+ rj::Writer<rj::StringBuffer> writer(strBuf);
+ doc.Accept(writer);
+ return strBuf.GetString();
+ }
+ for (const auto &entity : _entities) {
+ if (entity.first->_type != metric_entity_type) {
+ continue;
+ }
+ std::lock_guard<SpinLock> l(entity.first->_lock);
+ entity.first->trigger_hook_unlocked(false);
+ for (const auto &metric : entity.first->_metrics) {
+ if (metric.first->simple_name() != metric_name) {
+ continue;
+ }
+ for (auto& label : entity.first->_labels) {
+ if (label.first.c_str() == aggregate_label) {
+ std::string value = metric.second->to_string();
+ int64_t realValue = atoi(value.c_str());
+ std::string label_value = label.second.c_str();
+ auto it = label_map.find(label_value);
+ if (it == label_map.end()) {
+ label_map.insert(std::make_pair(label_value, realValue));
+ } else {
+ label_map.insert(std::make_pair(label_value, realValue+it->second));
Review comment:
```suggestion
it->second += realValue;
```
##########
File path: be/src/olap/base_tablet.cpp
##########
@@ -44,7 +44,9 @@ BaseTablet::BaseTablet(TabletMetaSharedPtr tablet_meta, DataDir* data_dir)
_metric_entity = DorisMetrics::instance()->metric_registry()->register_entity(
strings::Substitute("Tablet.$0", tablet_id()),
- {{"tablet_id", std::to_string(tablet_id())}}, MetricEntityType::kTablet);
+ {{"tablet_id", std::to_string(tablet_id())},
+ {"partition_id", std::to_string(partition_id())},
+ {"table_id", std::to_string(table_id())}},MetricEntityType::kTablet);
Review comment:
```suggestion
{{"tablet_id", std::to_string(tablet_id())},
{"partition_id", std::to_string(partition_id())},
{"table_id", std::to_string(table_id())}},
MetricEntityType::kTablet);
```
##########
File path: be/src/http/action/metrics_action.cpp
##########
@@ -36,11 +36,16 @@ namespace doris {
void MetricsAction::handle(HttpRequest* req) {
const std::string& type = req->param("type");
const std::string& with_tablet = req->param("with_tablet");
+ const std::string& aggregate_label = req->param("aggregate_label");
+ const std::string entity_type = req->param("entity_type");
+ const std::string metric_name = req->param("metric_name");
std::string str;
if (type == "core") {
str = _metric_registry->to_core_string();
} else if (type == "json") {
str = _metric_registry->to_json(with_tablet == "true");
+ } else if (type == "aggregate") {
+ str = _metric_registry->aggregate_metric(entity_type, metric_name, aggregate_label);
Review comment:
The output must be in JSON format?
##########
File path: be/src/http/action/metrics_action.cpp
##########
@@ -36,11 +36,16 @@ namespace doris {
void MetricsAction::handle(HttpRequest* req) {
const std::string& type = req->param("type");
const std::string& with_tablet = req->param("with_tablet");
+ const std::string& aggregate_label = req->param("aggregate_label");
+ const std::string entity_type = req->param("entity_type");
+ const std::string metric_name = req->param("metric_name");
Review comment:
```suggestion
const std::string& entity_type = req->param("entity_type");
const std::string& metric_name = req->param("metric_name");
```
##########
File path: be/src/util/metrics.cpp
##########
@@ -422,4 +422,62 @@ std::string MetricRegistry::to_core_string() const {
return ss.str();
}
+std::string MetricRegistry::aggregate_metric(const std::string entity_type,
+ const std::string metric_name,
+ const std::string& aggregate_label) const {
+ rj::Document doc{rj::kArrayType};
+ rj::Document::AllocatorType &allocator = doc.GetAllocator();
+ std::lock_guard<SpinLock> l(_lock);
+ std::map<std::string, int64_t> label_map;
+ MetricEntityType metric_entity_type = MetricEntityType::kTablet;
+ if (entity_type == "tablet") {
+ metric_entity_type = MetricEntityType::kTablet;
+ } else {
+ metric_entity_type = MetricEntityType::kServer;
+ }
+ if (metric_name.empty() || aggregate_label.empty()) {
+ rj::StringBuffer strBuf;
+ rj::Writer<rj::StringBuffer> writer(strBuf);
+ doc.Accept(writer);
+ return strBuf.GetString();
+ }
+ for (const auto &entity : _entities) {
+ if (entity.first->_type != metric_entity_type) {
+ continue;
+ }
+ std::lock_guard<SpinLock> l(entity.first->_lock);
+ entity.first->trigger_hook_unlocked(false);
+ for (const auto &metric : entity.first->_metrics) {
+ if (metric.first->simple_name() != metric_name) {
+ continue;
+ }
+ for (auto& label : entity.first->_labels) {
Review comment:
`_labels` is type of unordered_map, use `find` instead of traverse all items.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] acelyc111 commented on pull request #5824: [Metric][Http Interface] Aggregate metric for any metric label
Posted by GitBox <gi...@apache.org>.
acelyc111 commented on pull request #5824:
URL: https://github.com/apache/incubator-doris/pull/5824#issuecomment-841785894
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] acelyc111 commented on a change in pull request #5824: [Metric][Http Interface] Aggregate metric for any metric label
Posted by GitBox <gi...@apache.org>.
acelyc111 commented on a change in pull request #5824:
URL: https://github.com/apache/incubator-doris/pull/5824#discussion_r633060653
##########
File path: be/src/util/metrics.cpp
##########
@@ -422,4 +422,62 @@ std::string MetricRegistry::to_core_string() const {
return ss.str();
}
+std::string MetricRegistry::aggregate_metric(const std::string entity_type,
+ const std::string metric_name,
+ const std::string& aggregate_label) const {
+ rj::Document doc{rj::kArrayType};
+ rj::Document::AllocatorType &allocator = doc.GetAllocator();
+ std::lock_guard<SpinLock> l(_lock);
+ std::map<std::string, int64_t> label_map;
+ MetricEntityType metric_entity_type = MetricEntityType::kTablet;
+ if (entity_type == "tablet") {
+ metric_entity_type = MetricEntityType::kTablet;
+ } else {
+ metric_entity_type = MetricEntityType::kServer;
+ }
+ if (metric_name.empty() || aggregate_label.empty()) {
+ rj::StringBuffer strBuf;
+ rj::Writer<rj::StringBuffer> writer(strBuf);
+ doc.Accept(writer);
+ return strBuf.GetString();
+ }
+ for (const auto &entity : _entities) {
+ if (entity.first->_type != metric_entity_type) {
+ continue;
+ }
+ std::lock_guard<SpinLock> l(entity.first->_lock);
+ entity.first->trigger_hook_unlocked(false);
+ for (const auto &metric : entity.first->_metrics) {
+ if (metric.first->simple_name() != metric_name) {
+ continue;
+ }
+ for (auto& label : entity.first->_labels) {
+ if (label.first.c_str() == aggregate_label) {
+ std::string value = metric.second->to_string();
+ int64_t realValue = atoi(value.c_str());
Review comment:
How about if it's a double type?
##########
File path: be/src/util/metrics.h
##########
@@ -410,6 +410,9 @@ class MetricRegistry {
std::string to_prometheus(bool with_tablet_metrics = false) const;
std::string to_json(bool with_tablet_metrics = false) const;
std::string to_core_string() const;
+ std::string aggregate_metric(const std::string entityType,
+ const std::string metric_name,
Review comment:
```suggestion
std::string aggregate_metric(const std::string& entityType,
const std::string& metric_name,
```
##########
File path: be/src/util/metrics.cpp
##########
@@ -422,4 +422,62 @@ std::string MetricRegistry::to_core_string() const {
return ss.str();
}
+std::string MetricRegistry::aggregate_metric(const std::string entity_type,
+ const std::string metric_name,
+ const std::string& aggregate_label) const {
+ rj::Document doc{rj::kArrayType};
+ rj::Document::AllocatorType &allocator = doc.GetAllocator();
+ std::lock_guard<SpinLock> l(_lock);
+ std::map<std::string, int64_t> label_map;
+ MetricEntityType metric_entity_type = MetricEntityType::kTablet;
+ if (entity_type == "tablet") {
+ metric_entity_type = MetricEntityType::kTablet;
+ } else {
+ metric_entity_type = MetricEntityType::kServer;
+ }
+ if (metric_name.empty() || aggregate_label.empty()) {
+ rj::StringBuffer strBuf;
+ rj::Writer<rj::StringBuffer> writer(strBuf);
+ doc.Accept(writer);
+ return strBuf.GetString();
+ }
+ for (const auto &entity : _entities) {
+ if (entity.first->_type != metric_entity_type) {
+ continue;
+ }
+ std::lock_guard<SpinLock> l(entity.first->_lock);
+ entity.first->trigger_hook_unlocked(false);
+ for (const auto &metric : entity.first->_metrics) {
+ if (metric.first->simple_name() != metric_name) {
+ continue;
+ }
+ for (auto& label : entity.first->_labels) {
+ if (label.first.c_str() == aggregate_label) {
+ std::string value = metric.second->to_string();
+ int64_t realValue = atoi(value.c_str());
+ std::string label_value = label.second.c_str();
+ auto it = label_map.find(label_value);
+ if (it == label_map.end()) {
+ label_map.insert(std::make_pair(label_value, realValue));
+ } else {
+ label_map.insert(std::make_pair(label_value, realValue+it->second));
Review comment:
```suggestion
it->second += realValue;
```
##########
File path: be/src/olap/base_tablet.cpp
##########
@@ -44,7 +44,9 @@ BaseTablet::BaseTablet(TabletMetaSharedPtr tablet_meta, DataDir* data_dir)
_metric_entity = DorisMetrics::instance()->metric_registry()->register_entity(
strings::Substitute("Tablet.$0", tablet_id()),
- {{"tablet_id", std::to_string(tablet_id())}}, MetricEntityType::kTablet);
+ {{"tablet_id", std::to_string(tablet_id())},
+ {"partition_id", std::to_string(partition_id())},
+ {"table_id", std::to_string(table_id())}},MetricEntityType::kTablet);
Review comment:
```suggestion
{{"tablet_id", std::to_string(tablet_id())},
{"partition_id", std::to_string(partition_id())},
{"table_id", std::to_string(table_id())}},
MetricEntityType::kTablet);
```
##########
File path: be/src/http/action/metrics_action.cpp
##########
@@ -36,11 +36,16 @@ namespace doris {
void MetricsAction::handle(HttpRequest* req) {
const std::string& type = req->param("type");
const std::string& with_tablet = req->param("with_tablet");
+ const std::string& aggregate_label = req->param("aggregate_label");
+ const std::string entity_type = req->param("entity_type");
+ const std::string metric_name = req->param("metric_name");
std::string str;
if (type == "core") {
str = _metric_registry->to_core_string();
} else if (type == "json") {
str = _metric_registry->to_json(with_tablet == "true");
+ } else if (type == "aggregate") {
+ str = _metric_registry->aggregate_metric(entity_type, metric_name, aggregate_label);
Review comment:
The output must be in JSON format?
##########
File path: be/src/http/action/metrics_action.cpp
##########
@@ -36,11 +36,16 @@ namespace doris {
void MetricsAction::handle(HttpRequest* req) {
const std::string& type = req->param("type");
const std::string& with_tablet = req->param("with_tablet");
+ const std::string& aggregate_label = req->param("aggregate_label");
+ const std::string entity_type = req->param("entity_type");
+ const std::string metric_name = req->param("metric_name");
Review comment:
```suggestion
const std::string& entity_type = req->param("entity_type");
const std::string& metric_name = req->param("metric_name");
```
##########
File path: be/src/util/metrics.cpp
##########
@@ -422,4 +422,62 @@ std::string MetricRegistry::to_core_string() const {
return ss.str();
}
+std::string MetricRegistry::aggregate_metric(const std::string entity_type,
+ const std::string metric_name,
+ const std::string& aggregate_label) const {
+ rj::Document doc{rj::kArrayType};
+ rj::Document::AllocatorType &allocator = doc.GetAllocator();
+ std::lock_guard<SpinLock> l(_lock);
+ std::map<std::string, int64_t> label_map;
+ MetricEntityType metric_entity_type = MetricEntityType::kTablet;
+ if (entity_type == "tablet") {
+ metric_entity_type = MetricEntityType::kTablet;
+ } else {
+ metric_entity_type = MetricEntityType::kServer;
+ }
+ if (metric_name.empty() || aggregate_label.empty()) {
+ rj::StringBuffer strBuf;
+ rj::Writer<rj::StringBuffer> writer(strBuf);
+ doc.Accept(writer);
+ return strBuf.GetString();
+ }
+ for (const auto &entity : _entities) {
+ if (entity.first->_type != metric_entity_type) {
+ continue;
+ }
+ std::lock_guard<SpinLock> l(entity.first->_lock);
+ entity.first->trigger_hook_unlocked(false);
+ for (const auto &metric : entity.first->_metrics) {
+ if (metric.first->simple_name() != metric_name) {
+ continue;
+ }
+ for (auto& label : entity.first->_labels) {
Review comment:
`_labels` is type of unordered_map, use `find` instead of traverse all items.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] xinghuayu007 commented on pull request #5824: [Metric][Http Interface] Aggregate metric for any metric label
Posted by GitBox <gi...@apache.org>.
xinghuayu007 commented on pull request #5824:
URL: https://github.com/apache/incubator-doris/pull/5824#issuecomment-841966758
> > Usage:
> > http://localshot:8040/metrics?type=aggregate&entity_type=tablet&metric_name=query_scan_bytes&aggregate_label=table_id
>
> If I want to collect all the 5 metrics, I have to request 5 times?
Yes, this http interface supports to aggregate the label of one metric, not the metric self.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org