Skip to content

Commit

Permalink
17297 FIX mk-sql processes backups for clustered instances correctly
Browse files Browse the repository at this point in the history
The problem occured when the monitored MS SQL Server instance
is part of a clustered installation. Due to incorrect processing
and/or conversion, some backup entries might disappear from
the output.

This release resolves the issue.

SUP-21423
SUP-20138
SUP-21722
SUP-20585

Change-Id: I206e22dc331c18ad9c4ec8dbf9b9b1682ec9e163
  • Loading branch information
s-kipnis committed Jan 13, 2025
1 parent 50259e3 commit 40d8453
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
24 changes: 24 additions & 0 deletions .werks/17297.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[//]: # (werk v2)
# mk-sql processes backups for clustered instances correctly

key | value
---------- | ---
date | 2025-01-13T11:50:25+00:00
version | 2.3.0p25
class | fix
edition | cee
component | checks
level | 2
compatible | yes

The problem occured when the monitored MS SQL Server instance
is part of a clustered installation. Due to incorrect processing
and/or conversion, some backup entries might disappear from
the output.

This release resolves the issue.

SUP-21423
SUP-20138
SUP-21722
SUP-20585
12 changes: 6 additions & 6 deletions packages/mk-sql/src/ms_sql/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ impl SqlInstance {
self.generate_datafiles_section(endpoint, chunk, query, sep),
),
names::CLUSTERS => rt.block_on(
self.generate_transaction_logs_section(endpoint, chunk, query, sep),
self.generate_clusters_section(endpoint, chunk, query, sep),
),
_ => format!("{} not implemented\n", section.name()).to_string(),
}
Expand Down Expand Up @@ -1001,7 +1001,7 @@ impl SqlInstance {
}
let (nodes, active_node) = self.get_cluster_nodes(client, query).await?;
Ok(Some(format!(
"{}{sep}{}{sep}{}{sep}{}",
"{}{sep}{}{sep}{}{sep}{}\n",
self.name,
database.replace(' ', "_"),
active_node,
Expand All @@ -1022,7 +1022,7 @@ impl SqlInstance {
query: &str,
) -> Result<(String, String)> {
let answers = &run_custom_query(client, query).await?;
if answers.len() > 2 && !answers[0].is_empty() && !answers[1].is_empty() {
if answers.len() >= 2 && !answers[1].is_empty() {
return Ok((answers[0].get_node_names(), answers[1].get_active_node()));
}
Ok((String::default(), String::default()))
Expand Down Expand Up @@ -1212,7 +1212,7 @@ impl SqlInstance {
Some(UniAnswer::Block(block)) => block
.rows
.iter()
.map(|row| row.get(0).cloned().unwrap_or_default())
.map(|row| row.first().cloned().unwrap_or_default())
.collect::<Vec<String>>(),
None => {
log::error!("Databases answer is empty");
Expand Down Expand Up @@ -1727,7 +1727,7 @@ fn to_backup_entry(
.get_value_by_name("is_primary_replica")
.trim()
.to_string();
if replica_id.is_empty() || is_primary_replica == "True" {
if replica_id.is_empty() || is_primary_replica == "True" || is_primary_replica == "1" {
format!(
"{}{sep}{}{sep}{}+00:00{sep}{}\n",
instance_name,
Expand Down Expand Up @@ -1769,7 +1769,7 @@ fn to_backup_entry_odbc(
.get_value_by_name(row, "is_primary_replica")
.trim()
.to_string();
if replica_id.is_empty() || is_primary_replica == "True" {
if replica_id.is_empty() || is_primary_replica == "True" || is_primary_replica == "1" {
format!(
"{}{sep}{}{sep}{}+00:00{sep}{}\n",
instance_name,
Expand Down
11 changes: 6 additions & 5 deletions packages/mk-sql/src/ms_sql/sqls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ BEGIN
(CASE WHEN time_zone IS NOT NULL AND time_zone <> 127 THEN 60 * 15 * time_zone ELSE 0 END)), ''19700101''), 120)
AS last_backup_date,
cast(b.type as nvarchar(max)) as type,
cast(b.machine_name as nvarchar(max)),
isnull(rep.is_primary_replica,0) as is_primary_replica,
cast(b.machine_name as nvarchar(max)) as machine_name,
isnull(convert(nvarchar(40), rep.is_primary_replica), '''') as is_primary_replica,
rep.is_local,
isnull(convert(nvarchar(40), rep.replica_id), '''') AS replica_id,
cast(db.name as nvarchar(max)) AS database_name
Expand Down Expand Up @@ -281,11 +281,12 @@ cast(DATABASEPROPERTYEX(name, 'Status') as nvarchar(max)) AS Status, \
FROM master.dbo.sysdatabases";

pub const IS_CLUSTERED: &str =
"SELECT cast( SERVERPROPERTY('IsClustered') as nvarchar) AS is_clustered";
"SELECT cast( SERVERPROPERTY('IsClustered') as nvarchar(max)) AS is_clustered";
pub const CLUSTER_NODES: &str =
"SELECT cast(nodename as NVARCHAR) as nodename FROM sys.dm_os_cluster_nodes";
"SELECT cast(nodename as NVARCHAR(max)) as nodename FROM sys.dm_os_cluster_nodes";

pub const CLUSTER_ACTIVE_NODES: &str =
"SELECT cast(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') as nvarchar) AS active_node";
"SELECT cast(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') as nvarchar(max)) AS active_node";

pub const CONNECTIONS: &str = "SELECT name AS DbName, \
cast((SELECT COUNT(dbid) AS Num_Of_Connections FROM sys.sysprocesses WHERE dbid > 0 AND name = DB_NAME(dbid) GROUP BY dbid ) as bigint) AS NumberOfConnections \
Expand Down

0 comments on commit 40d8453

Please sign in to comment.