From 35843940012ecfd9b1f39003e8f80085523ff59a Mon Sep 17 00:00:00 2001 From: Dan Wang Date: Sun, 25 Jun 2023 23:56:08 +0800 Subject: [PATCH] feat(new_metrics): remove http service for perf counters (#1540) https://github.com/apache/incubator-pegasus/issues/1539 In https://github.com/XiaoMi/rdsn/pull/349 we've supported getting value of counter by http request. Now since perf counter will be replaced by new metrics, it can also be removed. --- src/http/builtin_http_calls.cpp | 6 -- src/http/builtin_http_calls.h | 2 - src/http/perf_counter_http_service.cpp | 66 ---------------- .../test/perf_counter_http_service_test.cpp | 76 ------------------- src/perf_counter/perf_counters.cpp | 10 --- src/perf_counter/perf_counters.h | 2 - src/perf_counter/test/perf_counters_test.cpp | 29 ------- 7 files changed, 191 deletions(-) delete mode 100644 src/http/perf_counter_http_service.cpp delete mode 100644 src/http/test/perf_counter_http_service_test.cpp diff --git a/src/http/builtin_http_calls.cpp b/src/http/builtin_http_calls.cpp index 127e57a5f0..c267ae03fd 100644 --- a/src/http/builtin_http_calls.cpp +++ b/src/http/builtin_http_calls.cpp @@ -92,12 +92,6 @@ namespace dsn { }) .with_help("Gets the server start time."); - register_http_call("perfCounter") - .with_callback([](const http_request &req, http_response &resp) { - get_perf_counter_handler(req, resp); - }) - .with_help("Gets the value of a perf counter"); - register_http_call("config") .with_callback([](const http_request &req, http_response &resp) { get_config(req, resp); }) .with_help("get the details of a specified config"); diff --git a/src/http/builtin_http_calls.h b/src/http/builtin_http_calls.h index 90bbd3675c..44c589ca43 100644 --- a/src/http/builtin_http_calls.h +++ b/src/http/builtin_http_calls.h @@ -24,8 +24,6 @@ struct http_response; // Register basic services for the HTTP server. extern void register_builtin_http_calls(); -extern void get_perf_counter_handler(const http_request &req, http_response &resp); - extern void get_help_handler(const http_request &req, http_response &resp); // Get /version diff --git a/src/http/perf_counter_http_service.cpp b/src/http/perf_counter_http_service.cpp deleted file mode 100644 index 5fcb24659a..0000000000 --- a/src/http/perf_counter_http_service.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// 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 -#include -#include -#include - -#include "builtin_http_calls.h" -#include "http/http_server.h" -#include "perf_counter/perf_counter.h" -#include "perf_counter/perf_counters.h" -#include "utils/autoref_ptr.h" -#include "utils/output_utils.h" - -namespace dsn { - -void get_perf_counter_handler(const http_request &req, http_response &resp) -{ - std::string perf_counter_name; - for (const auto &p : req.query_args) { - if ("name" == p.first) { - perf_counter_name = p.second; - } else { - resp.status_code = http_status_code::bad_request; - return; - } - } - - // get perf counter by perf counter name - perf_counter_ptr perf_counter = perf_counters::instance().get_counter(perf_counter_name); - - // insert perf counter info into table printer - dsn::utils::table_printer tp; - if (perf_counter) { - tp.add_row_name_and_data("name", perf_counter_name); - if (COUNTER_TYPE_NUMBER_PERCENTILES == perf_counter->type()) { - tp.add_row_name_and_data("p99", perf_counter->get_percentile(COUNTER_PERCENTILE_99)); - tp.add_row_name_and_data("p999", perf_counter->get_percentile(COUNTER_PERCENTILE_999)); - } else { - tp.add_row_name_and_data("value", perf_counter->get_value()); - } - tp.add_row_name_and_data("type", dsn_counter_type_to_string(perf_counter->type())); - tp.add_row_name_and_data("description", perf_counter->dsptr()); - } - - std::ostringstream out; - tp.output(out, dsn::utils::table_printer::output_format::kJsonCompact); - resp.body = out.str(); - resp.status_code = http_status_code::ok; -} -} // namespace dsn diff --git a/src/http/test/perf_counter_http_service_test.cpp b/src/http/test/perf_counter_http_service_test.cpp deleted file mode 100644 index 0f4da2690b..0000000000 --- a/src/http/test/perf_counter_http_service_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// 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 -#include - -#include "gtest/gtest.h" -#include "http/builtin_http_calls.h" -#include "http/http_server.h" -#include "perf_counter/perf_counter.h" -#include "perf_counter/perf_counter_wrapper.h" - -namespace dsn { - -TEST(perf_counter_http_service_test, get_perf_counter) -{ - struct test_case - { - const char *app; - const char *section; - const char *name; - dsn_perf_counter_type_t type; - const char *description; - } tests[] = { - {"replica", "http", "number", COUNTER_TYPE_NUMBER, "number type"}, - {"replica", "http", "volatile", COUNTER_TYPE_VOLATILE_NUMBER, "volatile type"}, - {"replica", "http", "rate", COUNTER_TYPE_RATE, "rate type"}, - {"replica", "http", "percentline", COUNTER_TYPE_NUMBER_PERCENTILES, "percentline type"}}; - - for (auto test : tests) { - // create perf counter - perf_counter_wrapper counter; - counter.init_global_counter(test.app, test.section, test.name, test.type, test.description); - - std::string perf_counter_name; - perf_counter::build_full_name(test.app, test.section, test.name, perf_counter_name); - - // get perf counter info through the http interface - http_request fake_req; - http_response fake_resp; - fake_req.query_args.emplace("name", perf_counter_name); - get_perf_counter_handler(fake_req, fake_resp); - - // get fake json based on the perf counter info which is getting above - std::string fake_json; - if (COUNTER_TYPE_NUMBER_PERCENTILES == test.type) { - fake_json = R"({"name":")" + perf_counter_name + R"(",)" + - R"("p99":"0.00","p999":"0.00",)" + - R"("type":")" + dsn_counter_type_to_string(test.type) + R"(",)" + - R"("description":")" + test.description + R"("})" + "\n"; - } else { - fake_json = R"({"name":")" + perf_counter_name + R"(",)" + - R"("value":"0.00",)" + - R"("type":")" + dsn_counter_type_to_string(test.type) + R"(",)" + - R"("description":")" + test.description + R"("})" + "\n"; - } - - ASSERT_EQ(fake_resp.status_code, http_status_code::ok); - ASSERT_EQ(fake_resp.body, fake_json); - } -} -} // namespace dsn diff --git a/src/perf_counter/perf_counters.cpp b/src/perf_counter/perf_counters.cpp index 49482fbd27..10dfc738bf 100644 --- a/src/perf_counter/perf_counters.cpp +++ b/src/perf_counter/perf_counters.cpp @@ -242,16 +242,6 @@ bool perf_counters::remove_counter(const std::string &full_name) return true; } -perf_counter_ptr perf_counters::get_counter(const std::string &full_name) -{ - utils::auto_read_lock l(_lock); - auto it = _counters.find(full_name); - if (it != _counters.end()) - return it->second.counter; - - return nullptr; -} - perf_counter *perf_counters::new_counter(const char *app, const char *section, const char *name, diff --git a/src/perf_counter/perf_counters.h b/src/perf_counter/perf_counters.h index 6dbb942cbf..90a6c1921a 100644 --- a/src/perf_counter/perf_counters.h +++ b/src/perf_counter/perf_counters.h @@ -74,8 +74,6 @@ class perf_counters : public utils::singleton /// bool remove_counter(const std::string &full_name); - perf_counter_ptr get_counter(const std::string &full_name); - struct counter_snapshot { double value{0.0}; diff --git a/src/perf_counter/test/perf_counters_test.cpp b/src/perf_counter/test/perf_counters_test.cpp index b830d63ba3..d2016c0998 100644 --- a/src/perf_counter/test/perf_counters_test.cpp +++ b/src/perf_counter/test/perf_counters_test.cpp @@ -316,33 +316,4 @@ TEST(perf_counters_test, query_snapshot_by_regexp) ASSERT_TRUE(info.counters.empty()); } -TEST(perf_counters_test, get_by_fullname) -{ - struct test_case - { - const char *app; - const char *section; - const char *name; - dsn_perf_counter_type_t type; - const char *dsptr; - bool create; - } tests[] = {{"replica", "eon", "get_by_fullname1", COUNTER_TYPE_NUMBER, "pf1", false}, - {"replica", "eon", "get_by_fullname2", COUNTER_TYPE_NUMBER, "pf2", true}}; - - for (auto test : tests) { - // precondition: make sure the perf counter doesn't exist - std::string perf_counter_name; - perf_counter::build_full_name(test.app, test.section, test.name, perf_counter_name); - perf_counters::instance().remove_counter(perf_counter_name.c_str()); - - if (test.create) { - // create perf counter - perf_counter_wrapper counter; - counter.init_global_counter(test.app, test.section, test.name, test.type, test.dsptr); - ASSERT_NE(nullptr, perf_counters::instance().get_counter(perf_counter_name)); - } else { - ASSERT_EQ(nullptr, perf_counters::instance().get_counter(perf_counter_name)); - } - } -} } // namespace dsn