Skip to content

Commit c51524e

Browse files
authored
[receiver/sqlserver] Add new metric: lock wait count (#39930)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### 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. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #39892 <!--Describe what testing was performed and which tests were added.--> #### 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. <!--Describe the documentation added.--> #### Documentation Added note in `metadata.yaml` describing new metric.
1 parent eed3dd0 commit c51524e

17 files changed

+3444
-3007
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: receiver/sqlserver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add new metric `sqlserver.lock.wait.count`
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [39892]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: This metric is disabled by default.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

receiver/sqlserverreceiver/documentation.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,16 @@ Total number of lock timeouts.
359359
| ---- | ----------- | ---------- |
360360
| “{timeouts}/s” | Gauge | Double |
361361
362+
### sqlserver.lock.wait.count
363+
364+
Cumulative count of lock waits that occurred.
365+
366+
This metric is only available when the receiver is configured to directly connect to SQL Server.
367+
368+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
369+
| ---- | ----------- | ---------- | ----------------------- | --------- |
370+
| {wait} | Sum | Int | Cumulative | true |
371+
362372
### sqlserver.login.rate
363373
364374
Total number of logins.

receiver/sqlserverreceiver/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func isPerfCounterQueryEnabled(metrics *metadata.MetricsConfig) bool {
267267
metrics.SqlserverDeadlockRate.Enabled ||
268268
metrics.SqlserverIndexSearchRate.Enabled ||
269269
metrics.SqlserverLockTimeoutRate.Enabled ||
270+
metrics.SqlserverLockWaitCount.Enabled ||
270271
metrics.SqlserverLockWaitRate.Enabled ||
271272
metrics.SqlserverLoginRate.Enabled ||
272273
metrics.SqlserverLogoutRate.Enabled ||

receiver/sqlserverreceiver/factory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func TestSetupQueries(t *testing.T) {
264264

265265
metricsMetadata, ok := metadata["metrics"].(map[string]any)
266266
require.True(t, ok)
267-
require.Len(t, metricsMetadata, 46,
267+
require.Len(t, metricsMetadata, 47,
268268
"Every time metrics are added or removed, the function `setupQueries` must "+
269269
"be modified to properly account for the change. Please update `setupQueries` and then, "+
270270
"and only then, update the expected metric count here.")

receiver/sqlserverreceiver/internal/metadata/generated_config.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/sqlserverreceiver/internal/metadata/generated_config_test.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/sqlserverreceiver/internal/metadata/generated_metrics.go

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/sqlserverreceiver/internal/metadata/generated_metrics_test.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/sqlserverreceiver/internal/metadata/testdata/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ all_set:
3131
enabled: true
3232
sqlserver.lock.timeout.rate:
3333
enabled: true
34+
sqlserver.lock.wait.count:
35+
enabled: true
3436
sqlserver.lock.wait.rate:
3537
enabled: true
3638
sqlserver.lock.wait_time.avg:
@@ -136,6 +138,8 @@ none_set:
136138
enabled: false
137139
sqlserver.lock.timeout.rate:
138140
enabled: false
141+
sqlserver.lock.wait.count:
142+
enabled: false
139143
sqlserver.lock.wait.rate:
140144
enabled: false
141145
sqlserver.lock.wait_time.avg:

receiver/sqlserverreceiver/metadata.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ metrics:
8686
gauge:
8787
value_type: double
8888
extended_documentation: This metric is only available when running on Windows.
89+
sqlserver.lock.wait.count:
90+
enabled: false
91+
description: Cumulative count of lock waits that occurred.
92+
unit: "{wait}"
93+
sum:
94+
monotonic: true
95+
aggregation_temporality: cumulative
96+
value_type: int
97+
extended_documentation: This metric is only available when the receiver is configured to directly connect to SQL Server.
8998
sqlserver.lock.wait.rate:
9099
enabled: true
91100
description: Number of lock requests resulting in a wait.

0 commit comments

Comments
 (0)