Skip to content

Commit

Permalink
[receiver/sqlserver] Add support for more database IO metrics (open-t…
Browse files Browse the repository at this point in the history
…elemetry#32833)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
This adds more metrics (disabled by default) from the existing
`database_io` query. The values being scraped can be found
[here](https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-io-virtual-file-stats-transact-sql?view=sql-server-ver16).

**Link to tracking Issue:** <Issue number if applicable>
Continued work on open-telemetry#29865

**Testing:** <Describe what testing was performed and which tests were
added.>
Tests added. Also confirmed all expected metrics were properly scraped
manually.
  • Loading branch information
crobert-1 authored Jun 5, 2024
1 parent 9815a65 commit fa5e8f1
Show file tree
Hide file tree
Showing 15 changed files with 1,715 additions and 59 deletions.
27 changes: 27 additions & 0 deletions .chloggen/sqlserver_add_io_metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: sqlserver.database.io.read_latency has been renamed to sqlserver.database.latency with a `direction` attribute.

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

# (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:

# 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: []
31 changes: 31 additions & 0 deletions .chloggen/sqlserver_io_metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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: sqlserverreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for more Database IO metrics

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

# (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 following metrics have been added:
- sqlserver.database.latency
- sqlserver.database.io
- sqlserver.database.operations
# 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: []
43 changes: 41 additions & 2 deletions receiver/sqlserverreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,28 @@ This metric is only available when the receiver is configured to directly connec
| ---- | ----------- | ------ |
| database.status | The current status of a database | Str: ``online``, ``restoring``, ``recovering``, ``pending_recovery``, ``suspect``, ``offline`` |
### sqlserver.database.io.read_latency
### sqlserver.database.io
Total time that the users waited for reads issued on this file.
The number of bytes of I/O on this file.
This metric is only available when the receiver is configured to directly connect to SQL Server.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | true |
#### Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| physical_filename | The physical filename of the file being monitored. | Any Str |
| logical_filename | The logical filename of the file being monitored. | Any Str |
| file_type | The type of file being monitored. | Any Str |
| direction | The direction of flow of bytes or operations. | Str: ``read``, ``write`` |
### sqlserver.database.latency
Total time that the users waited for I/O issued on this file.
This metric is only available when the receiver is configured to directly connect to SQL Server.
Expand All @@ -259,6 +278,26 @@ This metric is only available when the receiver is configured to directly connec
| physical_filename | The physical filename of the file being monitored. | Any Str |
| logical_filename | The logical filename of the file being monitored. | Any Str |
| file_type | The type of file being monitored. | Any Str |
| direction | The direction of flow of bytes or operations. | Str: ``read``, ``write`` |
### sqlserver.database.operations
The number of operations issued on the file.
This metric is only available when the receiver is configured to directly connect to SQL Server.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {operations} | Sum | Int | Cumulative | true |
#### Attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| physical_filename | The physical filename of the file being monitored. | Any Str |
| logical_filename | The logical filename of the file being monitored. | Any Str |
| file_type | The type of file being monitored. | Any Str |
| direction | The direction of flow of bytes or operations. | Str: ``read``, ``write`` |
### sqlserver.processes.blocked
Expand Down
11 changes: 10 additions & 1 deletion receiver/sqlserverreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func createDefaultConfig() component.Config {
func setupQueries(cfg *Config) []string {
var queries []string

if cfg.MetricsBuilderConfig.Metrics.SqlserverDatabaseIoReadLatency.Enabled {
if isDatabaseIOQueryEnabled(&cfg.MetricsBuilderConfig.Metrics) {
queries = append(queries, getSQLServerDatabaseIOQuery(cfg.InstanceName))
}

Expand Down Expand Up @@ -129,3 +129,12 @@ func setupScrapers(params receiver.CreateSettings, cfg *Config) ([]scraperhelper

return opts, nil
}

func isDatabaseIOQueryEnabled(metrics *metadata.MetricsConfig) bool {
if metrics.SqlserverDatabaseLatency.Enabled ||
metrics.SqlserverDatabaseOperations.Enabled ||
metrics.SqlserverDatabaseIo.Enabled {
return true
}
return false
}
2 changes: 1 addition & 1 deletion receiver/sqlserverreceiver/factory_others_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCreateMetricsReceiverOtherOS(t *testing.T) {
cfg.Server = "0.0.0.0"
cfg.Port = 1433
cfg.InstanceName = "instanceName"
cfg.Metrics.SqlserverDatabaseIoReadLatency.Enabled = true
cfg.Metrics.SqlserverDatabaseLatency.Enabled = true
require.NoError(t, cfg.Validate())

require.True(t, directDBConnectionEnabled(cfg))
Expand Down
2 changes: 1 addition & 1 deletion receiver/sqlserverreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestCreateMetricsReceiver(t *testing.T) {
cfg.Server = "0.0.0.0"
cfg.Port = 1433
require.NoError(t, cfg.Validate())
cfg.Metrics.SqlserverDatabaseIoReadLatency.Enabled = true
cfg.Metrics.SqlserverDatabaseLatency.Enabled = true

require.True(t, directDBConnectionEnabled(cfg))
require.Equal(t, "server=0.0.0.0;user id=sa;password=password;port=1433", getDBConnectionString(cfg))
Expand Down
12 changes: 10 additions & 2 deletions receiver/sqlserverreceiver/internal/metadata/generated_config.go

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.

Loading

0 comments on commit fa5e8f1

Please sign in to comment.