Skip to content
Closed
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
4 changes: 2 additions & 2 deletions exp/api/remote/remote_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (r *API) Write(ctx context.Context, msgType WriteMessageType, msg any) (_ W
if err == nil {
// Check the case mentioned in PRW 2.0.
// https://prometheus.io/docs/specs/remote_write_spec_2_0/#required-written-response-headers.
if msgType == WriteV2MessageType && !accumulatedStats.confirmed && accumulatedStats.NoDataWritten() {
if msgType == WriteV2MessageType && !accumulatedStats.Confirmed && accumulatedStats.NoDataWritten() {
// TODO(bwplotka): Allow users to disable this check or provide their stats for us to know if it's empty.
return accumulatedStats, fmt.Errorf("sent v2 request; "+
"got 2xx, but PRW 2.0 response header statistics indicate %v samples, %v histograms "+
Expand Down Expand Up @@ -329,7 +329,7 @@ func (r *API) attemptWrite(ctx context.Context, compr Compression, msgType Write

rs := WriteResponseStats{}
if msgType == WriteV2MessageType {
rs, err = parseWriteResponseStats(resp)
rs, err = ParseWriteResponseStats(resp)
if err != nil {
r.opts.logger.Warn("parsing rw write statistics failed; partial or no stats", "err", err)
}
Expand Down
2 changes: 1 addition & 1 deletion exp/api/remote/remote_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func testV2() *writev2.Request {
}

func stats(req *writev2.Request) (s WriteResponseStats) {
s.confirmed = true
s.Confirmed = true
for _, ts := range req.Timeseries {
s.Samples += len(ts.Samples)
s.Histograms += len(ts.Histograms)
Expand Down
12 changes: 6 additions & 6 deletions exp/api/remote/remote_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type WriteResponseStats struct {
// of the PRW 2.0 spec. When parsed from headers, it means we got at least one
// response header from the Receiver to confirm those numbers, meaning it must
// be at least 2.0 Receiver. See ParseWriteResponseStats for details.
confirmed bool
Confirmed bool
}

// NoDataWritten returns true if statistics indicate no data was written.
Expand All @@ -173,7 +173,7 @@ func (s WriteResponseStats) AllSamples() int {
// Add adds the given WriteResponseStats to this WriteResponseStats.
// If this WriteResponseStats is empty, it will be replaced by the given WriteResponseStats.
func (s *WriteResponseStats) Add(rs WriteResponseStats) {
s.confirmed = rs.confirmed
s.Confirmed = rs.Confirmed
s.Samples += rs.Samples
s.Histograms += rs.Histograms
s.Exemplars += rs.Exemplars
Expand All @@ -187,27 +187,27 @@ func (s *WriteResponseStats) Add(rs WriteResponseStats) {
// s.Confirmed = true only when see at least on response header.
//
// Error is returned when any of the header fails to parse as int64.
func parseWriteResponseStats(r *http.Response) (s WriteResponseStats, err error) {
func ParseWriteResponseStats(r *http.Response) (s WriteResponseStats, err error) {
var (
errs []error
h = r.Header
)
if v := h.Get(writtenSamplesHeader); v != "" { // Empty means zero.
s.confirmed = true
s.Confirmed = true
if s.Samples, err = strconv.Atoi(v); err != nil {
s.Samples = 0
errs = append(errs, err)
}
}
if v := h.Get(writtenHistogramsHeader); v != "" { // Empty means zero.
s.confirmed = true
s.Confirmed = true
if s.Histograms, err = strconv.Atoi(v); err != nil {
s.Histograms = 0
errs = append(errs, err)
}
}
if v := h.Get(writtenExemplarsHeader); v != "" { // Empty means zero.
s.confirmed = true
s.Confirmed = true
if s.Exemplars, err = strconv.Atoi(v); err != nil {
s.Exemplars = 0
errs = append(errs, err)
Expand Down
8 changes: 4 additions & 4 deletions exp/api/remote/remote_headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestWriteResponse(t *testing.T) {
Samples: 10,
Histograms: 5,
Exemplars: 2,
confirmed: true,
Confirmed: true,
}
resp.Add(stats)
if diff := cmp.Diff(stats, resp.Stats(), cmpopts.IgnoreUnexported(WriteResponseStats{})); diff != "" {
Expand All @@ -53,14 +53,14 @@ func TestWriteResponse(t *testing.T) {
Samples: 10,
Histograms: 5,
Exemplars: 2,
confirmed: true,
Confirmed: true,
}
resp.Add(toAdd)
if diff := cmp.Diff(WriteResponseStats{
Samples: 20,
Histograms: 10,
Exemplars: 4,
confirmed: true,
Confirmed: true,
}, resp.Stats(), cmpopts.IgnoreUnexported(WriteResponseStats{})); diff != "" {
t.Errorf("stats mismatch (-want +got):\n%s", diff)
}
Expand All @@ -77,7 +77,7 @@ func TestWriteResponse(t *testing.T) {
Samples: 10,
Histograms: 5,
Exemplars: 2,
confirmed: true,
Confirmed: true,
})
resp.SetExtraHeader("Custom-Header", "custom-value")

Expand Down
Loading