Files
doris/be/test/runtime/external_scan_context_mgr_test.cpp
Yingchun Lai 72f3082358 [Metrics] Add some metrics for container size in BE (#3246)
We can observe the workload of BE, and also it's a way to check
whether there is any problem in BE, like some container increase
too large and lead to OOM.

This patch add the following metrics:
```
Name                                   Description
rowset_count_generated_and_in_use      The total count of rowset id generated and in use since BE last start
unused_rowsets_count                   The total count of unused rowset waiting to be GC
broker_count                           The total count of brokers in management
data_stream_receiver_count             The total count of data stream receivers in management
fragment_endpoint_count                The total count of fragment endpoints of data stream in management, should always equal to data_stream_receiver_count
active_scan_context_count              The total count of active scan contexts
plan_fragment_count                    The total count of plan fragments in executing
load_channel_count                     The total count of load channels in management
result_buffer_block_count              The total count of result buffer blocks for queries, each block has a limited queue size (default 1024)
result_block_queue_count               The total count of queues for fragments, each queue has a limited size (default 20, by config::max_memory_sink_batch_count)
routine_load_task_count                The total count of routine load tasks in executing
small_file_cache_count                 The total count of cached small files' digest info
stream_load_pipe_count                 The total count of stream load pipes, each pipe has a limited buffer size (default 1M)
tablet_writer_count                    The total count of tablet writers
brpc_endpoint_stub_count               The total count of brpc endpoints
```
2020-04-25 16:13:39 +08:00

121 lines
4.0 KiB
C++

// 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 <gtest/gtest.h>
#include <memory>
#include "common/config.h"
#include "common/status.h"
#include "runtime/external_scan_context_mgr.h"
#include "runtime/fragment_mgr.h"
#include "runtime/result_queue_mgr.h"
#include "runtime/thread_resource_mgr.h"
#include "util/doris_metrics.h"
namespace doris {
class ExternalScanContextMgrTest : public testing::Test {
public:
ExternalScanContextMgrTest() {
DorisMetrics::instance()->initialize("ut");
FragmentMgr* fragment_mgr = new FragmentMgr(&_exec_env);
ThreadResourceMgr* thread_mgr = new ThreadResourceMgr();
ResultQueueMgr* result_queue_mgr = new ResultQueueMgr();
_exec_env._fragment_mgr = fragment_mgr;
_exec_env._thread_mgr = thread_mgr;
_exec_env._result_queue_mgr = result_queue_mgr;
}
virtual ~ExternalScanContextMgrTest() {
delete _exec_env._fragment_mgr;
delete _exec_env._thread_mgr;
delete _exec_env._result_queue_mgr;
}
protected:
virtual void SetUp() {
}
private:
ExecEnv _exec_env;
};
TEST_F(ExternalScanContextMgrTest, create_normal) {
std::shared_ptr<ScanContext> context;
ExternalScanContextMgr context_mgr(&_exec_env);
context_mgr._is_stop = true;
Status st = context_mgr.create_scan_context(&context);
ASSERT_TRUE(st.ok());
ASSERT_TRUE(context != nullptr);
}
TEST_F(ExternalScanContextMgrTest, get_normal) {
std::shared_ptr<ScanContext> context;
ExternalScanContextMgr context_mgr(&_exec_env);
context_mgr._is_stop = true;
Status st = context_mgr.create_scan_context(&context);
ASSERT_TRUE(st.ok());
ASSERT_TRUE(context != nullptr);
std::string context_id = context->context_id;
std::shared_ptr<ScanContext> result;
st = context_mgr.get_scan_context(context_id, &result);
ASSERT_TRUE(st.ok());
ASSERT_TRUE(context != nullptr);
}
TEST_F(ExternalScanContextMgrTest, get_abnormal) {
std::string context_id = "not_exist";
std::shared_ptr<ScanContext> result;
ExternalScanContextMgr context_mgr(&_exec_env);
context_mgr._is_stop = true;
Status st = context_mgr.get_scan_context(context_id, &result);
ASSERT_TRUE(!st.ok());
ASSERT_TRUE(result == nullptr);
}
TEST_F(ExternalScanContextMgrTest, clear_context) {
std::shared_ptr<ScanContext> context;
ExternalScanContextMgr context_mgr(&_exec_env);
context_mgr._is_stop = true;
Status st = context_mgr.create_scan_context(&context);
ASSERT_TRUE(st.ok());
ASSERT_TRUE(context != nullptr);
std::string context_id = context->context_id;
st = context_mgr.clear_scan_context(context_id);
ASSERT_TRUE(st.ok());
std::shared_ptr<ScanContext> result;
st = context_mgr.get_scan_context(context_id, &result);
ASSERT_TRUE(!st.ok());
ASSERT_TRUE(result == nullptr);
}
}
int main(int argc, char** argv) {
std::string conffile = std::string(getenv("DORIS_HOME")) + "/conf/be.conf";
if (!doris::config::init(conffile.c_str(), false)) {
fprintf(stderr, "error read config file. \n");
return -1;
}
doris::config::scan_context_gc_interval_min = 1;
// doris::init_glog("be-test");
::testing::InitGoogleTest(&argc, argv);
doris::CpuInfo::init();
return RUN_ALL_TESTS();
}