mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-12 17:32:32 +00:00
Merge pull request #72637 from ClickHouse/startup-scripts-execution-state
add `StartupScriptsExecutionState` metric
This commit is contained in:
commit
4346ccb434
@ -296,6 +296,7 @@ namespace CurrentMetrics
|
||||
extern const Metric MergesMutationsMemoryTracking;
|
||||
extern const Metric MaxDDLEntryID;
|
||||
extern const Metric MaxPushedDDLEntryID;
|
||||
extern const Metric StartupScriptsExecutionState;
|
||||
}
|
||||
|
||||
namespace ProfileEvents
|
||||
@ -366,6 +367,14 @@ namespace ErrorCodes
|
||||
}
|
||||
|
||||
|
||||
enum StartupScriptsExecutionState : CurrentMetrics::Value
|
||||
{
|
||||
NotFinished = 0,
|
||||
Success = 1,
|
||||
Failure = 2,
|
||||
};
|
||||
|
||||
|
||||
static std::string getCanonicalPath(std::string && path)
|
||||
{
|
||||
Poco::trimInPlace(path);
|
||||
@ -782,9 +791,12 @@ void loadStartupScripts(const Poco::Util::AbstractConfiguration & config, Contex
|
||||
startup_context->makeQueryContext();
|
||||
executeQuery(read_buffer, write_buffer, true, startup_context, callback, QueryFlags{ .internal = true }, std::nullopt, {});
|
||||
}
|
||||
|
||||
CurrentMetrics::set(CurrentMetrics::StartupScriptsExecutionState, StartupScriptsExecutionState::Success);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
CurrentMetrics::set(CurrentMetrics::StartupScriptsExecutionState, StartupScriptsExecutionState::Failure);
|
||||
tryLogCurrentException(log, "Failed to parse startup scripts file");
|
||||
}
|
||||
}
|
||||
|
@ -356,6 +356,8 @@
|
||||
M(SharedDatabaseCatalogTablesInLocalDropDetachQueue, "Number of tables in the queue for local drop or detach in Shared Catalog.") \
|
||||
\
|
||||
M(MergeTreeIndexGranularityInternalArraysTotalSize, "The total size of all internal arrays in Merge Tree index granularity objects in bytes.") \
|
||||
\
|
||||
M(StartupScriptsExecutionState, "State of startup scripts execution: 0 = not finished, 1 = success, 2 = failure.") \
|
||||
|
||||
#ifdef APPLY_FOR_EXTERNAL_METRICS
|
||||
#define APPLY_FOR_METRICS(M) APPLY_FOR_BUILTIN_METRICS(M) APPLY_FOR_EXTERNAL_METRICS(M)
|
||||
|
@ -0,0 +1,10 @@
|
||||
<clickhouse>
|
||||
<startup_scripts>
|
||||
<scripts>
|
||||
<query>SELECT 42;</query>
|
||||
</scripts>
|
||||
<scripts>
|
||||
<query>SELECT * FROM non_existent_table;</query>
|
||||
</scripts>
|
||||
</startup_scripts>
|
||||
</clickhouse>
|
@ -0,0 +1,11 @@
|
||||
<clickhouse>
|
||||
<startup_scripts>
|
||||
<scripts>
|
||||
<condition>SELECT 0;</condition>
|
||||
<query>SELECT * FROM non_existent_table;</query>
|
||||
</scripts>
|
||||
<scripts>
|
||||
<query>SELECT 42;</query>
|
||||
</scripts>
|
||||
</startup_scripts>
|
||||
</clickhouse>
|
@ -0,0 +1,8 @@
|
||||
<clickhouse>
|
||||
<users>
|
||||
<default>
|
||||
<profile>default</profile>
|
||||
<no_password></no_password>
|
||||
</default>
|
||||
</users>
|
||||
</clickhouse>
|
@ -0,0 +1,56 @@
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from enum import Enum
|
||||
|
||||
import pytest
|
||||
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
good = cluster.add_instance(
|
||||
"good",
|
||||
main_configs=["config/users.xml", "config/good_script.xml"],
|
||||
stay_alive=True,
|
||||
)
|
||||
bad = cluster.add_instance(
|
||||
"bad",
|
||||
main_configs=["config/users.xml", "config/bad_script.xml"],
|
||||
stay_alive=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def start_cluster():
|
||||
try:
|
||||
cluster.start()
|
||||
yield cluster
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
|
||||
def test_startup_execution_state(start_cluster):
|
||||
"""
|
||||
Making sure that the StartupScriptsExecutionState metric is set correctly.
|
||||
"""
|
||||
|
||||
STATE_SUCCESS = 1
|
||||
STATE_FAILURE = 2
|
||||
|
||||
assert (
|
||||
int(
|
||||
good.query(
|
||||
"SELECT value FROM system.metrics WHERE metric = 'StartupScriptsExecutionState'"
|
||||
).strip()
|
||||
)
|
||||
== STATE_SUCCESS
|
||||
)
|
||||
|
||||
assert (
|
||||
int(
|
||||
bad.query(
|
||||
"SELECT value FROM system.metrics WHERE metric = 'StartupScriptsExecutionState'"
|
||||
).strip()
|
||||
)
|
||||
== STATE_FAILURE
|
||||
)
|
Loading…
Reference in New Issue
Block a user