From d5563c78742f8d4677a62119755f4f39590cff9d Mon Sep 17 00:00:00 2001
From: Dan Wang <wangdan@apache.org>
Date: Tue, 27 Jun 2023 16:12:00 +0800
Subject: [PATCH] feat(new_metrics): remove pegasus_counter_reporter (#1548)

https://github.com/apache/incubator-pegasus/issues/1547

Since perf counters would be removed, `pegasus_counter_reporter` would
not be used to collect metrics to target monitoring system, thus could be
removed.
---
 src/CMakeLists.txt                        |   1 -
 src/redis_protocol/proxy/CMakeLists.txt   |   1 -
 src/redis_protocol/proxy/main.cpp         |   3 -
 src/reporter/CMakeLists.txt               |  44 ---
 src/reporter/pegasus_counter_reporter.cpp | 381 ----------------------
 src/reporter/pegasus_counter_reporter.h   | 119 -------
 src/reporter/pegasus_io_service.h         |  65 ----
 src/server/CMakeLists.txt                 |   1 -
 src/server/info_collector_app.cpp         |  11 +-
 src/server/info_collector_app.h           |   1 -
 src/server/pegasus_service_app.h          |  13 -
 src/server/test/CMakeLists.txt            |   1 -
 12 files changed, 1 insertion(+), 640 deletions(-)
 delete mode 100644 src/reporter/CMakeLists.txt
 delete mode 100644 src/reporter/pegasus_counter_reporter.cpp
 delete mode 100644 src/reporter/pegasus_counter_reporter.h
 delete mode 100644 src/reporter/pegasus_io_service.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4cd73096a8..00b8a0914d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -48,7 +48,6 @@ add_subdirectory(perf_counter)
 add_subdirectory(redis_protocol)
 add_subdirectory(remote_cmd)
 add_subdirectory(replica)
-add_subdirectory(reporter)
 add_subdirectory(runtime)
 add_subdirectory(sample)
 add_subdirectory(server)
diff --git a/src/redis_protocol/proxy/CMakeLists.txt b/src/redis_protocol/proxy/CMakeLists.txt
index 956ccce76c..b741360568 100644
--- a/src/redis_protocol/proxy/CMakeLists.txt
+++ b/src/redis_protocol/proxy/CMakeLists.txt
@@ -30,7 +30,6 @@ set(MY_PROJ_LIBS pegasus.rproxylib
                  absl::flat_hash_set
                  absl::strings
                  pegasus_geo_lib
-                 pegasus_reporter
                  event
                  s2
                  pegasus_client_static
diff --git a/src/redis_protocol/proxy/main.cpp b/src/redis_protocol/proxy/main.cpp
index 21de0aa583..0d3c0b9bc5 100644
--- a/src/redis_protocol/proxy/main.cpp
+++ b/src/redis_protocol/proxy/main.cpp
@@ -27,7 +27,6 @@
 
 #include "proxy_layer.h"
 #include "redis_parser.h"
-#include "reporter/pegasus_counter_reporter.h"
 #include "runtime/app_model.h"
 #include "runtime/service_app.h"
 #include "utils/error_code.h"
@@ -57,8 +56,6 @@ class proxy_app : public ::dsn::service_app
         _proxy = std::make_unique<proxy_stub>(
             f, args[1].c_str(), args[2].c_str(), args.size() > 3 ? args[3].c_str() : "");
 
-        pegasus::server::pegasus_counter_reporter::instance().start();
-
         return ::dsn::ERR_OK;
     }
 
diff --git a/src/reporter/CMakeLists.txt b/src/reporter/CMakeLists.txt
deleted file mode 100644
index 80b4b5b6f4..0000000000
--- a/src/reporter/CMakeLists.txt
+++ /dev/null
@@ -1,44 +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.
-
-set(MY_PROJ_NAME "pegasus_reporter")
-project(${MY_PROJ_NAME} C CXX)
-
-# Source files under CURRENT project directory will be automatically included.
-# You can manually set MY_PROJ_SRC to include source files under other directories.
-set(MY_PROJ_SRC "")
-
-# Search mode for source files under CURRENT project directory?
-# "GLOB_RECURSE" for recursive search
-# "GLOB" for non-recursive search
-set(MY_SRC_SEARCH_MODE "GLOB")
-
-# prometheus
-set(CMAKE_PREFIX_PATH ${THIRDPARTY_INSTALL_DIR};${CMAKE_PREFIX_PATH})
-find_package(prometheus-cpp)#TODO(huangwei5): make it optional
-# the INTERFACE_LINK_LIBRARIES of prometheus contains the absolute path of libcurl
-# when we use the compiled prometheus-cpp libs, the path of libcurl should be our own path
-find_package(CURL)
-get_target_property(_libs prometheus-cpp::pull INTERFACE_LINK_LIBRARIES)
-string(REGEX REPLACE ";/.*libcurl\.a" ";${CURL_LIBRARIES}" _libs "${_libs}")
-set_target_properties(prometheus-cpp::pull PROPERTIES INTERFACE_LINK_LIBRARIES "${_libs}")
-
-dsn_add_static_library()
-
-target_link_libraries(${MY_PROJ_NAME} PUBLIC pegasus_base
-                                            prometheus-cpp::pull
-                                            ) # TODO(huangwei5): dsn_add_static_library doesnt link libs, need fix
diff --git a/src/reporter/pegasus_counter_reporter.cpp b/src/reporter/pegasus_counter_reporter.cpp
deleted file mode 100644
index f7c902a04a..0000000000
--- a/src/reporter/pegasus_counter_reporter.cpp
+++ /dev/null
@@ -1,381 +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 "pegasus_counter_reporter.h"
-
-#include <alloca.h>
-#include <boost/asio.hpp> // IWYU pragma: keep
-#include <boost/asio/basic_deadline_timer.hpp>
-#include <boost/asio/detail/impl/epoll_reactor.hpp>
-#include <boost/asio/detail/impl/timer_queue_ptime.ipp>
-#include <boost/date_time/posix_time/posix_time_duration.hpp>
-#include <boost/system/error_code.hpp>
-#include <event2/buffer.h>
-#include <event2/event.h>
-#include <fmt/core.h>
-#include <prometheus/detail/gauge_builder.h>
-#include <prometheus/exposer.h>
-#include <prometheus/family.h>
-#include <prometheus/gauge.h>
-#include <prometheus/registry.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <algorithm>
-#include <functional>
-#include <iomanip>
-#include <ios>
-#include <iostream>
-#include <list>
-#include <map>
-#include <memory>
-#include <new>
-#include <string>
-#include <type_traits>
-#include <utility>
-
-#include "base/pegasus_utils.h"
-#include "common/common.h"
-#include "pegasus_io_service.h"
-#include "perf_counter/perf_counter.h"
-#include "perf_counter/perf_counters.h"
-#include "runtime/api_layer1.h"
-#include "runtime/rpc/rpc_address.h"
-#include "runtime/service_app.h"
-#include "utils/api_utilities.h"
-#include "utils/flags.h"
-#include "utils/fmt_logging.h"
-#include "utils/strings.h"
-
-DSN_DEFINE_uint64(pegasus.server,
-                  perf_counter_update_interval_seconds,
-                  10,
-                  "perf_counter_update_interval_seconds");
-DSN_DEFINE_bool(pegasus.server, perf_counter_enable_logging, true, "perf_counter_enable_logging");
-
-DSN_DEFINE_string(pegasus.server, perf_counter_sink, "", "perf_counter_sink");
-
-DSN_DEFINE_uint64(pegasus.server, prometheus_port, 9091, "prometheus exposer port");
-
-DSN_DEFINE_string(pegasus.server, falcon_host, "127.0.0.1", "falcon agent host");
-DSN_DEFINE_uint64(pegasus.server, falcon_port, 1988, "falcon agent port");
-DSN_DEFINE_string(pegasus.server, falcon_path, "/v1/push", "falcon agent http path");
-
-namespace pegasus {
-namespace server {
-
-static std::string get_hostname()
-{
-    char hostname[1024];
-
-    if (::gethostname(hostname, sizeof(hostname))) {
-        return {};
-    }
-    return hostname;
-}
-
-static void format_metrics_name(std::string &metrics_name)
-{
-    replace(metrics_name.begin(), metrics_name.end(), '@', ':');
-    replace(metrics_name.begin(), metrics_name.end(), '#', ':');
-    replace(metrics_name.begin(), metrics_name.end(), '.', '_');
-    replace(metrics_name.begin(), metrics_name.end(), '*', '_');
-    replace(metrics_name.begin(), metrics_name.end(), '(', '_');
-    replace(metrics_name.begin(), metrics_name.end(), ')', '_');
-}
-
-static void libevent_log(int severity, const char *msg)
-{
-    dsn_log_level_t level;
-    if (severity == EVENT_LOG_DEBUG)
-        level = LOG_LEVEL_DEBUG;
-    else if (severity == EVENT_LOG_MSG)
-        level = LOG_LEVEL_INFO;
-    else if (severity == EVENT_LOG_WARN)
-        level = LOG_LEVEL_WARNING;
-    else
-        level = LOG_LEVEL_ERROR;
-    dlog(level, msg);
-}
-
-pegasus_counter_reporter::pegasus_counter_reporter()
-    : _local_port(0), _last_report_time_ms(0), _perf_counter_sink(perf_counter_sink_t::INVALID)
-{
-}
-
-pegasus_counter_reporter::~pegasus_counter_reporter() { stop(); }
-
-void pegasus_counter_reporter::prometheus_initialize()
-{
-    _registry = std::make_shared<prometheus::Registry>();
-    _exposer =
-        std::make_unique<prometheus::Exposer>(fmt::format("0.0.0.0:{}", FLAGS_prometheus_port));
-    _exposer->RegisterCollectable(_registry);
-
-    LOG_INFO("prometheus exposer [0.0.0.0:{}] started", FLAGS_prometheus_port);
-}
-
-void pegasus_counter_reporter::falcon_initialize()
-{
-    _falcon_metric.endpoint = _local_host;
-    _falcon_metric.step = FLAGS_perf_counter_update_interval_seconds;
-    _falcon_metric.tags = fmt::format(
-        "service=pegasus,cluster={},job={},port={}", _cluster_name, _app_name, _local_port);
-
-    LOG_INFO(
-        "falcon initialize: endpoint({}), tag({})", _falcon_metric.endpoint, _falcon_metric.tags);
-}
-
-void pegasus_counter_reporter::start()
-{
-    ::dsn::utils::auto_write_lock l(_lock);
-    if (_report_timer != nullptr)
-        return;
-
-    dsn::rpc_address addr(dsn_primary_address());
-    char buf[1000];
-    pegasus::utils::addr2host(addr, buf, 1000);
-    _local_host = buf;
-    _local_port = addr.port();
-
-    _app_name = dsn::service_app::current_service_app_info().full_name;
-
-    _cluster_name = dsn::get_current_cluster_name();
-
-    _last_report_time_ms = dsn_now_ms();
-
-    if (dsn::utils::iequals("prometheus", FLAGS_perf_counter_sink)) {
-        _perf_counter_sink = perf_counter_sink_t::PROMETHEUS;
-    } else if (dsn::utils::iequals("falcon", FLAGS_perf_counter_sink)) {
-        _perf_counter_sink = perf_counter_sink_t::FALCON;
-    } else {
-        _perf_counter_sink = perf_counter_sink_t::INVALID;
-    }
-
-    if (perf_counter_sink_t::FALCON == _perf_counter_sink) {
-        falcon_initialize();
-    }
-
-    if (perf_counter_sink_t::PROMETHEUS == _perf_counter_sink) {
-        prometheus_initialize();
-    }
-
-    event_set_log_callback(libevent_log);
-
-    _report_timer.reset(new boost::asio::deadline_timer(pegasus_io_service::instance().ios));
-    _report_timer->expires_from_now(
-        boost::posix_time::seconds(rand() % FLAGS_perf_counter_update_interval_seconds + 1));
-    _report_timer->async_wait(std::bind(
-        &pegasus_counter_reporter::on_report_timer, this, _report_timer, std::placeholders::_1));
-}
-
-void pegasus_counter_reporter::stop()
-{
-    ::dsn::utils::auto_write_lock l(_lock);
-    if (_report_timer != nullptr) {
-        _report_timer->cancel();
-    }
-    _exposer = nullptr;
-    _registry = nullptr;
-}
-
-void pegasus_counter_reporter::update_counters_to_falcon(const std::string &result,
-                                                         int64_t timestamp)
-{
-    LOG_INFO("update counters to falcon with timestamp = {}", timestamp);
-    http_post_request(FLAGS_falcon_host,
-                      FLAGS_falcon_port,
-                      FLAGS_falcon_path,
-                      "application/x-www-form-urlencoded",
-                      result);
-}
-
-void pegasus_counter_reporter::update()
-{
-    uint64_t now = dsn_now_ms();
-    int64_t timestamp = now / 1000;
-
-    dsn::perf_counters::instance().take_snapshot();
-
-    if (FLAGS_perf_counter_enable_logging) {
-        std::stringstream oss;
-        oss << "logging perf counter(name, type, value):" << std::endl;
-        oss << std::fixed << std::setprecision(2);
-        dsn::perf_counters::instance().iterate_snapshot(
-            [&oss](const dsn::perf_counters::counter_snapshot &cs) {
-                oss << "[" << cs.name << ", " << dsn_counter_type_to_string(cs.type) << ", "
-                    << cs.value << "]" << std::endl;
-            });
-        LOG_INFO("{}", oss.str());
-    }
-
-    if (perf_counter_sink_t::FALCON == _perf_counter_sink) {
-        std::stringstream oss;
-        oss << "[";
-
-        bool first_append = true;
-        _falcon_metric.timestamp = timestamp;
-
-        dsn::perf_counters::instance().iterate_snapshot(
-            [&oss, &first_append, this](const dsn::perf_counters::counter_snapshot &cs) {
-                _falcon_metric.metric = cs.name;
-                _falcon_metric.value = cs.value;
-                _falcon_metric.counterType = "GAUGE";
-
-                if (!first_append)
-                    oss << ",";
-                _falcon_metric.encode_json_state(oss);
-                first_append = false;
-            });
-        oss << "]";
-        update_counters_to_falcon(oss.str(), timestamp);
-    }
-
-    if (perf_counter_sink_t::PROMETHEUS == _perf_counter_sink) {
-        const std::string hostname = get_hostname();
-        dsn::perf_counters::instance().iterate_snapshot([&hostname, this](
-            const dsn::perf_counters::counter_snapshot &cs) {
-            std::string metrics_name = cs.name;
-
-            // Splits metric_name like:
-            //   "collector*app.pegasus*app_stat_multi_put_qps@1.0.p999"
-            //   "collector*app.pegasus*app_stat_multi_put_qps@1.0"
-            // app[0] = "1" which is the app(app name or app id)
-            // app[1] = "0" which is the partition_index
-            // app[2] = "p999" or "" which represent the percent
-            std::string app[3] = {"", "", ""};
-            std::list<std::string> lv;
-            ::dsn::utils::split_args(metrics_name.c_str(), lv, '@');
-            if (lv.size() > 1) {
-                std::list<std::string> lv1;
-                ::dsn::utils::split_args(lv.back().c_str(), lv1, '.');
-                CHECK_LE(lv1.size(), 3);
-                int i = 0;
-                for (auto &v : lv1) {
-                    app[i] = v;
-                    i++;
-                }
-            }
-            /**
-             * deal with corner case, for example:
-             *  replica*eon.replica*table.level.RPC_RRDB_RRDB_GET.latency(ns)@${table_name}.p999
-             * in this case, app[0] = app name, app[1] = p999, app[2] = ""
-             **/
-            if ("p999" == app[1]) {
-                app[2] = app[1];
-                app[1].clear();
-            }
-
-            // create metrics that prometheus support to report data
-            metrics_name = lv.front() + app[2];
-
-            // prometheus metric_name doesn't support characters like .*()@, it only supports ":"
-            // and "_" so change the name to make it all right.
-            format_metrics_name(metrics_name);
-
-            std::map<std::string, prometheus::Family<prometheus::Gauge> *>::iterator it =
-                _gauge_family_map.find(metrics_name);
-            if (it == _gauge_family_map.end()) {
-                auto &add_gauge_family = prometheus::BuildGauge()
-                                             .Name(metrics_name)
-                                             .Labels({{"service", "pegasus"},
-                                                      {"host_name", hostname},
-                                                      {"cluster", _cluster_name},
-                                                      {"pegasus_job", _app_name},
-                                                      {"port", std::to_string(_local_port)}})
-                                             .Register(*_registry);
-                it = _gauge_family_map
-                         .insert(std::pair<std::string, prometheus::Family<prometheus::Gauge> *>(
-                             metrics_name, &add_gauge_family))
-                         .first;
-            }
-
-            auto &second_gauge = it->second->Add({{"app", app[0]}, {"partition", app[1]}});
-            second_gauge.Set(cs.value);
-        });
-    }
-
-    LOG_INFO("update now_ms({}), last_report_time_ms({})", now, _last_report_time_ms);
-    _last_report_time_ms = now;
-}
-
-void pegasus_counter_reporter::http_post_request(const std::string &host,
-                                                 int32_t port,
-                                                 const std::string &path,
-                                                 const std::string &contentType,
-                                                 const std::string &data)
-{
-    LOG_DEBUG("start update_request: {}", data);
-    struct event_base *base = event_base_new();
-    struct evhttp_connection *conn = evhttp_connection_base_new(base, nullptr, host.c_str(), port);
-    struct evhttp_request *req =
-        evhttp_request_new(pegasus_counter_reporter::http_request_done, base);
-
-    evhttp_add_header(req->output_headers, "Host", host.c_str());
-    evhttp_add_header(req->output_headers, "Content-Type", contentType.c_str());
-    evbuffer_add(req->output_buffer, data.c_str(), data.size());
-    evhttp_connection_set_timeout(conn, 1);
-    evhttp_make_request(conn, req, EVHTTP_REQ_POST, path.c_str());
-
-    event_base_dispatch(base);
-
-    // clear;
-    evhttp_connection_free(conn);
-    event_base_free(base);
-}
-
-void pegasus_counter_reporter::http_request_done(struct evhttp_request *req, void *arg)
-{
-    struct event_base *event = (struct event_base *)arg;
-    if (req == nullptr) {
-        LOG_ERROR("http post request failed: unknown reason");
-    } else if (req->response_code == 0) {
-        LOG_ERROR("http post request failed: connection refused");
-    } else if (req->response_code == HTTP_OK) {
-        LOG_DEBUG("http post request succeed");
-    } else {
-        struct evbuffer *buf = evhttp_request_get_input_buffer(req);
-        size_t len = evbuffer_get_length(buf);
-        char *tmp = (char *)alloca(len + 1);
-        memcpy(tmp, evbuffer_pullup(buf, -1), len);
-        tmp[len] = '\0';
-        LOG_ERROR("http post request failed: code = {}, code_line = {}, input_buffer = {}",
-                  req->response_code,
-                  req->response_code_line,
-                  tmp);
-    }
-    event_base_loopexit(event, 0);
-}
-
-void pegasus_counter_reporter::on_report_timer(std::shared_ptr<boost::asio::deadline_timer> timer,
-                                               const boost::system::error_code &ec)
-{
-    // NOTICE: the following code is running out of rDSN's tls_context
-    if (!ec) {
-        update();
-        timer->expires_from_now(
-            boost::posix_time::seconds(FLAGS_perf_counter_update_interval_seconds));
-        timer->async_wait(std::bind(
-            &pegasus_counter_reporter::on_report_timer, this, timer, std::placeholders::_1));
-    } else if (boost::system::errc::operation_canceled != ec) {
-        CHECK(false, "pegasus report timer error!!!");
-    }
-}
-} // namespace server
-} // namespace pegasus
diff --git a/src/reporter/pegasus_counter_reporter.h b/src/reporter/pegasus_counter_reporter.h
deleted file mode 100644
index 4a1e97ea04..0000000000
--- a/src/reporter/pegasus_counter_reporter.h
+++ /dev/null
@@ -1,119 +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.
- */
-
-#pragma once
-
-#include <boost/asio/deadline_timer.hpp>
-#include <event2/http.h>        // IWYU pragma: keep
-#include <event2/http_struct.h> // IWYU pragma: keep
-#include <stdint.h>
-#include <map>
-#include <memory>
-#include <string>
-
-#include "common/json_helper.h"
-#include "utils/singleton.h"
-#include "utils/synchronize.h"
-
-namespace boost {
-namespace system {
-class error_code;
-} // namespace system
-} // namespace boost
-namespace prometheus {
-class Exposer;
-class Gauge;
-class Registry;
-template <typename T>
-class Family;
-} // namespace prometheus
-
-namespace pegasus {
-namespace server {
-
-// Falcon field description:
-//   https://book.open-falcon.org/zh/philosophy/data-model.html
-struct falcon_metric
-{
-    std::string endpoint;    // metric host
-    std::string metric;      // metric name
-    int64_t timestamp;       // report time in unix seconds
-    int32_t step;            // report interval in seconds
-    double value;            // metric value
-    std::string counterType; // GAUGE or COUNTER
-    std::string tags;        // metric description, such as cluster/service
-    DEFINE_JSON_SERIALIZATION(endpoint, metric, timestamp, step, value, counterType, tags)
-};
-
-enum class perf_counter_sink_t
-{
-    FALCON,
-    PROMETHEUS,
-    INVALID
-};
-
-class pegasus_counter_reporter : public dsn::utils::singleton<pegasus_counter_reporter>
-{
-public:
-    void start();
-    void stop();
-
-private:
-    pegasus_counter_reporter();
-    virtual ~pegasus_counter_reporter();
-
-    void falcon_initialize();
-    void prometheus_initialize();
-
-    void update_counters_to_falcon(const std::string &result, int64_t timestamp);
-
-    void http_post_request(const std::string &host,
-                           int32_t port,
-                           const std::string &path,
-                           const std::string &content_type,
-                           const std::string &data);
-    static void http_request_done(struct evhttp_request *req, void *arg);
-
-    void update();
-    void on_report_timer(std::shared_ptr<boost::asio::deadline_timer> timer,
-                         const boost::system::error_code &ec);
-
-    mutable ::dsn::utils::rw_lock_nr _lock;
-    std::string _local_host;
-    uint16_t _local_port;
-    std::string _app_name;
-    std::string _cluster_name;
-
-    uint64_t _last_report_time_ms;
-    std::shared_ptr<boost::asio::deadline_timer> _report_timer;
-
-    // perf counter flags
-    perf_counter_sink_t _perf_counter_sink;
-
-    falcon_metric _falcon_metric;
-
-    // prometheus relates
-    std::shared_ptr<prometheus::Registry> _registry;
-    std::unique_ptr<prometheus::Exposer> _exposer;
-    std::map<std::string, prometheus::Family<prometheus::Gauge> *> _gauge_family_map;
-
-    friend class dsn::utils::singleton<pegasus_counter_reporter>;
-};
-} // namespace server
-} // namespace pegasus
diff --git a/src/reporter/pegasus_io_service.h b/src/reporter/pegasus_io_service.h
deleted file mode 100644
index 03e27330fb..0000000000
--- a/src/reporter/pegasus_io_service.h
+++ /dev/null
@@ -1,65 +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.
- */
-
-#pragma once
-
-#include <boost/asio.hpp>
-#include <thread>
-#include <memory>
-#include <vector>
-#include "utils/singleton.h"
-
-namespace pegasus {
-namespace server {
-
-// TODO: seperate this into per-node service, so we can use
-// task::get_current_node for faster access to the nodes in all tasks
-// coz tasks may run in io-threads when [task.xxx] allow_inline is true
-class pegasus_io_service : public dsn::utils::singleton<pegasus_io_service>
-{
-public:
-    boost::asio::io_service ios;
-
-private:
-    pegasus_io_service()
-    {
-        _io_service_worker_count = 2;
-        for (int i = 0; i < _io_service_worker_count; i++) {
-            _workers.push_back(std::shared_ptr<std::thread>(new std::thread([this]() {
-                boost::asio::io_service::work work(ios);
-                ios.run();
-            })));
-        }
-    }
-
-    ~pegasus_io_service()
-    {
-        ios.stop();
-        for (auto worker : _workers) {
-            worker->join();
-        }
-    }
-
-    int _io_service_worker_count;
-    std::vector<std::shared_ptr<std::thread>> _workers;
-
-    friend class dsn::utils::singleton<pegasus_io_service>;
-};
-} // namespace server
-} // namespace pegasus
diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt
index ff48c181e3..d19408e276 100644
--- a/src/server/CMakeLists.txt
+++ b/src/server/CMakeLists.txt
@@ -37,7 +37,6 @@ set(MY_PROJ_LIBS
     dsn.replication.zookeeper_provider
     dsn_utils
     RocksDB::rocksdb
-    pegasus_reporter
     pegasus_base
     pegasus_client_static
     event
diff --git a/src/server/info_collector_app.cpp b/src/server/info_collector_app.cpp
index 0a40d5a4f0..398f8bd5b1 100644
--- a/src/server/info_collector_app.cpp
+++ b/src/server/info_collector_app.cpp
@@ -20,7 +20,6 @@
 #include "info_collector_app.h"
 
 #include "http/http_server.h"
-#include "reporter/pegasus_counter_reporter.h"
 #include "runtime/service_app.h"
 #include "server/available_detector.h"
 #include "server/info_collector.h"
@@ -33,8 +32,7 @@ class collector_http_service : public ::dsn::http_server_base
 {
 };
 
-info_collector_app::info_collector_app(const dsn::service_app_info *info)
-    : service_app(info), _updater_started(false)
+info_collector_app::info_collector_app(const dsn::service_app_info *info) : service_app(info)
 {
     register_http_service(new collector_http_service());
     dsn::start_http_server();
@@ -44,9 +42,6 @@ info_collector_app::~info_collector_app() {}
 
 ::dsn::error_code info_collector_app::start(const std::vector<std::string> &args)
 {
-    pegasus_counter_reporter::instance().start();
-    _updater_started = true;
-
     _collector.start();
     _detector.start();
     return ::dsn::ERR_OK;
@@ -54,10 +49,6 @@ ::dsn::error_code info_collector_app::start(const std::vector<std::string> &args
 
 ::dsn::error_code info_collector_app::stop(bool cleanup)
 {
-    if (_updater_started) {
-        pegasus_counter_reporter::instance().stop();
-    }
-
     _collector.stop();
     _detector.stop();
     return ::dsn::ERR_OK;
diff --git a/src/server/info_collector_app.h b/src/server/info_collector_app.h
index e21d9ca148..b731f0e483 100644
--- a/src/server/info_collector_app.h
+++ b/src/server/info_collector_app.h
@@ -42,7 +42,6 @@ class info_collector_app : public ::dsn::service_app
 private:
     info_collector _collector;
     available_detector _detector;
-    bool _updater_started;
 };
 }
 } // namespace
diff --git a/src/server/pegasus_service_app.h b/src/server/pegasus_service_app.h
index c581ecae0e..6d5eda6ac0 100644
--- a/src/server/pegasus_service_app.h
+++ b/src/server/pegasus_service_app.h
@@ -23,7 +23,6 @@
 #include "replica/replication_service_app.h"
 #include <pegasus/version.h>
 #include <pegasus/git_commit.h>
-#include "reporter/pegasus_counter_reporter.h"
 #include "utils/builtin_metrics.h"
 
 namespace pegasus {
@@ -49,9 +48,6 @@ class pegasus_replication_service_app : public ::dsn::replication::replication_s
         // built-in metrics) are started.
         CHECK_EQ(::dsn::replication::replication_service_app::start(args_new), ::dsn::ERR_OK);
 
-        // TODO(wangdan): remove after all metrics have been migrated.
-        pegasus_counter_reporter::instance().start();
-
         _builtin_metrics.start();
         return ::dsn::ERR_OK;
     }
@@ -60,9 +56,6 @@ class pegasus_replication_service_app : public ::dsn::replication::replication_s
     {
         ::dsn::error_code ret = ::dsn::replication::replication_service_app::stop();
 
-        // TODO(wangdan): remove after all metrics have been migrated.
-        pegasus_counter_reporter::instance().stop();
-
         _builtin_metrics.stop();
         return ret;
     }
@@ -91,9 +84,6 @@ class pegasus_meta_service_app : public ::dsn::service::meta_service_app
         // built-in metrics) are started.
         CHECK_EQ(::dsn::service::meta_service_app::start(args_new), ::dsn::ERR_OK);
 
-        // TODO(wangdan): remove after all metrics have been migrated.
-        pegasus_counter_reporter::instance().start();
-
         _builtin_metrics.start();
         return ::dsn::ERR_OK;
     }
@@ -102,9 +92,6 @@ class pegasus_meta_service_app : public ::dsn::service::meta_service_app
     {
         ::dsn::error_code ret = ::dsn::service::meta_service_app::stop();
 
-        // TODO(wangdan): remove after all metrics have been migrated.
-        pegasus_counter_reporter::instance().stop();
-
         _builtin_metrics.stop();
         return ret;
     }
diff --git a/src/server/test/CMakeLists.txt b/src/server/test/CMakeLists.txt
index e9b9200f3e..8a2fbd6f1c 100644
--- a/src/server/test/CMakeLists.txt
+++ b/src/server/test/CMakeLists.txt
@@ -45,7 +45,6 @@ set(MY_PROJ_LIBS
         dsn.failure_detector
         dsn.replication.zookeeper_provider
         dsn_utils
-        pegasus_reporter
         RocksDB::rocksdb
         pegasus_client_static
         event