@@ -134,7 +134,7 @@ func (cs *ContainerStats) Listen() *io.PipeWriter {
134
134
doc := json .NewEncoder (cs .config .Out )
135
135
136
136
// channel to transfer metric from decoder to encoder
137
- metric := make (chan performance. VMMetrics )
137
+ metric := make (chan * types. StatsJSON )
138
138
139
139
// if we aren't streaming and the container is not running, then create an empty
140
140
// docker stat to return
@@ -145,7 +145,6 @@ func (cs *ContainerStats) Listen() *io.PipeWriter {
145
145
// go routine to stop on Context.Cancel
146
146
go func () {
147
147
<- cs .config .Ctx .Done ()
148
- close (metric )
149
148
cs .Stop ()
150
149
}()
151
150
@@ -155,6 +154,7 @@ func (cs *ContainerStats) Listen() *io.PipeWriter {
155
154
for {
156
155
select {
157
156
case <- cs .config .Ctx .Done ():
157
+ close (metric )
158
158
return
159
159
default :
160
160
for dec .More () {
@@ -163,10 +163,20 @@ func (cs *ContainerStats) Listen() *io.PipeWriter {
163
163
if err != nil {
164
164
log .Errorf ("container metric decoding error for container(%s): %s" , cs .config .ContainerID , err )
165
165
cs .config .Cancel ()
166
+ close (metric )
167
+ return
168
+ }
169
+ // convert the Stat to docker struct
170
+ stat , err := cs .ToContainerStats (& vmm )
171
+ if err != nil {
172
+ log .Errorf ("container metric conversion error for container(%s): %s" , cs .config .ContainerID , err )
173
+ cs .config .Cancel ()
174
+ close (metric )
175
+ return
166
176
}
167
177
// send the decoded metric for transform and encoding
168
178
if cs .IsListening () {
169
- metric <- vmm
179
+ metric <- stat
170
180
}
171
181
}
172
182
}
@@ -183,13 +193,7 @@ func (cs *ContainerStats) Listen() *io.PipeWriter {
183
193
case <- cs .config .Ctx .Done ():
184
194
ticker .Stop ()
185
195
return
186
- case nm := <- metric :
187
- // convert the Stat to docker struct
188
- stat , err := cs .ToContainerStats (& nm )
189
- if err != nil {
190
- log .Errorf ("container metric conversion error for container(%s): %s" , cs .config .ContainerID , err )
191
- cs .config .Cancel ()
192
- }
196
+ case stat := <- metric :
193
197
if stat != nil {
194
198
cs .preDockerStat = stat
195
199
}
0 commit comments