-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feat] support fe/be metrics system table #54221
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
Open
zhaorongsheng
wants to merge
16
commits into
apache:master
Choose a base branch
from
zhaorongsheng:feature_support_fe_be_metrics_tables
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
27ba453
support fe/be metrics system table
56ceabb
support fe/be metrics system table
35f9b95
support fe/be metrics system table
e91458d
support fe/be metrics system table
12d4aa8
support fe/be metrics system table
76f1ad3
support fe/be metrics system table
bc159f4
support fe/be metrics system table
c61e4e4
support fe/be metrics system table
538da1f
support fe/be metrics system table
f5a17b4
support fe/be metrics system table
693101f
add fe/be metric system table
bfe8c3d
add fe/be metrics tables
5f201d2
Update fe/fe-core/src/main/java/org/apache/doris/metric/ListMetricVis…
zhaorongsheng e8d9677
Update be/src/util/metrics.cpp
zhaorongsheng e449a3f
Update be/src/exec/schema_scanner/schema_frontend_metrics_scanner.h
zhaorongsheng 8a957dd
Update be/src/exec/schema_scanner/schema_backend_metrics_scanner.h
zhaorongsheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
be/src/exec/schema_scanner/schema_backend_metrics_scanner.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "exec/schema_scanner/schema_backend_metrics_scanner.h" | ||
|
|
||
| #include "runtime/exec_env.h" | ||
| #include "runtime/runtime_query_statistics_mgr.h" | ||
| #include "runtime/runtime_state.h" | ||
| #include "vec/common/string_ref.h" | ||
| #include "vec/core/block.h" | ||
| #include "vec/data_types/data_type_factory.hpp" | ||
|
|
||
| namespace doris { | ||
| #include "common/compile_check_begin.h" | ||
|
|
||
| std::vector<SchemaScanner::ColumnDesc> SchemaBackendMetricsScanner::_s_tbls_columns = { | ||
| // name, type, size, is_null | ||
| {"BE_ID", TYPE_BIGINT, sizeof(int64_t), true}, | ||
| {"BE_IP", TYPE_VARCHAR, sizeof(StringRef), true}, | ||
| {"METRIC_NAME", TYPE_VARCHAR, sizeof(StringRef), true}, | ||
| {"METRIC_TYPE", TYPE_VARCHAR, sizeof(StringRef), true}, | ||
| {"METRIC_VALUE", TYPE_DOUBLE, sizeof(double), true}, | ||
| {"TAG", TYPE_VARCHAR, sizeof(StringRef), true}}; | ||
|
|
||
| SchemaBackendMetricsScanner::SchemaBackendMetricsScanner() | ||
| : SchemaScanner(_s_tbls_columns, TSchemaTableType::SCH_BE_METRICS) {} | ||
|
|
||
| SchemaBackendMetricsScanner::~SchemaBackendMetricsScanner() {} | ||
|
|
||
| Status SchemaBackendMetricsScanner::start(RuntimeState* state) { | ||
| _block_rows_limit = state->batch_size(); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| Status SchemaBackendMetricsScanner::get_next_block_internal(vectorized::Block* block, bool* eos) { | ||
| if (!_is_init) { | ||
| return Status::InternalError("Used before initialized."); | ||
| } | ||
|
|
||
| if (nullptr == block || nullptr == eos) { | ||
| return Status::InternalError("input pointer is nullptr."); | ||
| } | ||
|
|
||
| if (_backend_metrics_block == nullptr) { | ||
| _backend_metrics_block = vectorized::Block::create_unique(); | ||
| for (int i = 0; i < _s_tbls_columns.size(); ++i) { | ||
| auto data_type = vectorized::DataTypeFactory::instance().create_data_type( | ||
| _s_tbls_columns[i].type, true); | ||
| _backend_metrics_block->insert(vectorized::ColumnWithTypeAndName( | ||
| data_type->create_column(), data_type, _s_tbls_columns[i].name)); | ||
| } | ||
| _backend_metrics_block->reserve(_block_rows_limit); | ||
| DorisMetrics::instance()->metric_registry()->get_be_metrics_block( | ||
| _backend_metrics_block.get()); | ||
| _total_rows = (int)_backend_metrics_block->rows(); | ||
| } | ||
|
|
||
| if (_row_idx == _total_rows) { | ||
| *eos = true; | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| int current_batch_rows = std::min(_block_rows_limit, _total_rows - _row_idx); | ||
| vectorized::MutableBlock mblock = vectorized::MutableBlock::build_mutable_block(block); | ||
| RETURN_IF_ERROR(mblock.add_rows(_backend_metrics_block.get(), _row_idx, current_batch_rows)); | ||
| _row_idx += current_batch_rows; | ||
|
|
||
| *eos = _row_idx == _total_rows; | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| } // namespace doris |
49 changes: 49 additions & 0 deletions
49
be/src/exec/schema_scanner/schema_backend_metrics_scanner.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "common/status.h" | ||
| #include "exec/schema_scanner.h" | ||
|
|
||
| namespace doris { | ||
| class RuntimeState; | ||
| namespace vectorized { | ||
| class Block; | ||
| } // namespace vectorized | ||
|
|
||
| class SchemaBackendMetricsScanner : public SchemaScanner { | ||
| ENABLE_FACTORY_CREATOR(SchemaBackendMetricsScanner); | ||
|
|
||
| public: | ||
| SchemaBackendMetricsScanner(); | ||
| ~SchemaBackendMetricsScanner() override; | ||
|
|
||
| Status start(RuntimeState* state) override; | ||
| Status get_next_block_internal(vectorized::Block* block, bool* eos) override; | ||
|
|
||
| static std::vector<SchemaScanner::ColumnDesc> _s_tbls_columns; | ||
|
|
||
| private: | ||
| int _block_rows_limit = 4096; | ||
| int _row_idx = 0; | ||
| int _total_rows = 0; | ||
| std::unique_ptr<vectorized::Block> _backend_metrics_block = nullptr; | ||
| }; | ||
| } // namespace doris |
132 changes: 132 additions & 0 deletions
132
be/src/exec/schema_scanner/schema_frontend_metrics_scanner.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "exec/schema_scanner/schema_frontend_metrics_scanner.h" | ||
|
|
||
| #include <gen_cpp/FrontendService_types.h> | ||
|
|
||
| #include <exception> | ||
| #include <vector> | ||
|
|
||
| #include "exec/schema_scanner/schema_helper.h" | ||
| #include "runtime/define_primitive_type.h" | ||
| #include "runtime/runtime_state.h" | ||
| #include "vec/common/string_ref.h" | ||
| #include "vec/core/block.h" | ||
| #include "vec/data_types/data_type_factory.hpp" | ||
|
|
||
| namespace doris { | ||
| #include "common/compile_check_begin.h" | ||
|
|
||
| std::vector<SchemaScanner::ColumnDesc> SchemaFrontendMetricsScanner::_s_frontend_metric_columns = { | ||
| // name, type, size, is_null | ||
| {"FE", TYPE_VARCHAR, sizeof(StringRef), true}, | ||
| {"METRIC_NAME", TYPE_VARCHAR, sizeof(StringRef), true}, | ||
| {"METRIC_TYPE", TYPE_VARCHAR, sizeof(StringRef), true}, | ||
| {"METRIC_VALUE", TYPE_DOUBLE, sizeof(double), true}, | ||
| {"TAG", TYPE_VARCHAR, sizeof(StringRef), true}}; | ||
|
|
||
| SchemaFrontendMetricsScanner::SchemaFrontendMetricsScanner() | ||
| : SchemaScanner(_s_frontend_metric_columns, TSchemaTableType::SCH_FE_METRICS) {} | ||
|
|
||
| SchemaFrontendMetricsScanner::~SchemaFrontendMetricsScanner() = default; | ||
|
|
||
| Status SchemaFrontendMetricsScanner::start(RuntimeState* state) { | ||
| TFetchFeMetricsRequest request; | ||
|
|
||
| for (const auto& fe_addr : _param->common_param->fe_addr_list) { | ||
| TFetchFeMetricsResult tmp_ret; | ||
| RETURN_IF_ERROR(SchemaHelper::fetch_frontend_metrics(fe_addr.hostname, fe_addr.port, | ||
| request, &tmp_ret)); | ||
|
|
||
| _metrics_list_result.metrics_list.insert(_metrics_list_result.metrics_list.end(), | ||
| tmp_ret.metrics_list.begin(), | ||
| tmp_ret.metrics_list.end()); | ||
| } | ||
|
|
||
| return Status::OK(); | ||
| } | ||
|
|
||
| Status SchemaFrontendMetricsScanner::get_next_block_internal(vectorized::Block* block, bool* eos) { | ||
| if (!_is_init) { | ||
| return Status::InternalError("call this before initial."); | ||
| } | ||
| if (block == nullptr || eos == nullptr) { | ||
| return Status::InternalError("invalid parameter."); | ||
| } | ||
|
|
||
| *eos = true; | ||
| if (_metrics_list_result.metrics_list.empty()) { | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| return _fill_block_impl(block); | ||
| } | ||
|
|
||
| Status SchemaFrontendMetricsScanner::_fill_block_impl(vectorized::Block* block) { | ||
| SCOPED_TIMER(_fill_block_timer); | ||
|
|
||
| const auto& metrics_list = _metrics_list_result.metrics_list; | ||
| size_t row_num = metrics_list.size(); | ||
| if (row_num == 0) { | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| for (size_t col_idx = 0; col_idx < _s_frontend_metric_columns.size(); ++col_idx) { | ||
| std::vector<StringRef> str_refs(row_num); | ||
| std::vector<double> double_vals(row_num); | ||
| std::vector<void*> datas(row_num); | ||
| std::vector<std::string> column_values( | ||
| row_num); // Store the strings to ensure their lifetime | ||
|
|
||
| for (size_t row_idx = 0; row_idx < row_num; ++row_idx) { | ||
| const auto& row = metrics_list[row_idx]; | ||
| if (row.size() != _s_frontend_metric_columns.size()) { | ||
| return Status::InternalError( | ||
| "process list meet invalid schema, schema_size={}, input_data_size={}", | ||
| _s_frontend_metric_columns.size(), row.size()); | ||
| } | ||
|
|
||
| // Fetch and store the column value based on its index | ||
| std::string& column_value = | ||
| column_values[row_idx]; // Reference to the actual string in the vector | ||
| column_value = row[col_idx]; | ||
|
|
||
| if (_s_frontend_metric_columns[col_idx].type == TYPE_DOUBLE) { | ||
| try { | ||
| double val = !column_value.empty() ? std::stod(column_value) : 0; | ||
| double_vals[row_idx] = val; | ||
| } catch (const std::exception& e) { | ||
| return Status::InternalError( | ||
| "process list meet invalid data, column={}, data={}, reason={}", | ||
| _s_frontend_metric_columns[col_idx].name, column_value, e.what()); | ||
|
Comment on lines
+114
to
+116
|
||
| } | ||
| datas[row_idx] = &double_vals[row_idx]; | ||
| } else { | ||
| str_refs[row_idx] = | ||
| StringRef(column_values[row_idx].data(), column_values[row_idx].size()); | ||
| datas[row_idx] = &str_refs[row_idx]; | ||
| } | ||
| } | ||
|
|
||
| RETURN_IF_ERROR(fill_dest_column_for_range(block, col_idx, datas)); | ||
| } | ||
|
|
||
| return Status::OK(); | ||
| } | ||
|
|
||
| } // namespace doris | ||
53 changes: 53 additions & 0 deletions
53
be/src/exec/schema_scanner/schema_frontend_metrics_scanner.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "common/status.h" | ||
| #include "exec/schema_scanner.h" | ||
| #include "gen_cpp/FrontendService_types.h" | ||
|
|
||
| namespace doris { | ||
|
|
||
| class RuntimeState; | ||
|
|
||
| namespace vectorized { | ||
| class Block; | ||
| } | ||
|
|
||
| class SchemaFrontendMetricsScanner : public SchemaScanner { | ||
| ENABLE_FACTORY_CREATOR(SchemaFrontendMetricsScanner); | ||
|
|
||
| public: | ||
| SchemaFrontendMetricsScanner(); | ||
| ~SchemaFrontendMetricsScanner() override; | ||
|
|
||
| Status start(RuntimeState* state) override; | ||
| Status get_next_block_internal(vectorized::Block* block, bool* eos) override; | ||
|
|
||
| static std::vector<SchemaScanner::ColumnDesc> _s_tbls_columns; | ||
|
|
||
| private: | ||
| Status _fill_block_impl(vectorized::Block* block); | ||
|
|
||
| TFetchFeMetricsResult _metrics_list_result; | ||
| }; | ||
|
|
||
| } // namespace doris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The error message references "process list" which is a copy-paste error from SchemaProcesslistScanner. The error message should reference "frontend metrics" instead to accurately reflect the context of this scanner.