Skip to content

[receiver/sqlserver] Remove duplicated flags for enabling top query c… #40416

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

Merged
Merged
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
29 changes: 29 additions & 0 deletions .chloggen/sqlserver-remove-extra-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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: Rename flags for enabling top query collection and query sample collection.

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

# (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: |
Renamed `top_query_collection.enabled` to `events."db.server.top_query".enabled` in top query collection.
Renamed `query_sample_collection.enabled` to `events."db.server.query_sample".enabled` in query sample collection.

# 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: [user]
5 changes: 3 additions & 2 deletions receiver/sqlserverreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
)

type QuerySample struct {
Enabled bool `mapstructure:"enabled"`
MaxRowsPerQuery uint64 `mapstructure:"max_rows_per_query"`

// prevent unkeyed literal initialization
_ struct{}
}

type TopQueryCollection struct {
Expand All @@ -24,7 +26,6 @@ type TopQueryCollection struct {
// The query statement will also be reported, hence, it is not ideal to send it as a metric. Hence
// we are reporting them as logs.
// The `N` is configured via `TopQueryCount`
Enabled bool `mapstructure:"enabled"`
LookbackTime uint `mapstructure:"lookback_time"`
MaxQuerySampleCount uint `mapstructure:"max_query_sample_count"`
TopQueryCount uint `mapstructure:"top_query_count"`
Expand Down
2 changes: 0 additions & 2 deletions receiver/sqlserverreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,11 @@ func TestLoadConfig(t *testing.T) {
}
expected.ComputerName = "CustomServer"
expected.InstanceName = "CustomInstance"
expected.TopQueryCollection.Enabled = true
expected.LookbackTime = 60
expected.TopQueryCount = 200
expected.MaxQuerySampleCount = 1000

expected.QuerySample = QuerySample{
Enabled: true,
MaxRowsPerQuery: 1450,
}

Expand Down
66 changes: 0 additions & 66 deletions receiver/sqlserverreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,72 +539,6 @@ events:
enabled: false
```

### db.server.query_sample

query sample

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| client.address | Hostname or address of the client. | Any Str |
| client.port | TCP port used by the client. | Any Int |
| db.namespace | The database name. | Any Str |
| db.query.text | The text of the database query being executed. | Any Str |
| db.system.name | The database management system (DBMS) product as identified by the client instrumentation. | Any Str |
| network.peer.address | IP address of the peer client. | Any Str |
| network.peer.port | TCP port used by the peer client. | Any Int |
| sqlserver.blocking_session_id | Session ID that is blocking the current session. 0 if none. | Any Int |
| sqlserver.context_info | Context information for the session, represented as a hexadecimal string. | Any Str |
| sqlserver.command | SQL command type being executed. | Any Str |
| sqlserver.cpu_time | CPU time consumed by the query, in seconds. | Any Double |
| sqlserver.deadlock_priority | Deadlock priority value for the session. | Any Int |
| sqlserver.estimated_completion_time | Estimated time remaining for the request to complete, in seconds. | Any Double |
| sqlserver.lock_timeout | Lock timeout value in seconds. | Any Double |
| sqlserver.logical_reads | Number of logical reads (data read from cache/memory). | Any Int |
| sqlserver.open_transaction_count | Number of transactions currently open in the session. | Any Int |
| sqlserver.percent_complete | Percentage of work completed. | Any Double |
| 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 |
| 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 |
| sqlserver.query_start | Timestamp of when the SQL query started (ISO 8601 format). | Any Str |
| sqlserver.reads | Number of physical reads performed by the query. | Any Int |
| sqlserver.request_status | Status of the request (e.g., running, suspended). | Any Str |
| sqlserver.row_count | Number of rows affected or returned by the query. | Any Int |
| sqlserver.session_id | ID of the SQL Server session. | Any Int |
| sqlserver.session_status | Status of the session (e.g., running, sleeping). | Any Str |
| sqlserver.total_elapsed_time | Total elapsed time for completed executions of this plan, reported in delta seconds. | Any Double |
| sqlserver.transaction_id | Unique ID of the active transaction. | Any Int |
| sqlserver.transaction_isolation_level | Transaction isolation level used in the session. Represented as numeric constant. | Any Int |
| sqlserver.wait_resource | The resource for which the session is waiting. | Any Str |
| sqlserver.wait_time | Duration in seconds the request has been waiting. | Any Double |
| sqlserver.wait_type | Type of wait encountered by the request. Empty if none. | Any Str |
| sqlserver.writes | Number of writes performed by the query. | Any Int |
| user.name | Login name associated with the SQL Server session. | Any Str |

### db.server.top_query

top query

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| 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 |
| db.query.text | The text of the database query being executed. | Any Str |
| sqlserver.execution_count | Number of times that the plan has been executed since it was last compiled, reported in delta value. | Any Int |
| 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 |
| 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 |
| 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 |
| 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 |
| sqlserver.query_plan | The query execution plan used by the SQL Server. | Any Str |
| 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 |
| sqlserver.total_rows | Total number of rows returned by the query, reported in delta value. | Any Int |
| sqlserver.total_elapsed_time | Total elapsed time for completed executions of this plan, reported in delta seconds. | Any Double |
| 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 |
| server.address | The network address of the server hosting the database. | Any Str |
| server.port | The port number on which the server is listening. | Any Int |
| db.system.name | The database management system (DBMS) product as identified by the client instrumentation. | Any Str |

## Resource Attributes

| Name | Description | Values | Enabled |
Expand Down
6 changes: 2 additions & 4 deletions receiver/sqlserverreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ func createDefaultConfig() component.Config {
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
LogsBuilderConfig: metadata.DefaultLogsBuilderConfig(),
QuerySample: QuerySample{
Enabled: false,
MaxRowsPerQuery: 100,
},
TopQueryCollection: TopQueryCollection{
Enabled: false,
LookbackTime: uint(2 * cfg.CollectionInterval / time.Second),
MaxQuerySampleCount: 1000,
TopQueryCount: 200,
Expand Down Expand Up @@ -91,11 +89,11 @@ func setupQueries(cfg *Config) []string {
func setupLogQueries(cfg *Config) []string {
var queries []string

if cfg.QuerySample.Enabled {
if cfg.Events.DbServerQuerySample.Enabled {
queries = append(queries, getSQLServerQuerySamplesQuery())
}

if cfg.TopQueryCollection.Enabled {
if cfg.Events.DbServerTopQuery.Enabled {
queries = append(queries, getSQLServerQueryTextAndPlanQuery())
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/sqlserverreceiver/factory_others_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestFactoryOtherOS(t *testing.T) {
require.Empty(t, sqlScrapers)

cfg.InstanceName = "instanceName"
cfg.TopQueryCollection.Enabled = true
cfg.Events.DbServerTopQuery.Enabled = true
scrapers, err = setupLogsScrapers(params, cfg)
require.NoError(t, err)
require.NotEmpty(t, scrapers)
Expand Down
4 changes: 1 addition & 3 deletions receiver/sqlserverreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ func TestFactory(t *testing.T) {
InitialDelay: time.Second,
},
TopQueryCollection: TopQueryCollection{
Enabled: false,
LookbackTime: uint(2 * 10),
MaxQuerySampleCount: 1000,
TopQueryCount: 200,
CollectionInterval: time.Minute,
},
QuerySample: QuerySample{
Enabled: false,
MaxRowsPerQuery: 100,
},
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
Expand Down Expand Up @@ -204,7 +202,7 @@ func TestFactory(t *testing.T) {
require.Empty(t, sqlScrapers)

cfg.InstanceName = "instanceName"
cfg.TopQueryCollection.Enabled = true
cfg.Events.DbServerTopQuery.Enabled = true
scrapers, err = setupLogsScrapers(params, cfg)
require.NoError(t, err)
require.NotEmpty(t, scrapers)
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.

6 changes: 3 additions & 3 deletions receiver/sqlserverreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ attributes:
## query sample
client.address:
description: Hostname or address of the client.
type: string
type: string
client.port:
description: TCP port used by the client.
type: int
Expand Down Expand Up @@ -221,7 +221,7 @@ attributes:

events:
db.server.top_query:
enabled: true
enabled: false
description: top query
attributes:
- sqlserver.total_worker_time
Expand All @@ -240,7 +240,7 @@ events:
- server.port
- db.system.name
db.server.query_sample:
enabled: true
enabled: false
description: query sample
attributes:
- client.address
Expand Down
36 changes: 19 additions & 17 deletions receiver/sqlserverreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
)

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

cfg.TopQueryCollection.Enabled = enabled
cfg.QuerySample.Enabled = enabled
cfg.Events.DbServerTopQuery.Enabled = enabled
cfg.Events.DbServerQuerySample.Enabled = enabled
// cfg.TopQueryCollection.Enabled = enabled
// cfg.QuerySample.Enabled = enabled
}

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

// Ensure there aren't any scrapers when all metrics are disabled.
// Disable all metrics manually that are enabled by default
configureAllScraperMetrics(cfg, false)
configureAllScraperMetricsAndEvents(cfg, false)

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

configureAllScraperMetrics(cfg, true)
configureAllScraperMetricsAndEvents(cfg, true)

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

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

configureAllScraperMetrics(cfg, true)
configureAllScraperMetricsAndEvents(cfg, true)
scrapers := setupSQLServerScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
assert.NotNil(t, scrapers)

Expand All @@ -194,12 +196,12 @@ func TestScrapeCacheAndDiff(t *testing.T) {
cfg.Port = 1433
cfg.Server = "0.0.0.0"
cfg.MetricsBuilderConfig.ResourceAttributes.SqlserverInstanceName.Enabled = true
cfg.TopQueryCollection.Enabled = true
cfg.Events.DbServerTopQuery.Enabled = true
assert.NoError(t, cfg.Validate())

configureAllScraperMetrics(cfg, false)
configureAllScraperMetricsAndEvents(cfg, false)

cfg.TopQueryCollection.Enabled = true
cfg.Events.DbServerTopQuery.Enabled = true
scrapers := setupSQLServerLogsScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
assert.NotNil(t, scrapers)

Expand Down Expand Up @@ -349,11 +351,11 @@ func TestQueryTextAndPlanQuery(t *testing.T) {
cfg.Port = 1433
cfg.Server = "0.0.0.0"
cfg.MetricsBuilderConfig.ResourceAttributes.SqlserverInstanceName.Enabled = true
cfg.TopQueryCollection.Enabled = true
cfg.Events.DbServerTopQuery.Enabled = true
assert.NoError(t, cfg.Validate())

configureAllScraperMetrics(cfg, false)
cfg.TopQueryCollection.Enabled = true
configureAllScraperMetricsAndEvents(cfg, false)
cfg.Events.DbServerTopQuery.Enabled = true
cfg.TopQueryCollection.CollectionInterval = cfg.ControllerConfig.CollectionInterval

scrapers := setupSQLServerLogsScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
Expand Down Expand Up @@ -409,11 +411,11 @@ func TestInvalidQueryTextAndPlanQuery(t *testing.T) {
cfg.Password = "password"
cfg.Port = 1433
cfg.Server = "0.0.0.0"
cfg.TopQueryCollection.Enabled = true
cfg.Events.DbServerTopQuery.Enabled = true
assert.NoError(t, cfg.Validate())

configureAllScraperMetrics(cfg, false)
cfg.TopQueryCollection.Enabled = true
configureAllScraperMetricsAndEvents(cfg, false)
cfg.Events.DbServerTopQuery.Enabled = true

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

configureAllScraperMetrics(cfg, false)
cfg.QuerySample.Enabled = true
configureAllScraperMetricsAndEvents(cfg, false)
cfg.Events.DbServerQuerySample.Enabled = true

scrapers := setupSQLServerLogsScrapers(receivertest.NewNopSettings(metadata.Type), cfg)
assert.NotNil(t, scrapers)
Expand Down
4 changes: 1 addition & 3 deletions receiver/sqlserverreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ sqlserver/named:
server.address:
enabled: true
top_query_collection:
enabled: true
lookback_time: 60
max_query_sample_count: 1000
top_query_count: 200
query_sample_collection:
enabled: true
max_rows_per_query: 1450
max_rows_per_query: 1450