Skip to content

Commit 0766b50

Browse files
committed
Receive: fix thanos_receive_write_{timeseries,samples} stats
There are two path data can be written to a receiver: through the HTTP or the gRPC endpoint, and `thanos_receive_write_{timeseries,samples}` only count the number of timeseries/samples received through the HTTP endpoint. So, there is no risk that a sample will be counted twice, once as a remote write and once as a local write. On the other hand, we still need to account for the replication factor, and only count local writes is not enough as there might be no local writes at all (e.g. in RouterOnly mode). Signed-off-by: Mikhail Nozdrachev <[email protected]>
1 parent 1040f7b commit 0766b50

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
1616
- [#7592](https://github.com/thanos-io/thanos/pull/7592) Ruler: Only increment `thanos_rule_evaluation_with_warnings_total` metric for non PromQL warnings.
1717
- [#7614](https://github.com/thanos-io/thanos/pull/7614) *: fix debug log formatting.
1818
- [#7492](https://github.com/thanos-io/thanos/pull/7492) Compactor: update filtered blocks list before second downsample pass.
19+
- [#7643](https://github.com/thanos-io/thanos/pull/7643) Receive: fix thanos_receive_write_{timeseries,samples} stats
1920

2021
### Added
2122

pkg/receive/handler.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ type remoteWriteParams struct {
681681
alreadyReplicated bool
682682
}
683683

684-
func (h *Handler) gatherWriteStats(writes ...map[endpointReplica]map[string]trackedSeries) tenantRequestStats {
684+
func (h *Handler) gatherWriteStats(rf int, writes ...map[endpointReplica]map[string]trackedSeries) tenantRequestStats {
685685
var stats tenantRequestStats = make(tenantRequestStats)
686686

687687
for _, write := range writes {
@@ -708,8 +708,14 @@ func (h *Handler) gatherWriteStats(writes ...map[endpointReplica]map[string]trac
708708
}
709709
}
710710

711-
return stats
711+
// adjust counters by the replication factor
712+
for tenant, st := range stats {
713+
st.timeseries /= rf
714+
st.totalSamples /= rf
715+
stats[tenant] = st
716+
}
712717

718+
return stats
713719
}
714720

715721
func (h *Handler) fanoutForward(ctx context.Context, params remoteWriteParams) (tenantRequestStats, error) {
@@ -739,7 +745,7 @@ func (h *Handler) fanoutForward(ctx context.Context, params remoteWriteParams) (
739745
return stats, err
740746
}
741747

742-
stats = h.gatherWriteStats(localWrites, remoteWrites)
748+
stats = h.gatherWriteStats(len(params.replicas), localWrites, remoteWrites)
743749

744750
// Prepare a buffered channel to receive the responses from the local and remote writes. Remote writes will all go
745751
// asynchronously and with this capacity we will never block on writing to the channel.

0 commit comments

Comments
 (0)