Skip to content

Commit b51697f

Browse files
committed
pulling the hot path out of function to avoid a copy
1 parent 2fdc8c2 commit b51697f

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

pkg/formats/otel/otel.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,15 @@ func (f *OtelFormat) To(msgs []*kt.JCHF, serBuf []byte) (*kt.Output, error) {
185185
cv, err := otelm.Float64ObservableGauge(
186186
lm.Name,
187187
metric.WithFloat64Callback(func(_ context.Context, o metric.Float64Observer) error {
188-
for _, mm := range f.getLatestInputs(lm.Name) {
189-
o.Observe(mm.Value, metric.WithAttributeSet(mm.GetTagValues()))
188+
f.Debugf("Exporting data from otel for %s", lm.Name)
189+
for {
190+
select {
191+
case mm := <-f.inputs[lm.Name]:
192+
o.Observe(mm.Value, metric.WithAttributeSet(mm.GetTagValues()))
193+
default:
194+
return nil
195+
}
190196
}
191-
return nil
192197
}),
193198
)
194199
if err != nil {
@@ -229,10 +234,15 @@ func (f *OtelFormat) Rollup(rolls []rollup.Rollup) (*kt.Output, error) {
229234
cv, err := otelm.Float64ObservableGauge(
230235
lm.Name,
231236
metric.WithFloat64Callback(func(_ context.Context, o metric.Float64Observer) error {
232-
for _, mm := range f.getLatestInputs(lm.Name) {
233-
o.Observe(mm.Value, metric.WithAttributeSet(mm.GetTagValues()))
237+
f.Debugf("Exporting data from otel for %s", lm.Name)
238+
for {
239+
select {
240+
case mm := <-f.inputs[lm.Name]:
241+
o.Observe(mm.Value, metric.WithAttributeSet(mm.GetTagValues()))
242+
default:
243+
return nil
244+
}
234245
}
235-
return nil
236246
}),
237247
)
238248
if err != nil {
@@ -296,19 +306,6 @@ func (f *OtelFormat) toOtelDataRollup(in []rollup.Rollup) []OtelData {
296306
return ms
297307
}
298308

299-
func (f *OtelFormat) getLatestInputs(name string) []OtelData {
300-
f.Debugf("Exporting data from otel for %s", name)
301-
nv := make([]OtelData, 0, len(f.inputs[name]))
302-
for {
303-
select {
304-
case v := <-f.inputs[name]:
305-
nv = append(nv, v)
306-
default:
307-
return nv
308-
}
309-
}
310-
}
311-
312309
func (f *OtelFormat) toOtelMetric(in *kt.JCHF) []OtelData {
313310
switch in.EventType {
314311
case kt.KENTIK_EVENT_TYPE:

0 commit comments

Comments
 (0)