diff --git a/plugins/outputs/loki/stream.go b/plugins/outputs/loki/stream.go index 5af31f94e2744..5f1687ef2fb3b 100644 --- a/plugins/outputs/loki/stream.go +++ b/plugins/outputs/loki/stream.go @@ -59,7 +59,7 @@ func uniqKeyFromTagList(ts []*telegraf.Tag) (k string) { func newStream(ts []*telegraf.Tag) *Stream { s := &Stream{ Logs: make([]Log, 0), - Labels: make(map[string]string), + Labels: make(map[string]string, len(ts)), } for _, t := range ts { diff --git a/plugins/outputs/mongodb/mongodb.go b/plugins/outputs/mongodb/mongodb.go index 5847e0d5eb5a0..60dc930bfca7d 100644 --- a/plugins/outputs/mongodb/mongodb.go +++ b/plugins/outputs/mongodb/mongodb.go @@ -26,11 +26,11 @@ import ( var sampleConfig string func (s *MongoDB) getCollections(ctx context.Context) error { - s.collections = make(map[string]bson.M) collections, err := s.client.Database(s.MetricDatabase).ListCollections(ctx, bson.M{}) if err != nil { return fmt.Errorf("unable to execute ListCollections: %w", err) } + s.collections = make(map[string]bson.M, collections.RemainingBatchLength()) for collections.Next(ctx) { var collection bson.M if err = collections.Decode(&collection); err != nil { @@ -229,5 +229,9 @@ func (s *MongoDB) Write(metrics []telegraf.Metric) error { } func init() { - outputs.Add("mongodb", func() telegraf.Output { return &MongoDB{} }) + outputs.Add("mongodb", func() telegraf.Output { + return &MongoDB{ + collections: make(map[string]bson.M), + } + }) }