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 22:27:51 +02:00
committed by GitHub
co-authored by Ryan McKinley
parent 548b4daa49
commit 15e278e9e1
4 changed files with 36 additions and 13 deletions
+3 -1
View File
@@ -173,7 +173,9 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r
FrameStorage: pipeline.NewFrameStorage(), FrameStorage: pipeline.NewFrameStorage(),
} }
} else { } else {
storage := &pipeline.FileStorage{} storage := &pipeline.FileStorage{
DataPath: cfg.DataPath,
}
g.channelRuleStorage = storage g.channelRuleStorage = storage
builder = &pipeline.StorageRuleBuilder{ builder = &pipeline.StorageRuleBuilder{
Node: node, Node: node,
+19 -10
View File
@@ -3,19 +3,25 @@ package pipeline
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"os" "path/filepath"
) )
// FileStorage can load channel rules from a file on disk. // 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) { func (f *FileStorage) ListRemoteWriteBackends(_ context.Context, orgID int64) ([]RemoteWriteBackend, error) {
backendBytes, _ := ioutil.ReadFile(os.Getenv("GF_LIVE_REMOTE_WRITE_BACKENDS_FILE")) backendBytes, err := ioutil.ReadFile(filepath.Join(f.DataPath, "pipeline", "remote-write-backends.json"))
var remoteWriteBackends RemoteWriteBackends
err := json.Unmarshal(backendBytes, &remoteWriteBackends)
if err != nil { 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 var backends []RemoteWriteBackend
for _, b := range remoteWriteBackends.Backends { 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) { func (f *FileStorage) ListChannelRules(_ context.Context, orgID int64) ([]ChannelRule, error) {
ruleBytes, _ := ioutil.ReadFile(os.Getenv("GF_LIVE_CHANNEL_RULES_FILE")) ruleBytes, err := ioutil.ReadFile(filepath.Join(f.DataPath, "pipeline", "live-channel-rules.json"))
var channelRules ChannelRules
err := json.Unmarshal(ruleBytes, &channelRules)
if err != nil { 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 var rules []ChannelRule
for _, r := range channelRules.Rules { for _, r := range channelRules.Rules {
@@ -10,6 +10,7 @@ import { GrafanaCloudBackend } from './types';
export default function CloudAdminPage() { export default function CloudAdminPage() {
const navModel = useNavModel('live-cloud'); const navModel = useNavModel('live-cloud');
const [cloud, setCloud] = useState<GrafanaCloudBackend[]>([]); const [cloud, setCloud] = useState<GrafanaCloudBackend[]>([]);
const [error, setError] = useState<string>();
const styles = useStyles(getStyles); const styles = useStyles(getStyles);
useEffect(() => { useEffect(() => {
@@ -18,12 +19,17 @@ export default function CloudAdminPage() {
.then((data) => { .then((data) => {
setCloud(data.remoteWriteBackends); setCloud(data.remoteWriteBackends);
}) })
.catch((e) => console.error(e)); .catch((e) => {
if (e.data) {
setError(JSON.stringify(e.data, null, 2));
}
});
}, []); }, []);
return ( return (
<Page navModel={navModel}> <Page navModel={navModel}>
<Page.Contents> <Page.Contents>
{error && <pre>{error}</pre>}
{!cloud && <>Loading cloud definitions</>} {!cloud && <>Loading cloud definitions</>}
{cloud && {cloud &&
cloud.map((v) => { cloud.map((v) => {
@@ -24,6 +24,7 @@ export default function PipelineAdminPage() {
const [selectedRule, setSelectedRule] = useState<Rule>(); const [selectedRule, setSelectedRule] = useState<Rule>();
const [defaultRules, setDefaultRules] = useState<any[]>([]); const [defaultRules, setDefaultRules] = useState<any[]>([]);
const navModel = useNavModel('live-pipeline'); const navModel = useNavModel('live-pipeline');
const [error, setError] = useState<string>();
const styles = useStyles(getStyles); const styles = useStyles(getStyles);
useEffect(() => { useEffect(() => {
@@ -33,7 +34,11 @@ export default function PipelineAdminPage() {
setRules(data.rules); setRules(data.rules);
setDefaultRules(data.rules); setDefaultRules(data.rules);
}) })
.catch((e) => console.error(e)); .catch((e) => {
if (e.data) {
setError(JSON.stringify(e.data, null, 2));
}
});
}, []); }, []);
const onRowClick = (event: any) => { const onRowClick = (event: any) => {
@@ -57,6 +62,7 @@ export default function PipelineAdminPage() {
return ( return (
<Page navModel={navModel}> <Page navModel={navModel}>
<Page.Contents> <Page.Contents>
{error && <pre>{error}</pre>}
<div className="page-action-bar"> <div className="page-action-bar">
<div className="gf-form gf-form--grow"> <div className="gf-form gf-form--grow">
<Input placeholder="Search pattern..." onChange={onSearchQueryChange} /> <Input placeholder="Search pattern..." onChange={onSearchQueryChange} />