mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
38 lines
852 B
Go
38 lines
852 B
Go
|
package pipeline
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// LokiDataOutput can output raw data to Loki (as string value).
|
||
|
type LokiDataOutput struct {
|
||
|
lokiWriter *lokiWriter
|
||
|
}
|
||
|
|
||
|
func NewLokiDataOutput(endpoint, user, password string) *LokiDataOutput {
|
||
|
return &LokiDataOutput{
|
||
|
lokiWriter: newLokiWriter(endpoint, user, password),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|