Skip to content

Commit

Permalink
Receive: fix thanos_receive_write_{timeseries,samples} stats
Browse files Browse the repository at this point in the history
There are two path a 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 count 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).
  • Loading branch information
cincinnat committed Aug 15, 2024
1 parent 43f3704 commit 44490ea
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/receive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,11 @@ type remoteWriteParams struct {

func (h *Handler) gatherWriteStats(writes ...map[endpointReplica]map[string]trackedSeries) tenantRequestStats {
var stats tenantRequestStats = make(tenantRequestStats)
var rf int = 0

for _, write := range writes {
rf += len(write)

for er := range write {
for tenant, series := range write[er] {
samples := 0
Expand All @@ -708,8 +711,13 @@ func (h *Handler) gatherWriteStats(writes ...map[endpointReplica]map[string]trac
}
}

return stats
// adjust samples counters by the replication factor
for tenant, st := range stats {
st.totalSamples /= rf
stats[tenant] = st
}

return stats
}

func (h *Handler) fanoutForward(ctx context.Context, params remoteWriteParams) (tenantRequestStats, error) {
Expand Down

0 comments on commit 44490ea

Please sign in to comment.