Skip to content

Commit 7c058a5

Browse files
sv-splunkcrobert-1
andauthored
receiver/postgresql - Fixing the field name client_addr in query_sample collection (#42446)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description In the field mapping of query_sample attributes in client.go, we are currently mapping `currentAttributes["network.peer.address"] = row["client_addrs"], and in this line client_addrs is misspelled. Actual field name in pg_stat_activity table is client_addr. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #42447 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Curtis Robert <[email protected]>
1 parent dc5c284 commit 7c058a5

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

.chloggen/pg-client_addr-fix.yaml

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: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: postgresqlreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Properly set `network.peer.address` attribute
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: [42447]
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: [user]

receiver/postgresqlreceiver/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ func (c *postgreSQLClient) getQuerySamples(ctx context.Context, limit int64, new
945945
}
946946
currentAttributes[dbPrefix+"pid"] = pid
947947
currentAttributes["network.peer.port"] = clientPort
948-
currentAttributes["network.peer.address"] = row["client_addrs"]
948+
currentAttributes["network.peer.address"] = row["client_addr"]
949949
currentAttributes["db.query.text"] = obfuscated
950950
currentAttributes["db.namespace"] = row["datname"]
951951
currentAttributes["user.name"] = row["usename"]

receiver/postgresqlreceiver/scraper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func TestScrapeQuerySample(t *testing.T) {
426426
scraper := newPostgreSQLScraper(settings, cfg, factory, newCache(1), newTTLCache[string](1, time.Second))
427427
scraper.newestQueryTimestamp = 123440.111
428428
mock.ExpectQuery(expectedScrapeSampleQuery).WillReturnRows(sqlmock.NewRows(
429-
[]string{"datname", "usename", "client_addrs", "client_hostname", "client_port", "query_start", "wait_event_type", "wait_event", "query_id", "pid", "application_name", "_query_start_timestamp", "state", "query", "duration_ms"},
429+
[]string{"datname", "usename", "client_addr", "client_hostname", "client_port", "query_start", "wait_event_type", "wait_event", "query_id", "pid", "application_name", "_query_start_timestamp", "state", "query", "duration_ms"},
430430
).FromCSVString("postgres,otelu,11.4.5.14,otel,114514,2025-02-12T16:37:54.843+08:00,,,123131231231,1450,receiver,123445.123,idle,select * from pg_stat_activity where id = 32,1.2"))
431431
actualLogs, err := scraper.scrapeQuerySamples(t.Context(), 30)
432432
assert.NoError(t, err)

receiver/postgresqlreceiver/testdata/scraper/query-sample/expected.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ resourceLogs:
5050
doubleValue: 1.2
5151
body: {}
5252
eventName: db.server.query_sample
53-
timeUnixNano: "1755817062035258000"
53+
timeUnixNano: "1758612388939691000"
5454
scope:
5555
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/postgresqlreceiver
5656
version: latest

0 commit comments

Comments
 (0)