Live: search for pipeline files in data folder (#39198)

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Alexander Emelin
2021-09-14 23:27:51 +03:00
committed by GitHub
parent 548b4daa49
commit 15e278e9e1
4 changed files with 36 additions and 13 deletions

View File

@@ -3,19 +3,25 @@ package pipeline
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
// FileStorage can load channel rules from a file on disk.
type FileStorage struct{}
type FileStorage struct {
DataPath string
}
func (f *FileStorage) ListRemoteWriteBackends(_ context.Context, orgID int64) ([]RemoteWriteBackend, error) {
backendBytes, _ := ioutil.ReadFile(os.Getenv("GF_LIVE_REMOTE_WRITE_BACKENDS_FILE"))
var remoteWriteBackends RemoteWriteBackends
err := json.Unmarshal(backendBytes, &remoteWriteBackends)
backendBytes, err := ioutil.ReadFile(filepath.Join(f.DataPath, "pipeline", "remote-write-backends.json"))
if err != nil {
return nil, err
return nil, fmt.Errorf("can't read ./pipeline/remote-write-backends.json file: %w", err)
}
var remoteWriteBackends RemoteWriteBackends
err = json.Unmarshal(backendBytes, &remoteWriteBackends)
if err != nil {
return nil, fmt.Errorf("can't unmarshal remote-write-backends.json data: %w", err)
}
var backends []RemoteWriteBackend
for _, b := range remoteWriteBackends.Backends {
@@ -27,11 +33,14 @@ func (f *FileStorage) ListRemoteWriteBackends(_ context.Context, orgID int64) ([
}
func (f *FileStorage) ListChannelRules(_ context.Context, orgID int64) ([]ChannelRule, error) {
ruleBytes, _ := ioutil.ReadFile(os.Getenv("GF_LIVE_CHANNEL_RULES_FILE"))
var channelRules ChannelRules
err := json.Unmarshal(ruleBytes, &channelRules)
ruleBytes, err := ioutil.ReadFile(filepath.Join(f.DataPath, "pipeline", "live-channel-rules.json"))
if err != nil {
return nil, err
return nil, fmt.Errorf("can't read ./data/live-channel-rules.json file: %w", err)
}
var channelRules ChannelRules
err = json.Unmarshal(ruleBytes, &channelRules)
if err != nil {
return nil, fmt.Errorf("can't unmarshal live-channel-rules.json data: %w", err)
}
var rules []ChannelRule
for _, r := range channelRules.Rules {