Skip to content

Commit

Permalink
Improve channel handling in remote_write handler (#17031)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrsMark authored Mar 19, 2020
1 parent eff7e41 commit 4f5d1a1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions metricbeat/module/prometheus/remote_write/remote_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
if err != nil {
return nil, err
}

m := &MetricSet{
BaseMetricSet: base,
events: make(chan mb.Event),
Expand All @@ -71,7 +70,6 @@ func (m *MetricSet) Run(reporter mb.PushReporterV2) {
select {
case <-reporter.Done():
m.server.Stop()
close(m.events)
return
case e := <-m.events:
reporter.Event(e)
Expand Down Expand Up @@ -100,12 +98,16 @@ func (m *MetricSet) handleFunc(writer http.ResponseWriter, req *http.Request) {
http.Error(writer, err.Error(), http.StatusBadRequest)
return
}
// refactor, optimize

samples := protoToSamples(&protoReq)
events := samplesToEvents(samples)

for _, e := range events {
m.events <- e
select {
case <-req.Context().Done():
return
case m.events <- e:
}
}
writer.WriteHeader(http.StatusAccepted)
}
Expand Down

0 comments on commit 4f5d1a1

Please sign in to comment.