Skip to content

Commit f8628d8

Browse files
sincejunedd-jasminesun
authored andcommitted
[receiver/sqlserver] Use generated structured event functions in the … (open-telemetry#40041)
…top query collection <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description - Added `events` definition for top query collection. - Rewrite top query collection with mdatagen generated functions. cc @dmitryax <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue n/a <!--Describe what testing was performed and which tests were added.--> #### Testing Passed <!--Describe the documentation added.--> #### Documentation Added <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 841c781 commit f8628d8

20 files changed

+629
-145
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: sqlserverreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Zero values in delta attributes will be reported in top query collection.
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: [40041]
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 change includes the following attributes:
20+
- sqlserver.total_worker_time
21+
- sqlserver.execution_count
22+
- sqlserver.total_logical_reads
23+
- sqlserver.total_logical_writes
24+
- sqlserver.total_physical_reads
25+
- sqlserver.total_rows
26+
- sqlserver.total_grant_kb
27+
28+
# If your change doesn't affect end users or the exported elements of any package,
29+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
30+
# Optional: The change log or logs in which this entry should be included.
31+
# e.g. '[user]' or '[user, api]'
32+
# Include 'user' if the change is relevant to end users.
33+
# Include 'api' if there is a change to a library API.
34+
# Default: '[user]'
35+
change_logs: [user]
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: sqlserverreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Use generated structured event functions in mdatagen
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: [40041]
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+
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: [api]

receiver/sqlserverreceiver/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type TopQueryCollection struct {
3333
type Config struct {
3434
scraperhelper.ControllerConfig `mapstructure:",squash"`
3535
metadata.MetricsBuilderConfig `mapstructure:",squash"`
36+
metadata.LogsBuilderConfig `mapstructure:",squash"`
3637
// EnableTopQueryCollection enables the collection of the top queries by the execution time.
3738
// It will collect the top N queries based on totalElapsedTimeDiffs during the last collection interval.
3839
// The query statement will also be reported, hence, it is not ideal to send it as a metric. Hence

receiver/sqlserverreceiver/config_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ func TestLoadConfig(t *testing.T) {
144144
expected.MetricsBuilderConfig = metadata.MetricsBuilderConfig{
145145
Metrics: metadata.DefaultMetricsConfig(),
146146
ResourceAttributes: metadata.ResourceAttributesConfig{
147+
HostName: metadata.ResourceAttributeConfig{
148+
Enabled: true,
149+
},
150+
SqlserverDatabaseName: metadata.ResourceAttributeConfig{
151+
Enabled: true,
152+
},
153+
SqlserverInstanceName: metadata.ResourceAttributeConfig{
154+
Enabled: true,
155+
},
156+
SqlserverComputerName: metadata.ResourceAttributeConfig{
157+
Enabled: true,
158+
},
159+
ServerAddress: metadata.ResourceAttributeConfig{
160+
Enabled: true,
161+
},
162+
ServerPort: metadata.ResourceAttributeConfig{
163+
Enabled: true,
164+
},
165+
},
166+
}
167+
expected.LogsBuilderConfig = metadata.LogsBuilderConfig{
168+
Events: metadata.DefaultEventsConfig(),
169+
ResourceAttributes: metadata.ResourceAttributesConfig{
170+
HostName: metadata.ResourceAttributeConfig{
171+
Enabled: true,
172+
},
147173
SqlserverDatabaseName: metadata.ResourceAttributeConfig{
148174
Enabled: true,
149175
},
@@ -178,7 +204,7 @@ func TestLoadConfig(t *testing.T) {
178204
require.NoError(t, sub.Unmarshal(cfg))
179205

180206
assert.NoError(t, xconfmap.Validate(cfg))
181-
if diff := cmp.Diff(expected, cfg, cmpopts.IgnoreUnexported(Config{}), cmpopts.IgnoreUnexported(metadata.MetricConfig{}), cmpopts.IgnoreUnexported(metadata.ResourceAttributeConfig{})); diff != "" {
207+
if diff := cmp.Diff(expected, cfg, cmpopts.IgnoreUnexported(Config{}), cmpopts.IgnoreUnexported(metadata.MetricConfig{}), cmpopts.IgnoreUnexported(metadata.EventConfig{}), cmpopts.IgnoreUnexported(metadata.ResourceAttributeConfig{})); diff != "" {
182208
t.Errorf("Config mismatch (-expected +actual):\n%s", diff)
183209
}
184210
})

receiver/sqlserverreceiver/documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ Total number of mirror write transactions.
512512
513513
| Name | Description | Values | Enabled |
514514
| ---- | ----------- | ------ | ------- |
515+
| host.name | The host name of SQL Server | Any Str | true |
515516
| server.address | Name of the database host. | Any Str | false |
516517
| server.port | Server port number. | Any Int | false |
517518
| sqlserver.computer.name | The name of the SQL Server instance being monitored. | Any Str | false |

receiver/sqlserverreceiver/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func createDefaultConfig() component.Config {
5151
return &Config{
5252
ControllerConfig: cfg,
5353
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
54+
LogsBuilderConfig: metadata.DefaultLogsBuilderConfig(),
5455
QuerySample: QuerySample{
5556
Enabled: false,
5657
MaxRowsPerQuery: 100,

receiver/sqlserverreceiver/factory_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func TestFactory(t *testing.T) {
5454
MaxRowsPerQuery: 100,
5555
},
5656
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
57+
LogsBuilderConfig: metadata.DefaultLogsBuilderConfig(),
5758
}
5859

5960
require.Equal(t, expectedCfg, factory.CreateDefaultConfig())

receiver/sqlserverreceiver/internal/metadata/generated_config.go

Lines changed: 56 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: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)