Skip to content

Commit 8d5e2fe

Browse files
sincejuneatoulme
andauthored
[receiver/sqlserver] Remove duplicated flags for enabling top query c… (#40416)
…ollection and query sample collection <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description - Removed `top_query_collection.enabled` in favor of `events."db.server.top_query".enabled` in top query collection. - Removed `query_sample_collection.enabled` in favor of `events."db.server.query_sample".enabled` in query sample collection. <!-- 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 Updated <!--Describe the documentation added.--> #### Documentation Added <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Antoine Toulme <[email protected]>
1 parent 64518e7 commit 8d5e2fe

File tree

12 files changed

+63
-105
lines changed

12 files changed

+63
-105
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: Rename flags for enabling top query collection and query sample 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: [40416]
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+
Renamed `top_query_collection.enabled` to `events."db.server.top_query".enabled` in top query collection.
20+
Renamed `query_sample_collection.enabled` to `events."db.server.query_sample".enabled` in query sample collection.
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [user]

receiver/sqlserverreceiver/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
)
1515

1616
type QuerySample struct {
17-
Enabled bool `mapstructure:"enabled"`
1817
MaxRowsPerQuery uint64 `mapstructure:"max_rows_per_query"`
18+
19+
// prevent unkeyed literal initialization
20+
_ struct{}
1921
}
2022

2123
type TopQueryCollection struct {
@@ -24,7 +26,6 @@ type TopQueryCollection struct {
2426
// The query statement will also be reported, hence, it is not ideal to send it as a metric. Hence
2527
// we are reporting them as logs.
2628
// The `N` is configured via `TopQueryCount`
27-
Enabled bool `mapstructure:"enabled"`
2829
LookbackTime uint `mapstructure:"lookback_time"`
2930
MaxQuerySampleCount uint `mapstructure:"max_query_sample_count"`
3031
TopQueryCount uint `mapstructure:"top_query_count"`

receiver/sqlserverreceiver/config_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,11 @@ func TestLoadConfig(t *testing.T) {
189189
}
190190
expected.ComputerName = "CustomServer"
191191
expected.InstanceName = "CustomInstance"
192-
expected.TopQueryCollection.Enabled = true
193192
expected.LookbackTime = 60
194193
expected.TopQueryCount = 200
195194
expected.MaxQuerySampleCount = 1000
196195

197196
expected.QuerySample = QuerySample{
198-
Enabled: true,
199197
MaxRowsPerQuery: 1450,
200198
}
201199

receiver/sqlserverreceiver/documentation.md

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -539,72 +539,6 @@ events:
539539
enabled: false
540540
```
541541
542-
### db.server.query_sample
543-
544-
query sample
545-
546-
#### Attributes
547-
548-
| Name | Description | Values |
549-
| ---- | ----------- | ------ |
550-
| client.address | Hostname or address of the client. | Any Str |
551-
| client.port | TCP port used by the client. | Any Int |
552-
| db.namespace | The database name. | Any Str |
553-
| db.query.text | The text of the database query being executed. | Any Str |
554-
| db.system.name | The database management system (DBMS) product as identified by the client instrumentation. | Any Str |
555-
| network.peer.address | IP address of the peer client. | Any Str |
556-
| network.peer.port | TCP port used by the peer client. | Any Int |
557-
| sqlserver.blocking_session_id | Session ID that is blocking the current session. 0 if none. | Any Int |
558-
| sqlserver.context_info | Context information for the session, represented as a hexadecimal string. | Any Str |
559-
| sqlserver.command | SQL command type being executed. | Any Str |
560-
| sqlserver.cpu_time | CPU time consumed by the query, in seconds. | Any Double |
561-
| sqlserver.deadlock_priority | Deadlock priority value for the session. | Any Int |
562-
| sqlserver.estimated_completion_time | Estimated time remaining for the request to complete, in seconds. | Any Double |
563-
| sqlserver.lock_timeout | Lock timeout value in seconds. | Any Double |
564-
| sqlserver.logical_reads | Number of logical reads (data read from cache/memory). | Any Int |
565-
| sqlserver.open_transaction_count | Number of transactions currently open in the session. | Any Int |
566-
| sqlserver.percent_complete | Percentage of work completed. | Any Double |
567-
| sqlserver.query_hash | Binary hash value calculated on the query and used to identify queries with similar logic, reported in the HEX format. | Any Str |
568-
| sqlserver.query_plan_hash | Binary hash value calculated on the query execution plan and used to identify similar query execution plans, reported in the HEX format. | Any Str |
569-
| sqlserver.query_start | Timestamp of when the SQL query started (ISO 8601 format). | Any Str |
570-
| sqlserver.reads | Number of physical reads performed by the query. | Any Int |
571-
| sqlserver.request_status | Status of the request (e.g., running, suspended). | Any Str |
572-
| sqlserver.row_count | Number of rows affected or returned by the query. | Any Int |
573-
| sqlserver.session_id | ID of the SQL Server session. | Any Int |
574-
| sqlserver.session_status | Status of the session (e.g., running, sleeping). | Any Str |
575-
| sqlserver.total_elapsed_time | Total elapsed time for completed executions of this plan, reported in delta seconds. | Any Double |
576-
| sqlserver.transaction_id | Unique ID of the active transaction. | Any Int |
577-
| sqlserver.transaction_isolation_level | Transaction isolation level used in the session. Represented as numeric constant. | Any Int |
578-
| sqlserver.wait_resource | The resource for which the session is waiting. | Any Str |
579-
| sqlserver.wait_time | Duration in seconds the request has been waiting. | Any Double |
580-
| sqlserver.wait_type | Type of wait encountered by the request. Empty if none. | Any Str |
581-
| sqlserver.writes | Number of writes performed by the query. | Any Int |
582-
| user.name | Login name associated with the SQL Server session. | Any Str |
583-
584-
### db.server.top_query
585-
586-
top query
587-
588-
#### Attributes
589-
590-
| Name | Description | Values |
591-
| ---- | ----------- | ------ |
592-
| sqlserver.total_worker_time | Total amount of CPU time that was consumed by executions of this plan since it was compiled, reported in delta seconds. | Any Double |
593-
| db.query.text | The text of the database query being executed. | Any Str |
594-
| sqlserver.execution_count | Number of times that the plan has been executed since it was last compiled, reported in delta value. | Any Int |
595-
| sqlserver.total_logical_reads | Total number of logical reads performed by executions of this plan since it was compiled, reported in delta value. | Any Int |
596-
| sqlserver.total_logical_writes | Total number of logical writes performed by executions of this plan since it was compiled, reported in delta value. | Any Int |
597-
| sqlserver.total_physical_reads | Total number of physical reads performed by executions of this plan since it was compiled, reported in delta value. | Any Int |
598-
| sqlserver.query_hash | Binary hash value calculated on the query and used to identify queries with similar logic, reported in the HEX format. | Any Str |
599-
| sqlserver.query_plan | The query execution plan used by the SQL Server. | Any Str |
600-
| sqlserver.query_plan_hash | Binary hash value calculated on the query execution plan and used to identify similar query execution plans, reported in the HEX format. | Any Str |
601-
| sqlserver.total_rows | Total number of rows returned by the query, reported in delta value. | Any Int |
602-
| sqlserver.total_elapsed_time | Total elapsed time for completed executions of this plan, reported in delta seconds. | Any Double |
603-
| sqlserver.total_grant_kb | The total amount of reserved memory grant in KB this plan received since it was compiled, reported in delta value. | Any Int |
604-
| server.address | The network address of the server hosting the database. | Any Str |
605-
| server.port | The port number on which the server is listening. | Any Int |
606-
| db.system.name | The database management system (DBMS) product as identified by the client instrumentation. | Any Str |
607-
608542
## Resource Attributes
609543
610544
| Name | Description | Values | Enabled |

receiver/sqlserverreceiver/factory.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ func createDefaultConfig() component.Config {
5353
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
5454
LogsBuilderConfig: metadata.DefaultLogsBuilderConfig(),
5555
QuerySample: QuerySample{
56-
Enabled: false,
5756
MaxRowsPerQuery: 100,
5857
},
5958
TopQueryCollection: TopQueryCollection{
60-
Enabled: false,
6159
LookbackTime: uint(2 * cfg.CollectionInterval / time.Second),
6260
MaxQuerySampleCount: 1000,
6361
TopQueryCount: 200,
@@ -91,11 +89,11 @@ func setupQueries(cfg *Config) []string {
9189
func setupLogQueries(cfg *Config) []string {
9290
var queries []string
9391

94-
if cfg.QuerySample.Enabled {
92+
if cfg.Events.DbServerQuerySample.Enabled {
9593
queries = append(queries, getSQLServerQuerySamplesQuery())
9694
}
9795

98-
if cfg.TopQueryCollection.Enabled {
96+
if cfg.Events.DbServerTopQuery.Enabled {
9997
queries = append(queries, getSQLServerQueryTextAndPlanQuery())
10098
}
10199

receiver/sqlserverreceiver/factory_others_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestFactoryOtherOS(t *testing.T) {
9090
require.Empty(t, sqlScrapers)
9191

9292
cfg.InstanceName = "instanceName"
93-
cfg.TopQueryCollection.Enabled = true
93+
cfg.Events.DbServerTopQuery.Enabled = true
9494
scrapers, err = setupLogsScrapers(params, cfg)
9595
require.NoError(t, err)
9696
require.NotEmpty(t, scrapers)

receiver/sqlserverreceiver/factory_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ func TestFactory(t *testing.T) {
4444
InitialDelay: time.Second,
4545
},
4646
TopQueryCollection: TopQueryCollection{
47-
Enabled: false,
4847
LookbackTime: uint(2 * 10),
4948
MaxQuerySampleCount: 1000,
5049
TopQueryCount: 200,
5150
CollectionInterval: time.Minute,
5251
},
5352
QuerySample: QuerySample{
54-
Enabled: false,
5553
MaxRowsPerQuery: 100,
5654
},
5755
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
@@ -204,7 +202,7 @@ func TestFactory(t *testing.T) {
204202
require.Empty(t, sqlScrapers)
205203

206204
cfg.InstanceName = "instanceName"
207-
cfg.TopQueryCollection.Enabled = true
205+
cfg.Events.DbServerTopQuery.Enabled = true
208206
scrapers, err = setupLogsScrapers(params, cfg)
209207
require.NoError(t, err)
210208
require.NotEmpty(t, scrapers)

receiver/sqlserverreceiver/internal/metadata/generated_config.go

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

receiver/sqlserverreceiver/internal/metadata/generated_logs_test.go

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

receiver/sqlserverreceiver/metadata.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ attributes:
136136
## query sample
137137
client.address:
138138
description: Hostname or address of the client.
139-
type: string
139+
type: string
140140
client.port:
141141
description: TCP port used by the client.
142142
type: int
@@ -221,7 +221,7 @@ attributes:
221221

222222
events:
223223
db.server.top_query:
224-
enabled: true
224+
enabled: false
225225
description: top query
226226
attributes:
227227
- sqlserver.total_worker_time
@@ -240,7 +240,7 @@ events:
240240
- server.port
241241
- db.system.name
242242
db.server.query_sample:
243-
enabled: true
243+
enabled: false
244244
description: query sample
245245
attributes:
246246
- client.address

receiver/sqlserverreceiver/scraper_test.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
2727
)
2828

29-
func configureAllScraperMetrics(cfg *Config, enabled bool) {
29+
func configureAllScraperMetricsAndEvents(cfg *Config, enabled bool) {
3030
// Some of these metrics are enabled by default, but it's still helpful to include
3131
// in the case of using a config that may have previously disabled a metric.
3232
cfg.Metrics.SqlserverBatchRequestRate.Enabled = enabled
@@ -78,8 +78,10 @@ func configureAllScraperMetrics(cfg *Config, enabled bool) {
7878
cfg.Metrics.SqlserverTransactionWriteRate.Enabled = enabled
7979
cfg.Metrics.SqlserverUserConnectionCount.Enabled = enabled
8080

81-
cfg.TopQueryCollection.Enabled = enabled
82-
cfg.QuerySample.Enabled = enabled
81+
cfg.Events.DbServerTopQuery.Enabled = enabled
82+
cfg.Events.DbServerQuerySample.Enabled = enabled
83+
// cfg.TopQueryCollection.Enabled = enabled
84+
// cfg.QuerySample.Enabled = enabled
8385
}
8486

8587
func TestEmptyScrape(t *testing.T) {
@@ -94,7 +96,7 @@ func TestEmptyScrape(t *testing.T) {
9496

9597
// Ensure there aren't any scrapers when all metrics are disabled.
9698
// Disable all metrics manually that are enabled by default
97-
configureAllScraperMetrics(cfg, false)
99+
configureAllScraperMetricsAndEvents(cfg, false)
98100

99101
scrapers := setupSQLServerScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
100102
assert.Empty(t, scrapers)
@@ -111,7 +113,7 @@ func TestSuccessfulScrape(t *testing.T) {
111113
cfg.MetricsBuilderConfig.ResourceAttributes.ServerPort.Enabled = true
112114
assert.NoError(t, cfg.Validate())
113115

114-
configureAllScraperMetrics(cfg, true)
116+
configureAllScraperMetricsAndEvents(cfg, true)
115117

116118
scrapers := setupSQLServerScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
117119
assert.NotEmpty(t, scrapers)
@@ -167,7 +169,7 @@ func TestScrapeInvalidQuery(t *testing.T) {
167169

168170
assert.NoError(t, cfg.Validate())
169171

170-
configureAllScraperMetrics(cfg, true)
172+
configureAllScraperMetricsAndEvents(cfg, true)
171173
scrapers := setupSQLServerScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
172174
assert.NotNil(t, scrapers)
173175

@@ -194,12 +196,12 @@ func TestScrapeCacheAndDiff(t *testing.T) {
194196
cfg.Port = 1433
195197
cfg.Server = "0.0.0.0"
196198
cfg.MetricsBuilderConfig.ResourceAttributes.SqlserverInstanceName.Enabled = true
197-
cfg.TopQueryCollection.Enabled = true
199+
cfg.Events.DbServerTopQuery.Enabled = true
198200
assert.NoError(t, cfg.Validate())
199201

200-
configureAllScraperMetrics(cfg, false)
202+
configureAllScraperMetricsAndEvents(cfg, false)
201203

202-
cfg.TopQueryCollection.Enabled = true
204+
cfg.Events.DbServerTopQuery.Enabled = true
203205
scrapers := setupSQLServerLogsScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
204206
assert.NotNil(t, scrapers)
205207

@@ -349,11 +351,11 @@ func TestQueryTextAndPlanQuery(t *testing.T) {
349351
cfg.Port = 1433
350352
cfg.Server = "0.0.0.0"
351353
cfg.MetricsBuilderConfig.ResourceAttributes.SqlserverInstanceName.Enabled = true
352-
cfg.TopQueryCollection.Enabled = true
354+
cfg.Events.DbServerTopQuery.Enabled = true
353355
assert.NoError(t, cfg.Validate())
354356

355-
configureAllScraperMetrics(cfg, false)
356-
cfg.TopQueryCollection.Enabled = true
357+
configureAllScraperMetricsAndEvents(cfg, false)
358+
cfg.Events.DbServerTopQuery.Enabled = true
357359
cfg.TopQueryCollection.CollectionInterval = cfg.ControllerConfig.CollectionInterval
358360

359361
scrapers := setupSQLServerLogsScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
@@ -409,11 +411,11 @@ func TestInvalidQueryTextAndPlanQuery(t *testing.T) {
409411
cfg.Password = "password"
410412
cfg.Port = 1433
411413
cfg.Server = "0.0.0.0"
412-
cfg.TopQueryCollection.Enabled = true
414+
cfg.Events.DbServerTopQuery.Enabled = true
413415
assert.NoError(t, cfg.Validate())
414416

415-
configureAllScraperMetrics(cfg, false)
416-
cfg.TopQueryCollection.Enabled = true
417+
configureAllScraperMetricsAndEvents(cfg, false)
418+
cfg.Events.DbServerTopQuery.Enabled = true
417419

418420
scrapers := setupSQLServerLogsScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
419421
assert.NotNil(t, scrapers)
@@ -508,8 +510,8 @@ func TestRecordDatabaseSampleQuery(t *testing.T) {
508510
cfg.MetricsBuilderConfig.ResourceAttributes.SqlserverInstanceName.Enabled = true
509511
assert.NoError(t, cfg.Validate())
510512

511-
configureAllScraperMetrics(cfg, false)
512-
cfg.QuerySample.Enabled = true
513+
configureAllScraperMetricsAndEvents(cfg, false)
514+
cfg.Events.DbServerQuerySample.Enabled = true
513515

514516
scrapers := setupSQLServerLogsScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
515517
assert.NotNil(t, scrapers)

receiver/sqlserverreceiver/testdata/config.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ sqlserver/named:
1515
server.address:
1616
enabled: true
1717
top_query_collection:
18-
enabled: true
1918
lookback_time: 60
2019
max_query_sample_count: 1000
2120
top_query_count: 200
2221
query_sample_collection:
23-
enabled: true
24-
max_rows_per_query: 1450
22+
max_rows_per_query: 1450

0 commit comments

Comments
 (0)