Skip to content

[receiver/sqlserver] Add new metric: lock wait count #39930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crobert-1
Copy link
Member

Description

Adds a new metric sqlserver.lock.wait.count to represent the total number of lock waits. This required adding a new metric to metadata.yaml, updating the existing SQL Server perf counter query, and updating tests.

Link to tracking issue

Fixes #39892

Testing

Updated tests for new metric, all are passing.

Also, tested to ensure the instance_name configuration option still works (only metrics for the specified instance name are returned.) I tested with it set to the right value and unset, returning the same results (only one instance in my test environment,) and then also tested with the wrong value and saw no metrics were returned. This has to be done manually at this point as we don't have integration tests with a real SQL Server instance. The existing tests rely on saved query data, and aren't required to be updated with changes to the receiver.

Documentation

Added note in metadata.yaml describing new metric.

@crobert-1 crobert-1 requested a review from a team as a code owner May 7, 2025 16:14
@crobert-1 crobert-1 requested a review from andrzej-stencel May 7, 2025 16:14
@github-actions github-actions bot added receiver/sqlserver Run Windows Enable running windows test on a PR labels May 7, 2025
@github-actions github-actions bot requested review from sincejune and StefanKurek May 7, 2025 16:14
sqlserver.lock.wait.count:
enabled: false
description: Cumulative count of lock waits that occurred.
unit: "{waits}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd appreciate feedback on what the unit should be here, if anyone has any thoughts.

(
SELECT
rgwg.name AS instance
,rgwg.total_request_count AS [Request Count]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including extra selects here in case we want to add these metrics in the future.

@@ -352,6 +353,14 @@ func (s *sqlServerScraperHelper) recordDatabasePerfCounterMetrics(ctx context.Co
} else {
s.mb.RecordSqlserverLockTimeoutRateDataPoint(now, val)
}
case lockWaitCount:
val, err := retrieveInt(row, valueKey)
Copy link
Member Author

@crobert-1 crobert-1 May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retrieveInt is called here instead of strconv.ParseInt to conform to new functionality introduced in #39905 (which hasn't been merged yet).

@@ -32,45 +32,49 @@ func configureAllScraperMetrics(cfg *Config, enabled bool) {
cfg.Metrics.SqlserverBatchRequestRate.Enabled = enabled
cfg.Metrics.SqlserverBatchSQLCompilationRate.Enabled = enabled
cfg.Metrics.SqlserverBatchSQLRecompilationRate.Enabled = enabled

cfg.Metrics.SqlserverDatabaseBackupOrRestoreRate.Enabled = enabled
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to this method aren't entirely relevant to this PR, my apologies. I noticed not all metrics were being included in this method so I used it as an opportunity to add all metrics to this list and alphabetize them.

To validate this is the full list, refer to the generated list of metrics.

@crobert-1 crobert-1 force-pushed the sqlserver_add_lock_wait_count branch from 1d5b494 to 86b9866 Compare May 8, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[receiver/sqlserver] Add lock wait count metric
3 participants