Skip to content

Commit

Permalink
mk-sql adds headers to the error message
Browse files Browse the repository at this point in the history
Previously, the mk-sql plugin would send only error text when
an error occurred, which could disrupt other services.
Now, in the event of an error, the mk-sql plugin always sends
SQL plain headers, thereby eliminating this problem.

Change-Id: I91146955c6139941527b59b81e378b2b07e9c2a8
  • Loading branch information
s-kipnis committed May 29, 2024
1 parent 69223a9 commit 3419412
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/mk-sql/src/ms_sql/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,8 @@ fn generate_signaling_block(
async fn generate_data(ms_sql: &config::ms_sql::Config, environment: &Env) -> Result<String> {
let instances = find_usable_instances(ms_sql, environment).await?;
if instances.is_empty() {
return Ok("ERROR: Failed to gather SQL server instances\n".to_string());
return Ok(generate_signaling_block(ms_sql, &None)
+ "ERROR: Failed to gather SQL server instances\n");
} else {
log::info!(
"Found {} SQL server instances: [ {} ]",
Expand Down
32 changes: 32 additions & 0 deletions packages/mk-sql/tests/test_ms_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,38 @@ async fn test_check_config_exec_piggyback_remote() {
assert!(!output.is_empty());
}

#[tokio::test(flavor = "multi_thread")]
async fn test_lack_of_sql_db() {
let dir = tools::create_temp_process_dir();
let content = std::fs::read_to_string(
PathBuf::new()
.join("tests")
.join("files")
.join("test-no-ms-sql.yml"),
)
.unwrap();
tools::create_file_with_content(dir.path(), "mk-sql.yml", &content);
let check_config = CheckConfig::load_file(&dir.path().join("mk-sql.yml")).unwrap();
let output = check_config.exec(&Env::default()).await.unwrap();
let awaited = "<<<mssql_instance:sep(124)>>>
<<<mssql_databases:sep(124)>>>
<<<mssql_counters:sep(124)>>>
<<<mssql_blocked_sessions:sep(124)>>>
<<<mssql_transactionlogs:sep(124)>>>
<<<mssql_clusters:sep(124)>>>
<<<mssql_mirroring:sep(09)>>>
<<<mssql_availability_groups:sep(09)>>>
<<<mssql_connections>>>
<<<mssql_tablespaces>>>
<<<mssql_datafiles:sep(124)>>>
<<<mssql_backup:sep(124)>>>
<<<mssql_jobs:sep(09)>>>
<<<mssql_instance:sep(124)>>>
ERROR: Failed to gather SQL server instances\n"
.to_owned();
assert_eq!(output.to_owned(), awaited);
}

#[cfg(windows)]
fn create_localhost_remote_config(endpoint: SqlDbEndpoint) -> String {
format!(
Expand Down

0 comments on commit 3419412

Please sign in to comment.