Move NewSources input prep to server
Signed-off-by: Tim Raymond <tim@timraymond.com>pull/1695/head
parent
b30fd6e260
commit
1c72fd338b
|
@ -626,22 +626,14 @@ type LayoutStore interface {
|
|||
Update(context.Context, Layout) error
|
||||
}
|
||||
|
||||
// NewSources adds sources to BoltDb idempotently by name, as well as respective kapacitors
|
||||
func NewSources(ctx context.Context, sourcesStore SourcesStore, serversStore ServersStore, newSources string, logger Logger) error {
|
||||
if newSources == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
type SourceAndKapacitor struct {
|
||||
// SourceAndKapacitor is used to parse any NewSources server flag arguments
|
||||
type SourceAndKapacitor struct {
|
||||
Source Source `json:"influxdb"`
|
||||
Kapacitor Server `json:"kapacitor"`
|
||||
}
|
||||
var srcsKaps []SourceAndKapacitor
|
||||
// On JSON unmarshal error, continue server process without new source and write error to log
|
||||
if err := json.Unmarshal([]byte(newSources), &srcsKaps); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// NewSources adds sources to BoltDb idempotently by name, as well as respective kapacitors
|
||||
func NewSources(ctx context.Context, sourcesStore SourcesStore, serversStore ServersStore, srcsKaps []SourceAndKapacitor, logger Logger) error {
|
||||
srcs, err := sourcesStore.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
|
@ -300,14 +301,29 @@ func (s *Server) Serve(ctx context.Context) error {
|
|||
}
|
||||
service := openService(ctx, s.BoltPath, layoutBuilder, sourcesBuilder, kapacitorBuilder, logger, s.useAuth())
|
||||
|
||||
go func() {
|
||||
if s.NewSources == "" {
|
||||
return
|
||||
}
|
||||
|
||||
var srcsKaps []chronograf.SourceAndKapacitor
|
||||
// On JSON unmarshal error, continue server process without new source and write error to log
|
||||
if err := json.Unmarshal([]byte(s.NewSources), &srcsKaps); err != nil {
|
||||
logger.
|
||||
WithField("component", "server").
|
||||
WithField("NewSources", "invalid").
|
||||
Error(err)
|
||||
}
|
||||
|
||||
// Add any new sources and kapacitors as specified via server flag
|
||||
if err = chronograf.NewSources(ctx, service.SourcesStore, service.ServersStore, s.NewSources, logger); err != nil {
|
||||
if err = chronograf.NewSources(ctx, service.SourcesStore, service.ServersStore, srcsKaps, logger); err != nil {
|
||||
// Continue with server run even if adding NewSources fails
|
||||
logger.
|
||||
WithField("component", "server").
|
||||
WithField("NewSources", "invalid").
|
||||
Error(err)
|
||||
}
|
||||
}()
|
||||
|
||||
basepath = s.Basepath
|
||||
if basepath != "" && s.PrefixRoutes == false {
|
||||
|
|
Loading…
Reference in New Issue