You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by la...@apache.org on 2023/06/25 15:56:14 UTC

[incubator-pegasus] branch migrate-metrics-dev updated: feat(new_metrics): remove http service for perf counters (#1540)

This is an automated email from the ASF dual-hosted git repository.

laiyingchun pushed a commit to branch migrate-metrics-dev
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/migrate-metrics-dev by this push:
     new 066f4cad1 feat(new_metrics): remove http service for perf counters (#1540)
066f4cad1 is described below

commit 066f4cad1345da2c86ab0cb552a11c34cdd2ea71
Author: Dan Wang <wa...@apache.org>
AuthorDate: Sun Jun 25 23:56:08 2023 +0800

    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 --------------------
 src/http/test/perf_counter_http_service_test.cpp | 78 ------------------------
 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, 193 deletions(-)

diff --git a/src/http/builtin_http_calls.cpp b/src/http/builtin_http_calls.cpp
index 127e57a5f..c267ae03f 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 90bbd3675..44c589ca4 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 <meta_server_ipport>/version
diff --git a/src/http/perf_counter_http_service.cpp b/src/http/perf_counter_http_service.cpp
deleted file mode 100644
index 5fcb24659..000000000
--- 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 <iosfwd>
-#include <string>
-#include <unordered_map>
-#include <utility>
-
-#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 ec447d761..000000000
--- a/src/http/test/perf_counter_http_service_test.cpp
+++ /dev/null
@@ -1,78 +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.
-
-// IWYU pragma: no_include <gtest/gtest-message.h>
-// IWYU pragma: no_include <gtest/gtest-test-part.h>
-#include <gtest/gtest.h>
-#include <string>
-#include <unordered_map>
-
-#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 49482fbd2..10dfc738b 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 6dbb942cb..90a6c1921 100644
--- a/src/perf_counter/perf_counters.h
+++ b/src/perf_counter/perf_counters.h
@@ -74,8 +74,6 @@ public:
     ///
     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 eb495ee55..c49d1dd2b 100644
--- a/src/perf_counter/test/perf_counters_test.cpp
+++ b/src/perf_counter/test/perf_counters_test.cpp
@@ -327,33 +327,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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org