func (w *StatsWriter) buildPayloads(sp pb.StatsPayload, maxEntriesPerPayload int) []pb.StatsPayload {
	split := splitPayloads(sp.Stats, maxEntriesPerPayload)
	grouped := make([]pb.StatsPayload, 0, len(sp.Stats))
	current := pb.StatsPayload{
		AgentHostname:  sp.AgentHostname,
		AgentEnv:       sp.AgentEnv,
		AgentVersion:   sp.AgentVersion,
		ClientComputed: sp.ClientComputed,
	}
	var nbEntries, nbBuckets int
	addPayload := func() {
		log.Debugf("Flushing %d entries (buckets=%d client_payloads=%d)", nbEntries, nbBuckets, len(current.Stats))
		atomic.AddInt64(&w.stats.StatsBuckets, int64(nbBuckets))
		atomic.AddInt64(&w.stats.ClientPayloads, int64(len(current.Stats)))
		atomic.AddInt64(&w.stats.StatsEntries, int64(nbEntries))
		grouped = append(grouped, current)
		current.Stats = nil
		nbEntries = 0
		nbBuckets = 0
	}
	for _, p := range split {
		if nbEntries+p.nbEntries > maxEntriesPerPayload {
			addPayload()
		}
		nbEntries += p.nbEntries
		nbBuckets += len(p.Stats)
		resolveContainerTags(&p.ClientStatsPayload)
		current.Stats = append(current.Stats, p.ClientStatsPayload)
	}
	if nbEntries > 0 {
		addPayload()
	}
	if len(grouped) > 1 {
		atomic.AddInt64(&w.stats.Splits, 1)
	}
	return grouped
}
// buildPayloads splits pb.ClientStatsPayload that have more than maxEntriesPerPayload
// and then groups them into pb.StatsPayload with less than maxEntriesPerPayload
buildPayloads splits pb.ClientStatsPayload that have more than maxEntriesPerPayload
and then groups them into pb.StatsPayload with less than maxEntriesPerPayload
// buildPayloads splits pb . ClientStatsPayload that have more than maxEntriesPerPayload // and then groups them into pb . StatsPayload with less than maxEntriesPerPayload
func (w *StatsWriter) buildPayloads(sp pb.StatsPayload, maxEntriesPerPayload int) []pb.StatsPayload {
	split := splitPayloads(sp.Stats, maxEntriesPerPayload)
	grouped := make([]pb.StatsPayload, 0, len(sp.Stats))
	current := pb.StatsPayload{
		AgentHostname:  sp.AgentHostname,
		AgentEnv:       sp.AgentEnv,
		AgentVersion:   sp.AgentVersion,
		ClientComputed: sp.ClientComputed,
	}
	var nbEntries, nbBuckets int
	addPayload := func() {
		log.Debugf("Flushing %d entries (buckets=%d client_payloads=%d)", nbEntries, nbBuckets, len(current.Stats))
		atomic.AddInt64(&w.stats.StatsBuckets, int64(nbBuckets))
		atomic.AddInt64(&w.stats.ClientPayloads, int64(len(current.Stats)))
		atomic.AddInt64(&w.stats.StatsEntries, int64(nbEntries))
		grouped = append(grouped, current)
		current.Stats = nil
		nbEntries = 0
		nbBuckets = 0
	}
	for _, p := range split {
		if nbEntries+p.nbEntries > maxEntriesPerPayload {
			addPayload()
		}
		nbEntries += p.nbEntries
		nbBuckets += len(p.Stats)
		resolveContainerTags(&p.ClientStatsPayload)
		current.Stats = append(current.Stats, p.ClientStatsPayload)
	}
	if nbEntries > 0 {
		addPayload()
	}
	if len(grouped) > 1 {
		atomic.AddInt64(&w.stats.Splits, 1)
	}
	return grouped
}
func ( w * StatsWriter ) buildPayloads ( sp pb . StatsPayload , maxEntriesPerPayload int ) [ ] pb . StatsPayload { split := splitPayloads ( sp . Stats , maxEntriesPerPayload ) grouped := make ( [ ] pb . StatsPayload , 0 , len ( sp . Stats ) ) current := pb . StatsPayload { AgentHostname : sp . AgentHostname , AgentEnv : sp . AgentEnv , AgentVersion : sp . AgentVersion , ClientComputed : sp . ClientComputed , } var nbEntries , nbBuckets int addPayload := func ( ) { log . Debugf ( " " , nbEntries , nbBuckets , len ( current . Stats ) ) atomic . AddInt64 ( & w . stats . StatsBuckets , int64 ( nbBuckets ) ) atomic . AddInt64 ( & w . stats . ClientPayloads , int64 ( len ( current . Stats ) ) ) atomic . AddInt64 ( & w . stats . StatsEntries , int64 ( nbEntries ) ) grouped = append ( grouped , current ) current . Stats = nil nbEntries = 0 nbBuckets = 0 } for _ , p := range split { if nbEntries + p . nbEntries > maxEntriesPerPayload { addPayload ( ) } nbEntries += p . nbEntries nbBuckets += len ( p . Stats ) resolveContainerTags ( & p . ClientStatsPayload ) current . Stats = append ( current . Stats , p . ClientStatsPayload ) } if nbEntries > 0 { addPayload ( ) } if len ( grouped ) > 1 { atomic . AddInt64 ( & w . stats . Splits , 1 ) } return grouped }
buildPayloads splits pb.ClientStatsPayload that have more than maxEntriesPerPayload
and then groups them into pb.StatsPayload with less than maxEntriesPerPayload
buildPayloads splits pb . ClientStatsPayload that have more than maxEntriesPerPayload and then groups them into pb . StatsPayload with less than maxEntriesPerPayload