diff --git a/contrib/tiflash-proxy b/contrib/tiflash-proxy index 874c0a3b631..3fa3f4867d7 160000 --- a/contrib/tiflash-proxy +++ b/contrib/tiflash-proxy @@ -1 +1 @@ -Subproject commit 874c0a3b63190e82fe05dc1c939312c08afaa199 +Subproject commit 3fa3f4867d77187a48d69e5b2e08b398ebe22f00 diff --git a/dbms/src/Flash/LogSearch.cpp b/dbms/src/Flash/LogSearch.cpp index 23f89e8ac67..64b1bd2dfcd 100644 --- a/dbms/src/Flash/LogSearch.cpp +++ b/dbms/src/Flash/LogSearch.cpp @@ -410,9 +410,11 @@ bool FilterFileByDatetime( const int64_t start_time) { static const std::string date_format_example = "0000-00-00-00:00:00.000"; - static const std::string raftstore_proxy_date_format_example = "0000-00-00-00:00:00.000000000"; static const char * date_format = "%d-%d-%d-%d:%d:%d.%d"; + static const std::string raftstore_proxy_date_format_example = "0000-00-00T00:00:00.000.log"; + static const char * raftstore_proxy_date_format = "%d-%d-%dT%d-%d-%d.%d"; + for (const auto & ignore_log_file_prefix : ignore_log_file_prefixes) { if (!ignore_log_file_prefix.empty() && startsWith(path, ignore_log_file_prefix)) @@ -441,7 +443,7 @@ bool FilterFileByDatetime( else { // filter proxy log end datetime - return filterLogEndDatetime(path, raftstore_proxy_date_format_example, date_format, start_time); + return filterLogEndDatetime(path, raftstore_proxy_date_format_example, raftstore_proxy_date_format, start_time); } } diff --git a/dbms/src/Flash/tests/gtest_log_search.cpp b/dbms/src/Flash/tests/gtest_log_search.cpp index 87334dfb30c..07f6d190aad 100644 --- a/dbms/src/Flash/tests/gtest_log_search.cpp +++ b/dbms/src/Flash/tests/gtest_log_search.cpp @@ -123,7 +123,7 @@ TEST_F(LogSearchTest, SearchDir) ASSERT_TRUE(FilterFileByDatetime("/1/server.log.2021-10-09-14:50:55.481.gz", {"/1/test-err.log"}, 1633855377000)); // 1633855377000 : 2021-10-10 16:42:57 ASSERT_FALSE(FilterFileByDatetime("/1/server.log.2021-10-10-16:43:57.123.gz", {"/1/test-err.log"}, 1633855377000)); - ASSERT_TRUE(FilterFileByDatetime("/1/proxy.log.2021-10-09-14:50:55.123456789", {"/1/test-err.log"}, 1633855377000)); + ASSERT_TRUE(FilterFileByDatetime("/1/tiflash_tikv.2021-10-09T14-50-55.123.log", {"/1/test-err.log"}, 1633855377000)); { const std::string example_data = "[2020/04/23 13:11:02.329 +08:00] [DEBUG] [\"Application : Load metadata done.\"]\n"; diff --git a/dbms/src/Server/MetricsPrometheus.cpp b/dbms/src/Server/MetricsPrometheus.cpp index c195722e2fd..78a4af15197 100644 --- a/dbms/src/Server/MetricsPrometheus.cpp +++ b/dbms/src/Server/MetricsPrometheus.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 PingCAP, Ltd. +// Copyright 2023 PingCAP, Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -103,7 +103,7 @@ class MetricHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory std::shared_ptr getHTTPServer( const TiFlashSecurityConfig & security_config, const std::weak_ptr & collectable, - const String & metrics_port) + const String & address) { Poco::Net::Context::Ptr context = new Poco::Net::Context( Poco::Net::Context::TLSV1_2_SERVER_USE, @@ -125,8 +125,7 @@ std::shared_ptr getHTTPServer( Poco::Net::SecureServerSocket socket(context); Poco::Net::HTTPServerParams::Ptr http_params = new Poco::Net::HTTPServerParams; - - Poco::Net::SocketAddress addr("0.0.0.0", std::stoi(metrics_port)); + Poco::Net::SocketAddress addr = Poco::Net::SocketAddress(address); socket.bind(addr, true); socket.listen(); auto server = std::make_shared(new MetricHandlerFactory(collectable), socket, http_params); @@ -136,6 +135,17 @@ std::shared_ptr getHTTPServer( constexpr Int64 MILLISECOND = 1000; constexpr Int64 INIT_DELAY = 5; +namespace +{ +inline bool isIPv6(const String & input_address) +{ + if (input_address.empty()) + return false; + char str[INET6_ADDRSTRLEN]; + return inet_pton(AF_INET6, input_address.c_str(), str) == 1; +} +} // namespace + MetricsPrometheus::MetricsPrometheus( Context & context, const AsynchronousMetrics & async_metrics_, @@ -202,17 +212,23 @@ MetricsPrometheus::MetricsPrometheus( if (conf.hasOption(status_metrics_port) || !conf.hasOption(status_metrics_addr)) { auto metrics_port = conf.getString(status_metrics_port, DB::toString(DEFAULT_METRICS_PORT)); + auto listen_host = conf.getString("listen_host", "0.0.0.0"); + String addr; + if (isIPv6(listen_host)) + addr = "[" + listen_host + "]:" + metrics_port; + else + addr = listen_host + ":" + metrics_port; if (security_config.has_tls_config) { - server = getHTTPServer(security_config, tiflash_metrics.registry, metrics_port); + server = getHTTPServer(security_config, tiflash_metrics.registry, addr); server->start(); - LOG_INFO(log, "Enable prometheus secure pull mode; Metrics Port = {}", metrics_port); + LOG_INFO(log, "Enable prometheus secure pull mode; Listen Host = {}, Metrics Port = {}", listen_host, metrics_port); } else { - exposer = std::make_shared(metrics_port); + exposer = std::make_shared(addr); exposer->RegisterCollectable(tiflash_metrics.registry); - LOG_INFO(log, "Enable prometheus pull mode; Metrics Port = {}", metrics_port); + LOG_INFO(log, "Enable prometheus pull mode; Listen Host = {}, Metrics Port = {}", listen_host, metrics_port); } } else diff --git a/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp b/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp index c70acce453c..8f75c3f7a18 100644 --- a/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp +++ b/dbms/src/Storages/DeltaMerge/DeltaMergeStore_InternalBg.cpp @@ -595,7 +595,7 @@ SegmentPtr DeltaMergeStore::gcTrySegmentMerge(const DMContextPtr & dm_context, c auto new_segment = segmentMerge(*dm_context, segments_to_merge, SegmentMergeReason::BackgroundGCThread); if (new_segment) { - checkSegmentUpdate(dm_context, segment, ThreadType::BG_GC); + checkSegmentUpdate(dm_context, new_segment, ThreadType::BG_GC); } return new_segment; @@ -718,7 +718,7 @@ SegmentPtr DeltaMergeStore::gcTrySegmentMergeDelta(const DMContextPtr & dm_conte } segment_snap = {}; - checkSegmentUpdate(dm_context, segment, ThreadType::BG_GC); + checkSegmentUpdate(dm_context, new_segment, ThreadType::BG_GC); return new_segment; }