Skip to content

[receiver/sqlserver] Add metric for wait times #39990

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 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .chloggen/sqlserver_add_wait_time_metric.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: receiver/sqlserver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add new metric to track OS wait times

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [39977]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
The new metric is named `sqlserver.os.wait.duration` and disabled by default.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
17 changes: 17 additions & 0 deletions receiver/sqlserverreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,23 @@ Total memory in use.
| ---- | ----------- | ---------- | ----------------------- | --------- |
| “KB” | Sum | Double | Cumulative | false |

### sqlserver.os.wait.duration

Total wait time for this wait type

This metric is only available when the receiver is configured to directly connect to SQL Server.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| s | Sum | Double | Cumulative | true |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| wait.category | Category of the reason for a wait. | Any Str |
| wait.type | Type of the wait, view [WaitTypes documentation](https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-os-wait-stats-transact-sql?view=sql-server-ver16#WaitTypes) for more information. | Any Str |

### sqlserver.page.buffer_cache.free_list.stalls.rate

Number of free list stalls.
Expand Down
12 changes: 12 additions & 0 deletions receiver/sqlserverreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func setupQueries(cfg *Config) []string {
queries = append(queries, getSQLServerPropertiesQuery(cfg.InstanceName))
}

if isWaitStatsQueryEnabled(&cfg.Metrics) {
queries = append(queries, getSQLServerWaitStatsQuery(cfg.InstanceName))
}

return queries
}

Expand Down Expand Up @@ -284,3 +288,11 @@ func isPerfCounterQueryEnabled(metrics *metadata.MetricsConfig) bool {
metrics.SqlserverTransactionMirrorWriteRate.Enabled ||
metrics.SqlserverUserConnectionCount.Enabled
}

func isWaitStatsQueryEnabled(metrics *metadata.MetricsConfig) bool {
if metrics == nil {
return false
}

return metrics.SqlserverOsWaitDuration.Enabled
}
2 changes: 1 addition & 1 deletion receiver/sqlserverreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestSetupQueries(t *testing.T) {

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ all_set:
enabled: true
sqlserver.memory.usage:
enabled: true
sqlserver.os.wait.duration:
enabled: true
sqlserver.page.buffer_cache.free_list.stalls.rate:
enabled: true
sqlserver.page.buffer_cache.hit_ratio:
Expand Down Expand Up @@ -146,6 +148,8 @@ none_set:
enabled: false
sqlserver.memory.usage:
enabled: false
sqlserver.os.wait.duration:
enabled: false
sqlserver.page.buffer_cache.free_list.stalls.rate:
enabled: false
sqlserver.page.buffer_cache.hit_ratio:
Expand Down
18 changes: 17 additions & 1 deletion receiver/sqlserverreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ attributes:
description: The status of the tempdb space usage.
type: string
enum: [free, used]
wait.category:
description: Category of the reason for a wait.
type: string
wait.type:
description: Type of the wait, view [WaitTypes documentation](https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-os-wait-stats-transact-sql?view=sql-server-ver16#WaitTypes) for more information.
type: string

metrics:
sqlserver.user.connection.count:
Expand Down Expand Up @@ -415,7 +421,17 @@ metrics:
unit: “KB”
gauge:
value_type: double
attributes: []
attributes: []
sqlserver.os.wait.duration:
enabled: false
description: Total wait time for this wait type
unit: "s"
sum:
aggregation_temporality: cumulative
monotonic: true
value_type: double
attributes: [wait.category, wait.type]
extended_documentation: This metric is only available when the receiver is configured to directly connect to SQL Server.

tests:
config:
Expand Down
Loading
Loading