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
|
Update(context.Context, Layout) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SourceAndKapacitor is used to parse any NewSources server flag arguments
|
||||||
|
type SourceAndKapacitor struct {
|
||||||
|
Source Source `json:"influxdb"`
|
||||||
|
Kapacitor Server `json:"kapacitor"`
|
||||||
|
}
|
||||||
|
|
||||||
// NewSources adds sources to BoltDb idempotently by name, as well as respective kapacitors
|
// 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 {
|
func NewSources(ctx context.Context, sourcesStore SourcesStore, serversStore ServersStore, srcsKaps []SourceAndKapacitor, logger Logger) error {
|
||||||
if newSources == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
srcs, err := sourcesStore.All(ctx)
|
srcs, err := sourcesStore.All(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -3,6 +3,7 @@ package server
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
@ -300,14 +301,29 @@ func (s *Server) Serve(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
service := openService(ctx, s.BoltPath, layoutBuilder, sourcesBuilder, kapacitorBuilder, logger, s.useAuth())
|
service := openService(ctx, s.BoltPath, layoutBuilder, sourcesBuilder, kapacitorBuilder, logger, s.useAuth())
|
||||||
|
|
||||||
// Add any new sources and kapacitors as specified via server flag
|
go func() {
|
||||||
if err = chronograf.NewSources(ctx, service.SourcesStore, service.ServersStore, s.NewSources, logger); err != nil {
|
if s.NewSources == "" {
|
||||||
// Continue with server run even if adding NewSources fails
|
return
|
||||||
logger.
|
}
|
||||||
WithField("component", "server").
|
|
||||||
WithField("NewSources", "invalid").
|
var srcsKaps []chronograf.SourceAndKapacitor
|
||||||
Error(err)
|
// 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, 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
|
basepath = s.Basepath
|
||||||
if basepath != "" && s.PrefixRoutes == false {
|
if basepath != "" && s.PrefixRoutes == false {
|
||||||
|
|
Loading…
Reference in New Issue