Skip to content

Commit 4bfe6a7

Browse files
Naman-B-Parlechadashpolesongy23
authored
fix(receiver/prometheusremotewrite): count target_info samples in PRW response stats (#47108)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description > "we got 2xx status code from the Receiver yet statistics indicate some data was not written" This is due to target_info not being counted in samples leading to miss match count as mentioned in the [commet](#45150 (comment)) <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #45150 <!--Describe what testing was performed and which tests were added.--> #### Testing Added Sub-Test in TestTranslateV2 with - `service with only target_info metric` to verify stats are counted when target_info - Verified exising test `service with target_info metric` passes <!--Please delete paragraphs that you did not use before submitting.--> --------- Signed-off-by: Naman-B-Parlecha <naman.parlecha@finalroundai.com> Signed-off-by: Naman-B-Parlecha <namanparlecha@gmail.com> Co-authored-by: David Ashpole <dashpole@google.com> Co-authored-by: Yang Song <songy23@users.noreply.github.com>
1 parent fa1caec commit 4bfe6a7

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

.chloggen/47108.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. receiver/filelog)
7+
component: receiver/prometheus_remote_write
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Count target_info samples in PRW response stats
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: [47108]
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: []

receiver/prometheusremotewritereceiver/receiver.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
342342
snapshot := pmetric.NewResourceMetrics()
343343
attrs.CopyTo(snapshot.Resource().Attributes())
344344
prw.rmCache.Add(hashed, snapshot)
345+
// target_info is not stored as a metric but PRW requires the response
346+
// to report all received samples, including target_info, to avoid a stats mismatch
347+
stats.Samples += len(ts.Samples)
345348
continue
346349
}
347350

receiver/prometheusremotewritereceiver/receiver_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,48 @@ func TestTranslateV2(t *testing.T) {
22552255
Confirmed: true,
22562256
},
22572257
},
2258+
{
2259+
name: "service with only target_info metric",
2260+
request: &writev2.Request{
2261+
Symbols: []string{
2262+
"",
2263+
"job", "production/service_a", // 1, 2
2264+
"instance", "host1", // 3, 4
2265+
"machine_type", "n1-standard-1", // 5, 6
2266+
"cloud_provider", "gcp", // 7, 8
2267+
"region", "us-central1", // 9, 10
2268+
"datacenter", "sdc", // 11, 12
2269+
"__name__", "target_info", // 13, 14
2270+
},
2271+
Timeseries: []writev2.TimeSeries{
2272+
{
2273+
// target_info metric
2274+
Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE},
2275+
LabelsRefs: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},
2276+
Samples: []writev2.Sample{{Value: 1, Timestamp: 1}},
2277+
},
2278+
},
2279+
},
2280+
expectedMetrics: func() pmetric.Metrics {
2281+
metrics := pmetric.NewMetrics()
2282+
rm := metrics.ResourceMetrics().AppendEmpty()
2283+
attrs := rm.Resource().Attributes()
2284+
attrs.PutStr("service.namespace", "production")
2285+
attrs.PutStr("service.name", "service_a")
2286+
attrs.PutStr("service.instance.id", "host1")
2287+
attrs.PutStr("machine_type", "n1-standard-1")
2288+
attrs.PutStr("cloud_provider", "gcp")
2289+
attrs.PutStr("region", "us-central1")
2290+
attrs.PutStr("datacenter", "sdc")
2291+
return metrics
2292+
}(),
2293+
expectedStats: remote.WriteResponseStats{
2294+
Confirmed: true,
2295+
Samples: 1,
2296+
Histograms: 0,
2297+
Exemplars: 0,
2298+
},
2299+
},
22582300
} {
22592301
t.Run(tc.name, func(t *testing.T) {
22602302
// since we are using the rmCache to store values across requests, we need to clear it after each test, otherwise it will affect the next test

0 commit comments

Comments
 (0)