Skip to content

Commit a7af721

Browse files
authored
Standardize unit interpretation of lookback_time in config for top_query_collection (open-telemetry#43618)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description As a standard, all type of interval values in collector config currently requires an 's' suffix to interpret the unit. But the recently introduced lookback_time in top_query_collection does not follow this pattern. This needs to be fixed to maintain consistency and avoid ambiguity in unit interpretation. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#43573 <!--Describe what testing was performed and which tests were added.--> #### Testing Unit tests updated
1 parent 1ad45b9 commit a7af721

File tree

8 files changed

+37
-9
lines changed

8 files changed

+37
-9
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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: 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: Standardizing the unit interpretation of lookback_time in config for 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: [43573]
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+
Like other interval related config values, lookback_time also should suffix 's' to represent time in seconds.
20+
21+
# If your change doesn't affect end users or the exported elements of any package,
22+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: [user]

receiver/sqlserverreceiver/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ sqlserver:
5959
db.server.top_query:
6060
enabled: true
6161
top_query_collection: # this collection exports the most expensive queries as logs
62-
lookback_time: 60 # which time window should we look for the top queries
62+
lookback_time: 60s # which time window should we look for the top queries
6363
max_query_sample_count: 1000 # maximum number query we store in cache for top queries.
6464
top_query_count: 200 # The maximum number of active queries to report in a single run.
6565
collection_interval: 60s # collection interval for top query collection specifically
@@ -87,7 +87,7 @@ Windows-specific options:
8787
If specified, `instance_name` is also required to be defined. This option is ignored in non-Windows environments.
8888

8989
Top-Query collection specific options (only useful when top-query collection are enabled):
90-
- `lookback_time` (optional, example = `60`, default = `2 * collection_interval`): The time window (in second) in which to query for top queries.
90+
- `lookback_time` (optional, example = `60s`, default = `2 * collection_interval`): The time window (in second) in which to query for top queries.
9191
- Queries that were finished execution outside the lookback window are not included in the collection. Increasing the lookback window (in seconds) will be useful for capturing long-running queries.
9292
- `max_query_sample_count` (optional, example = `5000`, default = `1000`): The maximum number of records to fetch in a single run.
9393
- `top_query_count`: (optional, example = `100`, default = `200`): The maximum number of active queries to report (to the next consumer) in a single run.
@@ -143,7 +143,7 @@ Top query collection enabled:
143143
server: 0.0.0.0
144144
port: 1433
145145
top_query_collection:
146-
lookback_time: 60
146+
lookback_time: 60s
147147
max_query_sample_count: 1000
148148
top_query_count: 200
149149
query_sample_collection:

receiver/sqlserverreceiver/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type TopQueryCollection struct {
2626
// The query statement will also be reported, hence, it is not ideal to send it as a metric. Hence
2727
// we are reporting them as logs.
2828
// The `N` is configured via `TopQueryCount`
29-
LookbackTime uint `mapstructure:"lookback_time"`
29+
LookbackTime time.Duration `mapstructure:"lookback_time"`
3030
MaxQuerySampleCount uint `mapstructure:"max_query_sample_count"`
3131
TopQueryCount uint `mapstructure:"top_query_count"`
3232
CollectionInterval time.Duration `mapstructure:"collection_interval"`

receiver/sqlserverreceiver/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func TestLoadConfig(t *testing.T) {
197197
}
198198
expected.ComputerName = "CustomServer"
199199
expected.InstanceName = "CustomInstance"
200-
expected.LookbackTime = 60
200+
expected.LookbackTime = 60 * time.Second
201201
expected.TopQueryCount = 200
202202
expected.MaxQuerySampleCount = 1000
203203
expected.TopQueryCollection.CollectionInterval = 80 * time.Second

receiver/sqlserverreceiver/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func createDefaultConfig() component.Config {
5656
MaxRowsPerQuery: 100,
5757
},
5858
TopQueryCollection: TopQueryCollection{
59-
LookbackTime: uint(2 * cfg.CollectionInterval / time.Second),
59+
LookbackTime: 2 * cfg.CollectionInterval / time.Second,
6060
MaxQuerySampleCount: 1000,
6161
TopQueryCount: 200,
6262
CollectionInterval: time.Minute,

receiver/sqlserverreceiver/factory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestFactory(t *testing.T) {
4343
InitialDelay: time.Second,
4444
},
4545
TopQueryCollection: TopQueryCollection{
46-
LookbackTime: uint(2 * 10),
46+
LookbackTime: 2 * 10,
4747
MaxQuerySampleCount: 1000,
4848
TopQueryCount: 200,
4949
CollectionInterval: time.Minute,

receiver/sqlserverreceiver/scraper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Cont
643643

644644
rows, err := s.client.QueryRows(
645645
ctx,
646-
sql.Named("lookbackTime", -s.config.LookbackTime),
646+
sql.Named("lookbackTime", -int(s.config.LookbackTime.Seconds())),
647647
sql.Named("topNValue", s.config.TopQueryCount),
648648
)
649649
if err != nil {

receiver/sqlserverreceiver/testdata/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sqlserver/named:
1717
service.instance.id:
1818
enabled: false
1919
top_query_collection:
20-
lookback_time: 60
20+
lookback_time: 60s
2121
max_query_sample_count: 1000
2222
top_query_count: 200
2323
collection_interval: 80s

0 commit comments

Comments
 (0)