From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5FAAB469710 for ; Fri, 5 Jun 2020 11:37:05 +0300 (MSK) Received: by mail-lj1-f194.google.com with SMTP id n23so10707050ljh.7 for ; Fri, 05 Jun 2020 01:37:05 -0700 (PDT) From: Ilya Konyukhov Date: Fri, 5 Jun 2020 11:35:42 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/2] feedback: determine runtime platform info List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Cc: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org This patch detect which platform instance is running on. It uses luajit `jit` module to get OS name and architecture. Se more in [docs page](https://luajit.org/ext_jit.html). Also it tries to figure out whether instance is running inside docker container or not. It's difficult know accurately but one of the most stable and simple ways at the same time is to look in [`/proc/1/cgroup`](https://stackoverflow.com/a/20012536/1881632) file. Closes #3608 Related to #4943 --- cmake/os.cmake | 2 +- src/box/lua/feedback_daemon.lua | 29 ++++++++++++++++++++++++++- test/box-tap/feedback_daemon.test.lua | 3 +-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/cmake/os.cmake b/cmake/os.cmake index 905be61df..462bdccc3 100644 --- a/cmake/os.cmake +++ b/cmake/os.cmake @@ -78,7 +78,7 @@ elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") # # Default build type is None, which uses depends by Apple -# command line tools. Also supportting install with MacPorts. +# command line tools. Also supporting install with MacPorts. # if (NOT DARWIN_BUILD_TYPE) set(DARWIN_BUILD_TYPE None CACHE STRING diff --git a/src/box/lua/feedback_daemon.lua b/src/box/lua/feedback_daemon.lua index 95130d696..2ce49fb22 100644 --- a/src/box/lua/feedback_daemon.lua +++ b/src/box/lua/feedback_daemon.lua @@ -26,13 +26,40 @@ local function get_fiber_id(f) return fid end -local function fill_in_feedback(feedback) +local function detect_docker_environment() + local fh = fio.open('/proc/1/cgroup', {'O_RDONLY'}) + if not fh then return false end + + -- fh:read() doesn't read empty files + local big_enough_chunk = 4096 + local ok = fh:read(big_enough_chunk) + fh:close() + if not ok then return false end + + if not string.find(ok, 'docker') then return false end + + return true +end + +local function fill_in_base_info(feedback) if box.info.status ~= "running" then return nil, "not running" end feedback.tarantool_version = box.info.version feedback.server_id = box.info.uuid feedback.cluster_id = box.info.cluster.uuid +end + +local function fill_in_platform_info(feedback) + feedback.os = jit.os + feedback.arch = jit.arch + feedback.is_docker = detect_docker_environment() +end + +local function fill_in_feedback(feedback) + fill_in_base_info(feedback) + fill_in_platform_info(feedback) + return feedback end diff --git a/test/box-tap/feedback_daemon.test.lua b/test/box-tap/feedback_daemon.test.lua index d4adb71f1..c36b2a694 100755 --- a/test/box-tap/feedback_daemon.test.lua +++ b/test/box-tap/feedback_daemon.test.lua @@ -131,5 +131,4 @@ daemon.start() daemon.send_test() daemon.stop() -test:check() -os.exit(0) +os.exit(test:check() and 0 or 1) -- 2.24.3 (Apple Git-128)