Skip to content

Commit

Permalink
enhance telemetry metrics (#304)
Browse files Browse the repository at this point in the history
* * add some telemetry property:
  * session uuid
  * in docker or not
  * query counter
* disable telemetry on CI
  • Loading branch information
qijun-niu-timeplus authored Nov 20, 2023
1 parent b692b5f commit aaf5d03
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 3 deletions.
37 changes: 35 additions & 2 deletions programs/server/TelemetryCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@
#include <base/getMemoryAmount.h>
#include <Common/DateLUT.h>
#include <Common/getNumberOfPhysicalCPUCores.h>
#include <Core/ServerUUID.h>
#include <IO/WriteBufferFromString.h>
#include <IO/WriteHelpers.h>
#include <Interpreters/Context.h>
#include <filesystem>

namespace fs = std::filesystem;

namespace ProfileEvents
{
extern const Event SelectQuery;
extern const Event StreamingSelectQuery;
extern const Event HistoricalSelectQuery;
}

namespace DB
{
Expand Down Expand Up @@ -77,6 +88,21 @@ void TelemetryCollector::collect()

Int64 duration_in_minute = UTCMinutes::now() - started_on_in_minutes;

DB::UUID server_uuid = DB::ServerUUID::get();
std::string server_uuid_str = server_uuid != DB::UUIDHelpers::Nil ? DB::toString(server_uuid) : "Unknown";

/// https://stackoverflow.com/questions/20010199/how-to-determine-if-a-process-runs-inside-lxc-docker
bool in_docker = fs::exists("/.dockerenv");

auto load_counter = [](const auto & event){
assert (event < ProfileEvents::end());
return ProfileEvents::global_counters[event].load(std::memory_order_relaxed);
};

const auto total_select_query = load_counter(ProfileEvents::SelectQuery);
const auto streaming_select_query = load_counter(ProfileEvents::StreamingSelectQuery);
const auto historical_select_query = load_counter(ProfileEvents::HistoricalSelectQuery);

std::string data = fmt::format("{{"
"\"type\": \"track\","
"\"event\": \"proton_ping\","
Expand All @@ -87,9 +113,16 @@ void TelemetryCollector::collect()
" \"version\": \"{}\","
" \"new_session\": \"{}\","
" \"started_on\": \"{}\","
" \"duration_in_minute\": \"{}\""
" \"duration_in_minute\": \"{}\","
" \"server_id\": \"{}\","
" \"docker\": \"{}\","
" \"total_select_query\": \"{}\","
" \"historical_select_query\": \"{}\","
" \"streaming_select_query\": \"{}\""
"}}"
"}}", cpu, memory_in_gb, EDITION, VERSION_STRING, new_session, started_on, duration_in_minute);
"}}", cpu, memory_in_gb, EDITION, VERSION_STRING, new_session, started_on, duration_in_minute, server_uuid_str, in_docker, total_select_query, historical_select_query, streaming_select_query);

LOG_TRACE(log, "Sending telemetry: {}.", data);

new_session = false;

Expand Down
2 changes: 2 additions & 0 deletions src/Common/ProfileEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#define APPLY_FOR_EVENTS(M) \
M(Query, "Number of queries to be interpreted and potentially executed. Does not include queries that failed to parse or were rejected due to AST size limits, quota limits or limits on the number of simultaneously running queries. May include internal queries initiated by proton itself. Does not count subqueries.") \
M(SelectQuery, "Same as Query, but only for SELECT queries.") \
M(StreamingSelectQuery, "Same as Query, but only for streaming SELECT queries.") \
M(HistoricalSelectQuery, "Same as Query, but only for historical SELECT queries.") \
M(InsertQuery, "Same as Query, but only for INSERT queries.") \
M(FailedQuery, "Number of failed queries.") \
M(FailedSelectQuery, "Same as FailedQuery, but only for SELECT queries.") \
Expand Down
6 changes: 5 additions & 1 deletion src/Interpreters/InterpreterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ namespace ProfileEvents
{
extern const Event Query;
extern const Event SelectQuery;
extern const Event StreamingSelectQuery;
extern const Event HistoricalSelectQuery;
extern const Event InsertQuery;
}

Expand All @@ -123,8 +125,10 @@ std::unique_ptr<IInterpreter> InterpreterFactory::get(ASTPtr & query, ContextMut
}
else if (query->as<ASTSelectWithUnionQuery>())
{
auto interpreter = std::make_unique<InterpreterSelectWithUnionQuery>(query, context, options);
ProfileEvents::increment(ProfileEvents::SelectQuery);
return std::make_unique<InterpreterSelectWithUnionQuery>(query, context, options);
ProfileEvents::increment(interpreter->isStreamingQuery() ? ProfileEvents::StreamingSelectQuery : ProfileEvents::HistoricalSelectQuery);
return std::move(interpreter);
}
else if (query->as<ASTSelectIntersectExceptQuery>())
{
Expand Down
1 change: 1 addition & 0 deletions tests/proton_ci/functional_tests_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_run_command(check_name, output_path):
env.append("-e MAX_CONCURRENT_QUERIES=200")
env.append("-e MAX_CONCURRENT_INSERT_QUERIES=200")
env.append("-e MAX_CONCURRENT_SELECT_QUERIES=200")
env.append("-e TELEMETRY_ENABLED=false")

env_str = " ".join(env)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -58,6 +59,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -89,6 +91,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -62,6 +63,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -97,6 +99,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -131,6 +134,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -165,6 +169,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down
8 changes: 8 additions & 0 deletions tests/stream/test_stream_smoke/configs/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -58,6 +59,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -90,6 +92,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -122,6 +125,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -156,6 +160,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -191,6 +196,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -225,6 +231,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -259,6 +266,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -58,6 +59,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -90,6 +92,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -121,6 +124,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -152,6 +156,7 @@ services:
- MAX_CONCURRENT_STREAMING_QUERIES=100 # Default: 100
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -185,6 +190,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -223,6 +229,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -262,6 +269,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -300,6 +308,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -338,6 +347,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -376,6 +386,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down Expand Up @@ -414,6 +425,7 @@ services:
- MAX_SERVER_MEMORY_USAGE_TO_RAM_RATIO=0.9 # Default: 0.9
- MAX_SERVER_MEMORY_CACHE_TO_RAM_RATIO=0.5 # Default: 0.5
- STREAM_STORAGE_TYPE=kafka
- TELEMETRY_ENABLED=false # Turn off telemetry on smoke test

command: >
/bin/bash -c "echo sleeping; sleep 2; /entrypoint.sh"
Expand Down

0 comments on commit aaf5d03

Please sign in to comment.