grafana/pkg/services/live/pipeline/converter_influx_auto.go
Alexander Emelin 0bf70b14fd
Live: api to show available pipeline entities (#39469)
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2021-09-21 11:57:58 -07:00

45 lines
1.2 KiB
Go

package pipeline
import (
"context"
"github.com/grafana/grafana/pkg/services/live/convert"
)
type AutoInfluxConverterConfig struct {
FrameFormat string `json:"frameFormat"`
}
// AutoInfluxConverter decodes Influx line protocol input and transforms it
// to several ChannelFrame objects where Channel is constructed from original
// channel + / + <metric_name>.
type AutoInfluxConverter struct {
config AutoInfluxConverterConfig
converter *convert.Converter
}
func NewAutoInfluxConverter(config AutoInfluxConverterConfig) *AutoInfluxConverter {
return &AutoInfluxConverter{config: config, converter: convert.NewConverter()}
}
const ConverterTypeInfluxAuto = "influxAuto"
func (c *AutoInfluxConverter) Type() string {
return ConverterTypeInfluxAuto
}
func (c *AutoInfluxConverter) Convert(_ context.Context, vars Vars, body []byte) ([]*ChannelFrame, error) {
frameWrappers, err := c.converter.Convert(body, c.config.FrameFormat)
if err != nil {
return nil, err
}
channelFrames := make([]*ChannelFrame, 0, len(frameWrappers))
for _, fw := range frameWrappers {
channelFrames = append(channelFrames, &ChannelFrame{
Channel: vars.Channel + "/" + fw.Key(),
Frame: fw.Frame(),
})
}
return channelFrames, nil
}