Skip to content
Merged
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
35 changes: 27 additions & 8 deletions bigtable/metrics_monitoring_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,40 @@ func (me *monitoringExporter) exportTimeSeries(ctx context.Context, rm *otelmetr

name := fmt.Sprintf("projects/%s", me.projectID)

errs := []error{err}
var wg sync.WaitGroup
errs := make(chan error, len(tss)/sendBatchSize+1)
if err != nil {
errs <- err
}

for i := 0; i < len(tss); i += sendBatchSize {
j := i + sendBatchSize
if j >= len(tss) {
if j > len(tss) {
j = len(tss)
}

req := &monitoringpb.CreateTimeSeriesRequest{
Name: name,
TimeSeries: tss[i:j],
}
errs = append(errs, me.client.CreateServiceTimeSeries(ctx, req))
wg.Add(1)
go func(i, j int) {
defer wg.Done()
req := &monitoringpb.CreateTimeSeriesRequest{
Name: name,
TimeSeries: tss[i:j],
}
if err := me.client.CreateServiceTimeSeries(ctx, req); err != nil {
errs <- err
}
}(i, j)
}

wg.Wait()
close(errs)

var allErrors []error
for err := range errs {
allErrors = append(allErrors, err)
}

return errors.Join(errs...)
return errors.Join(allErrors...)
}

// recordToMetricAndMonitoredResourcePbs converts data from records to Metric and Monitored resource proto type for Cloud Monitoring.
Expand Down
Loading