grafana/pkg/services/live/pipeline/data_output_loki.go

38 lines
853 B
Go
Raw Normal View History

2021-11-09 04:10:43 -06:00
package pipeline
import (
"context"
"time"
)
// LokiDataOutput can output raw data to Loki (as string value).
type LokiDataOutput struct {
lokiWriter *lokiWriter
}
func NewLokiDataOutput(endpoint string, basicAuth *BasicAuth) *LokiDataOutput {
2021-11-09 04:10:43 -06:00
return &LokiDataOutput{
lokiWriter: newLokiWriter(endpoint, basicAuth),
2021-11-09 04:10:43 -06:00
}
}
const DataOutputTypeLoki = "loki"
func (out *LokiDataOutput) Type() string {
return DataOutputTypeLoki
}
func (out *LokiDataOutput) OutputData(_ context.Context, vars Vars, data []byte) ([]*ChannelData, error) {
if out.lokiWriter.endpoint == "" {
logger.Debug("Skip sending to Loki: no url")
return nil, nil
}
err := out.lokiWriter.write(LokiStream{
Stream: map[string]string{"channel": vars.Channel},
Values: []interface{}{
[]interface{}{time.Now().UnixNano(), string(data)},
},
})
return nil, err
}