Skip to content

Commit 8428fd3

Browse files
crobert-1dd-jasminesun
authored andcommitted
[receiver/sqlserver] Emit another metric for direct connection (open-telemetry#39940)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Before this PR the `sqlserver.page.life_expectancy` metric was only available when running on Windows as it was scraped from perf counters directly. This change enables the metric to be emitted also from directly connecting to SQL Server instances. <!--Describe what testing was performed and which tests were added.--> #### Testing Updated existing testing. open-telemetry#39930 adds this metric in the `configureAllScraperMetrics`, otherwise it would have needed to be added here. <!--Describe the documentation added.--> #### Documentation Removed documentation note that this metric was only available on Windows. <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 474678a commit 8428fd3

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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: Enable `sqlserver.page.life_expectancy` metric for all configurations
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: [39940]
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: |
19+
This metric was originally only available when running on Windows, but is
20+
now available for all configuration options, including direct connection.
21+
Since this metric is enabled by default, users who have direct connection
22+
configured will now have this metric emitted by default.
23+
24+
# If your change doesn't affect end users or the exported elements of any package,
25+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
26+
# Optional: The change log or logs in which this entry should be included.
27+
# e.g. '[user]' or '[user, api]'
28+
# Include 'user' if the change is relevant to end users.
29+
# Include 'api' if there is a change to a library API.
30+
# Default: '[user]'
31+
change_logs: []

receiver/sqlserverreceiver/documentation.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ This metric is only available when running on Windows.
8686
8787
Time a page will stay in the buffer pool.
8888
89-
This metric is only available when running on Windows.
90-
9189
| Unit | Metric Type | Value Type |
9290
| ---- | ----------- | ---------- |
9391
| s | Gauge | Int |

receiver/sqlserverreceiver/metadata.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ metrics:
210210
unit: s
211211
gauge:
212212
value_type: int
213-
extended_documentation: This metric is only available when running on Windows.
214213
sqlserver.page.split.rate:
215214
enabled: true
216215
description: Number of pages split as a result of overflowing index pages.

receiver/sqlserverreceiver/scraper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func (s *sqlServerScraperHelper) recordDatabasePerfCounterMetrics(ctx context.Co
235235
const numberOfDeadlocksPerSec = "Number of Deadlocks/sec"
236236
const mirrorWritesTransactionPerSec = "Mirrored Write Transactions/sec"
237237
const memoryGrantsPending = "Memory Grants Pending"
238+
const pageLifeExpectancy = "Page life expectancy"
238239
const pageLookupsPerSec = "Page lookups/sec"
239240
const processesBlocked = "Processes blocked"
240241
const sqlCompilationRate = "SQL Compilations/sec"
@@ -435,6 +436,14 @@ func (s *sqlServerScraperHelper) recordDatabasePerfCounterMetrics(ctx context.Co
435436
} else {
436437
s.mb.RecordSqlserverDeadlockRateDataPoint(now, val.(float64))
437438
}
439+
case pageLifeExpectancy:
440+
val, err := retrieveInt(row, valueKey)
441+
if err != nil {
442+
err = fmt.Errorf("failed to parse valueKey for row %d: %w in %s", i, err, pageLifeExpectancy)
443+
errs = append(errs, err)
444+
} else {
445+
s.mb.RecordSqlserverPageLifeExpectancyDataPoint(now, val.(int64))
446+
}
438447
case pageLookupsPerSec:
439448
val, err := retrieveFloat(row, valueKey)
440449
if err != nil {

receiver/sqlserverreceiver/testdata/expectedPerfCounters.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ resourceMetrics:
151151
scope:
152152
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver
153153
version: latest
154+
- resource:
155+
attributes:
156+
- key: server.address
157+
value:
158+
stringValue: 0.0.0.0
159+
- key: server.port
160+
value:
161+
intValue: "1433"
162+
- key: sqlserver.instance.name
163+
value:
164+
stringValue: d26d40521426
165+
scopeMetrics:
166+
- metrics:
167+
- description: Time a page will stay in the buffer pool.
168+
gauge:
169+
dataPoints:
170+
- asInt: "16771"
171+
startTimeUnixNano: "1000000"
172+
timeUnixNano: "2000000"
173+
name: sqlserver.page.life_expectancy
174+
unit: s
175+
scope:
176+
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver
177+
version: latest
154178
- resource:
155179
attributes:
156180
- key: server.address
@@ -175,6 +199,30 @@ resourceMetrics:
175199
scope:
176200
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver
177201
version: latest
202+
- resource:
203+
attributes:
204+
- key: server.address
205+
value:
206+
stringValue: 0.0.0.0
207+
- key: server.port
208+
value:
209+
intValue: "1433"
210+
- key: sqlserver.instance.name
211+
value:
212+
stringValue: d26d40521426
213+
scopeMetrics:
214+
- metrics:
215+
- description: Time a page will stay in the buffer pool.
216+
gauge:
217+
dataPoints:
218+
- asInt: "16771"
219+
startTimeUnixNano: "1000000"
220+
timeUnixNano: "2000000"
221+
name: sqlserver.page.life_expectancy
222+
unit: s
223+
scope:
224+
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver
225+
version: latest
178226
- resource:
179227
attributes:
180228
- key: server.address

0 commit comments

Comments
 (0)