From 1ccbe6fdd02e395cf04fb84d0803b4307689a07e Mon Sep 17 00:00:00 2001 From: Andy Xie Date: Thu, 11 Jan 2018 23:08:38 +0800 Subject: [PATCH] reduce labels for container info --- cache/memory/memory.go | 10 +++++----- cache/memory/memory_test.go | 26 +++++++++++++++----------- container/containerd/handler.go | 1 - container/containerd/handler_test.go | 1 - container/crio/handler.go | 1 - container/crio/handler_test.go | 1 - container/docker/handler.go | 1 - container/rkt/handler.go | 1 - info/v1/container.go | 2 -- manager/container.go | 7 ++++++- manager/manager_test.go | 13 +++++++++++-- storage/bigquery/bigquery.go | 16 ++++++++-------- storage/elasticsearch/elasticsearch.go | 12 ++++++------ storage/influxdb/influxdb.go | 24 ++++++++++++------------ storage/influxdb/influxdb_test.go | 4 ++-- storage/kafka/kafka.go | 12 ++++++------ storage/redis/redis.go | 12 ++++++------ storage/statsd/statsd.go | 8 ++++---- storage/stdout/stdout.go | 8 ++++---- storage/storage.go | 2 +- storage/test/mock.go | 4 ++-- storage/test/storagetests.go | 8 +++++--- 22 files changed, 93 insertions(+), 81 deletions(-) diff --git a/cache/memory/memory.go b/cache/memory/memory.go index ae8eb899..038f9b17 100644 --- a/cache/memory/memory.go +++ b/cache/memory/memory.go @@ -70,16 +70,16 @@ type InMemoryCache struct { backend storage.StorageDriver } -func (self *InMemoryCache) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { +func (self *InMemoryCache) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { var cstore *containerCache var ok bool func() { self.lock.Lock() defer self.lock.Unlock() - if cstore, ok = self.containerCacheMap[ref.Name]; !ok { - cstore = newContainerStore(ref, self.maxAge) - self.containerCacheMap[ref.Name] = cstore + if cstore, ok = self.containerCacheMap[cInfo.ContainerReference.Name]; !ok { + cstore = newContainerStore(cInfo.ContainerReference, self.maxAge) + self.containerCacheMap[cInfo.ContainerReference.Name] = cstore } }() @@ -87,7 +87,7 @@ func (self *InMemoryCache) AddStats(ref info.ContainerReference, stats *info.Con // TODO(monnand): To deal with long delay write operations, we // may want to start a pool of goroutines to do write // operations. - if err := self.backend.AddStats(ref, stats); err != nil { + if err := self.backend.AddStats(cInfo, stats); err != nil { glog.Error(err) } } diff --git a/cache/memory/memory_test.go b/cache/memory/memory_test.go index f1bfa7e5..769ee2cd 100644 --- a/cache/memory/memory_test.go +++ b/cache/memory/memory_test.go @@ -27,8 +27,10 @@ import ( const containerName = "/container" var ( - containerRef = info.ContainerReference{Name: containerName} - zero time.Time + cInfo = info.ContainerInfo{ + ContainerReference: info.ContainerReference{Name: containerName}, + } + zero time.Time ) // Make stats with the specified identifier. @@ -51,15 +53,17 @@ func TestAddStats(t *testing.T) { memoryCache := New(60*time.Second, nil) assert := assert.New(t) - assert.Nil(memoryCache.AddStats(containerRef, makeStat(0))) - assert.Nil(memoryCache.AddStats(containerRef, makeStat(1))) - assert.Nil(memoryCache.AddStats(containerRef, makeStat(2))) - assert.Nil(memoryCache.AddStats(containerRef, makeStat(0))) - containerRef2 := info.ContainerReference{ - Name: "/container2", + assert.Nil(memoryCache.AddStats(&cInfo, makeStat(0))) + assert.Nil(memoryCache.AddStats(&cInfo, makeStat(1))) + assert.Nil(memoryCache.AddStats(&cInfo, makeStat(2))) + assert.Nil(memoryCache.AddStats(&cInfo, makeStat(0))) + cInfo2 := info.ContainerInfo{ + ContainerReference: info.ContainerReference{ + Name: "/container2", + }, } - assert.Nil(memoryCache.AddStats(containerRef2, makeStat(0))) - assert.Nil(memoryCache.AddStats(containerRef2, makeStat(1))) + assert.Nil(memoryCache.AddStats(&cInfo2, makeStat(0))) + assert.Nil(memoryCache.AddStats(&cInfo2, makeStat(1))) } func TestRecentStatsNoRecentStats(t *testing.T) { @@ -74,7 +78,7 @@ func makeWithStats(n int) *InMemoryCache { memoryCache := New(60*time.Second, nil) for i := 0; i < n; i++ { - memoryCache.AddStats(containerRef, makeStat(i)) + memoryCache.AddStats(&cInfo, makeStat(i)) } return memoryCache } diff --git a/container/containerd/handler.go b/container/containerd/handler.go index b369d9b1..0ea7ee92 100644 --- a/container/containerd/handler.go +++ b/container/containerd/handler.go @@ -148,7 +148,6 @@ func (self *containerdContainerHandler) ContainerReference() (info.ContainerRefe Id: self.id, Name: self.name, Namespace: k8sContainerdNamespace, - Labels: self.labels, Aliases: self.aliases, }, nil } diff --git a/container/containerd/handler_test.go b/container/containerd/handler_test.go index a700ac8c..f97abdfb 100644 --- a/container/containerd/handler_test.go +++ b/container/containerd/handler_test.go @@ -89,7 +89,6 @@ func TestHandler(t *testing.T) { Name: "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", Aliases: []string{"40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9", "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/40af7cdcbe507acad47a5a62025743ad3ddc6ab93b77b21363aa1c1d641047c9"}, Namespace: k8sContainerdNamespace, - Labels: map[string]string{"io.cri-containerd.kind": "sandbox"}, }, }, } { diff --git a/container/crio/handler.go b/container/crio/handler.go index 024341da..9403ae61 100644 --- a/container/crio/handler.go +++ b/container/crio/handler.go @@ -209,7 +209,6 @@ func (self *crioContainerHandler) ContainerReference() (info.ContainerReference, Name: self.name, Aliases: self.aliases, Namespace: CrioNamespace, - Labels: self.labels, }, nil } diff --git a/container/crio/handler_test.go b/container/crio/handler_test.go index ed39b565..a6b18fbd 100644 --- a/container/crio/handler_test.go +++ b/container/crio/handler_test.go @@ -99,7 +99,6 @@ func TestHandler(t *testing.T) { Name: "/kubepods/pod068e8fa0-9213-11e7-a01f-507b9d4141fa/crio-81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f", Aliases: []string{"test", "81e5c2990803c383229c9680ce964738d5e566d97f5bd436ac34808d2ec75d5f"}, Namespace: CrioNamespace, - Labels: map[string]string{"io.kubernetes.container.name": "POD"}, }, }, } { diff --git a/container/docker/handler.go b/container/docker/handler.go index c5c46ae4..e33a602f 100644 --- a/container/docker/handler.go +++ b/container/docker/handler.go @@ -369,7 +369,6 @@ func (self *dockerContainerHandler) ContainerReference() (info.ContainerReferenc Name: self.name, Aliases: self.aliases, Namespace: DockerNamespace, - Labels: self.labels, }, nil } diff --git a/container/rkt/handler.go b/container/rkt/handler.go index 9caa0ce4..0ffeb8af 100644 --- a/container/rkt/handler.go +++ b/container/rkt/handler.go @@ -178,7 +178,6 @@ func (handler *rktContainerHandler) ContainerReference() (info.ContainerReferenc Name: handler.name, Aliases: handler.aliases, Namespace: RktNamespace, - Labels: handler.labels, }, nil } diff --git a/info/v1/container.go b/info/v1/container.go index 8d0c28e0..734b30f6 100644 --- a/info/v1/container.go +++ b/info/v1/container.go @@ -85,8 +85,6 @@ type ContainerReference struct { // Namespace under which the aliases of a container are unique. // An example of a namespace is "docker" for Docker containers. Namespace string `json:"namespace,omitempty"` - - Labels map[string]string `json:"labels,omitempty"` } // Sorts by container name. diff --git a/manager/container.go b/manager/container.go index 8193bb5e..9ee129c3 100644 --- a/manager/container.go +++ b/manager/container.go @@ -615,7 +615,12 @@ func (c *containerData) updateStats() error { } return err } - err = c.memoryCache.AddStats(ref, stats) + + cInfo := info.ContainerInfo{ + ContainerReference: ref, + } + + err = c.memoryCache.AddStats(&cInfo, stats) if err != nil { return err } diff --git a/manager/manager_test.go b/manager/manager_test.go index 5268dd4c..9f956dfd 100644 --- a/manager/manager_test.go +++ b/manager/manager_test.go @@ -102,8 +102,12 @@ func expectManagerWithContainers(containers []string, query *info.ContainerInfoR if err != nil { t.Error(err) } + + cInfo := info.ContainerInfo{ + ContainerReference: ref, + } for _, stat := range cinfo.Stats { - err = memoryCache.AddStats(ref, stat) + err = memoryCache.AddStats(&cInfo, stat) if err != nil { t.Error(err) } @@ -148,8 +152,13 @@ func expectManagerWithContainersV2(containers []string, query *info.ContainerInf if err != nil { t.Error(err) } + + cInfo := info.ContainerInfo{ + ContainerReference: ref, + } + for _, stat := range cinfo.Stats { - err = memoryCache.AddStats(ref, stat) + err = memoryCache.AddStats(&cInfo, stat) if err != nil { t.Error(err) } diff --git a/storage/bigquery/bigquery.go b/storage/bigquery/bigquery.go index 316f8f3c..d4675737 100644 --- a/storage/bigquery/bigquery.go +++ b/storage/bigquery/bigquery.go @@ -193,7 +193,7 @@ func (self *bigqueryStorage) GetSchema() *bigquery.TableSchema { } func (self *bigqueryStorage) containerStatsToRows( - ref info.ContainerReference, + cInfo *info.ContainerInfo, stats *info.ContainerStats, ) (row map[string]interface{}) { row = make(map[string]interface{}) @@ -205,9 +205,9 @@ func (self *bigqueryStorage) containerStatsToRows( row[colMachineName] = self.machineName // Container name - name := ref.Name - if len(ref.Aliases) > 0 { - name = ref.Aliases[0] + name := cInfo.ContainerReference.Name + if len(cInfo.ContainerReference.Aliases) > 0 { + name = cInfo.ContainerReference.Aliases[0] } row[colContainerName] = name @@ -250,7 +250,7 @@ func (self *bigqueryStorage) containerStatsToRows( } func (self *bigqueryStorage) containerFilesystemStatsToRows( - ref info.ContainerReference, + cInfo *info.ContainerInfo, stats *info.ContainerStats, ) (rows []map[string]interface{}) { for _, fsStat := range stats.Filesystem { @@ -263,13 +263,13 @@ func (self *bigqueryStorage) containerFilesystemStatsToRows( return rows } -func (self *bigqueryStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { +func (self *bigqueryStorage) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { if stats == nil { return nil } rows := make([]map[string]interface{}, 0) - rows = append(rows, self.containerStatsToRows(ref, stats)) - rows = append(rows, self.containerFilesystemStatsToRows(ref, stats)...) + rows = append(rows, self.containerStatsToRows(cInfo, stats)) + rows = append(rows, self.containerFilesystemStatsToRows(cInfo, stats)...) for _, row := range rows { err := self.client.InsertRow(row) if err != nil { diff --git a/storage/elasticsearch/elasticsearch.go b/storage/elasticsearch/elasticsearch.go index b43beed2..20014946 100644 --- a/storage/elasticsearch/elasticsearch.go +++ b/storage/elasticsearch/elasticsearch.go @@ -68,13 +68,13 @@ func new() (storage.StorageDriver, error) { } func (self *elasticStorage) containerStatsAndDefaultValues( - ref info.ContainerReference, stats *info.ContainerStats) *detailSpec { + cInfo *info.ContainerInfo, stats *info.ContainerStats) *detailSpec { timestamp := stats.Timestamp.UnixNano() / 1E3 var containerName string - if len(ref.Aliases) > 0 { - containerName = ref.Aliases[0] + if len(cInfo.ContainerReference.Aliases) > 0 { + containerName = cInfo.ContainerReference.Aliases[0] } else { - containerName = ref.Name + containerName = cInfo.ContainerReference.Name } detail := &detailSpec{ Timestamp: timestamp, @@ -85,7 +85,7 @@ func (self *elasticStorage) containerStatsAndDefaultValues( return detail } -func (self *elasticStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { +func (self *elasticStorage) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { if stats == nil { return nil } @@ -94,7 +94,7 @@ func (self *elasticStorage) AddStats(ref info.ContainerReference, stats *info.Co self.lock.Lock() defer self.lock.Unlock() // Add some default params based on ContainerStats - detail := self.containerStatsAndDefaultValues(ref, stats) + detail := self.containerStatsAndDefaultValues(cInfo, stats) // Index a cadvisor (using JSON serialization) _, err := self.client.Index(). Index(self.indexName). diff --git a/storage/influxdb/influxdb.go b/storage/influxdb/influxdb.go index f1fcf0dd..9f019c84 100644 --- a/storage/influxdb/influxdb.go +++ b/storage/influxdb/influxdb.go @@ -108,7 +108,7 @@ const ( ) func (self *influxdbStorage) containerFilesystemStatsToPoints( - ref info.ContainerReference, + cInfo *info.ContainerInfo, stats *info.ContainerStats) (points []*influxdb.Point) { if len(stats.Filesystem) == 0 { return points @@ -143,20 +143,20 @@ func (self *influxdbStorage) containerFilesystemStatsToPoints( points = append(points, pointFsUsage, pointFsLimit) } - self.tagPoints(ref, stats, points) + self.tagPoints(cInfo, stats, points) return points } // Set tags and timestamp for all points of the batch. // Points should inherit the tags that are set for BatchPoints, but that does not seem to work. -func (self *influxdbStorage) tagPoints(ref info.ContainerReference, stats *info.ContainerStats, points []*influxdb.Point) { +func (self *influxdbStorage) tagPoints(cInfo *info.ContainerInfo, stats *info.ContainerStats, points []*influxdb.Point) { // Use container alias if possible var containerName string - if len(ref.Aliases) > 0 { - containerName = ref.Aliases[0] + if len(cInfo.ContainerReference.Aliases) > 0 { + containerName = cInfo.ContainerReference.Aliases[0] } else { - containerName = ref.Name + containerName = cInfo.ContainerReference.Name } commonTags := map[string]string{ @@ -166,13 +166,13 @@ func (self *influxdbStorage) tagPoints(ref info.ContainerReference, stats *info. for i := 0; i < len(points); i++ { // merge with existing tags if any addTagsToPoint(points[i], commonTags) - addTagsToPoint(points[i], ref.Labels) + addTagsToPoint(points[i], cInfo.Spec.Labels) points[i].Time = stats.Timestamp } } func (self *influxdbStorage) containerStatsToPoints( - ref info.ContainerReference, + cInfo *info.ContainerInfo, stats *info.ContainerStats, ) (points []*influxdb.Point) { // CPU usage: Total usage in nanoseconds @@ -208,7 +208,7 @@ func (self *influxdbStorage) containerStatsToPoints( points = append(points, makePoint(serTxBytes, stats.Network.TxBytes)) points = append(points, makePoint(serTxErrors, stats.Network.TxErrors)) - self.tagPoints(ref, stats, points) + self.tagPoints(cInfo, stats, points) return points } @@ -221,7 +221,7 @@ func (self *influxdbStorage) defaultReadyToFlush() bool { return time.Since(self.lastWrite) >= self.bufferDuration } -func (self *influxdbStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { +func (self *influxdbStorage) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { if stats == nil { return nil } @@ -231,8 +231,8 @@ func (self *influxdbStorage) AddStats(ref info.ContainerReference, stats *info.C self.lock.Lock() defer self.lock.Unlock() - self.points = append(self.points, self.containerStatsToPoints(ref, stats)...) - self.points = append(self.points, self.containerFilesystemStatsToPoints(ref, stats)...) + self.points = append(self.points, self.containerStatsToPoints(cInfo, stats)...) + self.points = append(self.points, self.containerFilesystemStatsToPoints(cInfo, stats)...) if self.readyToFlush() { pointsToFlush = self.points self.points = make([]*influxdb.Point, 0) diff --git a/storage/influxdb/influxdb_test.go b/storage/influxdb/influxdb_test.go index bf00e3a4..8704d083 100644 --- a/storage/influxdb/influxdb_test.go +++ b/storage/influxdb/influxdb_test.go @@ -47,9 +47,9 @@ func (self *influxDbTestStorageDriver) readyToFlush() bool { return self.count >= self.buffer } -func (self *influxDbTestStorageDriver) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { +func (self *influxDbTestStorageDriver) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { self.count++ - return self.base.AddStats(ref, stats) + return self.base.AddStats(cInfo, stats) } func (self *influxDbTestStorageDriver) Close() error { diff --git a/storage/kafka/kafka.go b/storage/kafka/kafka.go index 16de668a..cd7f88cb 100644 --- a/storage/kafka/kafka.go +++ b/storage/kafka/kafka.go @@ -60,11 +60,11 @@ type detailSpec struct { ContainerStats *info.ContainerStats `json:"container_stats,omitempty"` } -func (driver *kafkaStorage) infoToDetailSpec(ref info.ContainerReference, stats *info.ContainerStats) *detailSpec { +func (driver *kafkaStorage) infoToDetailSpec(cInfo *info.ContainerInfo, stats *info.ContainerStats) *detailSpec { timestamp := time.Now() - containerID := ref.Id - containerLabels := ref.Labels - containerName := container.GetPreferredName(ref) + containerID := cInfo.ContainerReference.Id + containerLabels := cInfo.Spec.Labels + containerName := container.GetPreferredName(cInfo.ContainerReference) detail := &detailSpec{ Timestamp: timestamp, @@ -77,8 +77,8 @@ func (driver *kafkaStorage) infoToDetailSpec(ref info.ContainerReference, stats return detail } -func (driver *kafkaStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { - detail := driver.infoToDetailSpec(ref, stats) +func (driver *kafkaStorage) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { + detail := driver.infoToDetailSpec(cInfo, stats) b, err := json.Marshal(detail) driver.producer.Input() <- &kafka.ProducerMessage{ diff --git a/storage/redis/redis.go b/storage/redis/redis.go index c7463452..4a8fc5df 100644 --- a/storage/redis/redis.go +++ b/storage/redis/redis.go @@ -65,13 +65,13 @@ func (self *redisStorage) defaultReadyToFlush() bool { } // We must add some default params (for example: MachineName,ContainerName...)because containerStats do not include them -func (self *redisStorage) containerStatsAndDefaultValues(ref info.ContainerReference, stats *info.ContainerStats) *detailSpec { +func (self *redisStorage) containerStatsAndDefaultValues(cInfo *info.ContainerInfo, stats *info.ContainerStats) *detailSpec { timestamp := stats.Timestamp.UnixNano() / 1E3 var containerName string - if len(ref.Aliases) > 0 { - containerName = ref.Aliases[0] + if len(cInfo.ContainerReference.Aliases) > 0 { + containerName = cInfo.ContainerReference.Aliases[0] } else { - containerName = ref.Name + containerName = cInfo.ContainerReference.Name } detail := &detailSpec{ Timestamp: timestamp, @@ -83,7 +83,7 @@ func (self *redisStorage) containerStatsAndDefaultValues(ref info.ContainerRefer } // Push the data into redis -func (self *redisStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { +func (self *redisStorage) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { if stats == nil { return nil } @@ -93,7 +93,7 @@ func (self *redisStorage) AddStats(ref info.ContainerReference, stats *info.Cont self.lock.Lock() defer self.lock.Unlock() // Add some default params based on containerStats - detail := self.containerStatsAndDefaultValues(ref, stats) + detail := self.containerStatsAndDefaultValues(cInfo, stats) // To json b, _ := json.Marshal(detail) if self.readyToFlush() { diff --git a/storage/statsd/statsd.go b/storage/statsd/statsd.go index 9481c70d..03f4d015 100644 --- a/storage/statsd/statsd.go +++ b/storage/statsd/statsd.go @@ -105,16 +105,16 @@ func (self *statsdStorage) containerFsStatsToValues( } // Push the data into redis -func (self *statsdStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { +func (self *statsdStorage) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { if stats == nil { return nil } var containerName string - if len(ref.Aliases) > 0 { - containerName = ref.Aliases[0] + if len(cInfo.ContainerReference.Aliases) > 0 { + containerName = cInfo.ContainerReference.Aliases[0] } else { - containerName = ref.Name + containerName = cInfo.ContainerReference.Name } series := self.containerStatsToValues(stats) diff --git a/storage/stdout/stdout.go b/storage/stdout/stdout.go index aa8aafe9..5749454c 100644 --- a/storage/stdout/stdout.go +++ b/storage/stdout/stdout.go @@ -89,14 +89,14 @@ func (driver *stdoutStorage) containerFsStatsToValues(series *map[string]uint64, } } -func (driver *stdoutStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { +func (driver *stdoutStorage) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { if stats == nil { return nil } - containerName := ref.Name - if len(ref.Aliases) > 0 { - containerName = ref.Aliases[0] + containerName := cInfo.ContainerReference.Name + if len(cInfo.ContainerReference.Aliases) > 0 { + containerName = cInfo.ContainerReference.Aliases[0] } var buffer bytes.Buffer diff --git a/storage/storage.go b/storage/storage.go index b420d4b1..dd950862 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -22,7 +22,7 @@ import ( ) type StorageDriver interface { - AddStats(ref info.ContainerReference, stats *info.ContainerStats) error + AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error // Close will clear the state of the storage driver. The elements // stored in the underlying storage may or may not be deleted depending diff --git a/storage/test/mock.go b/storage/test/mock.go index 78e77867..d83d1d44 100644 --- a/storage/test/mock.go +++ b/storage/test/mock.go @@ -25,8 +25,8 @@ type MockStorageDriver struct { MockCloseMethod bool } -func (self *MockStorageDriver) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error { - args := self.Called(ref, stats) +func (self *MockStorageDriver) AddStats(cInfo *info.ContainerInfo, stats *info.ContainerStats) error { + args := self.Called(cInfo.ContainerReference, stats) return args.Error(0) } diff --git a/storage/test/storagetests.go b/storage/test/storagetests.go index f9162833..5f6a7c00 100644 --- a/storage/test/storagetests.go +++ b/storage/test/storagetests.go @@ -123,14 +123,16 @@ func StorageDriverFillRandomStatsFunc( samplePeriod := 1 * time.Second - ref := info.ContainerReference{ - Name: containerName, + cInfo := info.ContainerInfo{ + ContainerReference: info.ContainerReference{ + Name: containerName, + }, } trace := buildTrace(cpuTrace, memTrace, samplePeriod) for _, stats := range trace { - err := driver.AddStats(ref, stats) + err := driver.AddStats(&cInfo, stats) if err != nil { t.Fatalf("unable to add stats: %v", err) }