Update sources endpoint to take optional telegraf database name.

pull/587/head
Chris Goller 2016-11-18 13:13:32 -06:00
parent c6f772c69b
commit 923a9d3c31
8 changed files with 119 additions and 35 deletions

View File

@ -51,6 +51,7 @@ func MarshalSource(s chronograf.Source) ([]byte, error) {
Password: s.Password,
URL: s.URL,
Default: s.Default,
Telegraf: s.Telegraf,
})
}
@ -68,6 +69,7 @@ func UnmarshalSource(data []byte, s *chronograf.Source) error {
s.Password = pb.Password
s.URL = pb.URL
s.Default = pb.Default
s.Telegraf = pb.Telegraf
return nil
}

View File

@ -57,6 +57,7 @@ type Source struct {
Password string `protobuf:"bytes,5,opt,name=Password,json=password,proto3" json:"Password,omitempty"`
URL string `protobuf:"bytes,6,opt,name=URL,json=uRL,proto3" json:"URL,omitempty"`
Default bool `protobuf:"varint,7,opt,name=Default,json=default,proto3" json:"Default,omitempty"`
Telegraf string `protobuf:"bytes,8,opt,name=Telegraf,json=telegraf,proto3" json:"Telegraf,omitempty"`
}
func (m *Source) Reset() { *m = Source{} }
@ -157,39 +158,40 @@ func init() {
func init() { proto.RegisterFile("internal.proto", fileDescriptorInternal) }
var fileDescriptorInternal = []byte{
// 529 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x93, 0x4d, 0xae, 0xd3, 0x30,
0x10, 0x80, 0xe5, 0x26, 0xce, 0x8f, 0x8b, 0x0a, 0xb2, 0x10, 0x8a, 0x10, 0x8b, 0x2a, 0x62, 0x51,
0x36, 0x6f, 0x01, 0x27, 0x68, 0x1b, 0x84, 0x0a, 0xa5, 0xaf, 0xb8, 0x54, 0xac, 0x58, 0x98, 0xc4,
0xd0, 0x40, 0xfe, 0x70, 0x6c, 0xda, 0x6c, 0xd9, 0xc2, 0x31, 0xb8, 0x01, 0x17, 0x44, 0xe3, 0x3a,
0xa4, 0x12, 0xe8, 0xe9, 0x2d, 0xbf, 0x99, 0x49, 0xfc, 0xcd, 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xd6, 0xcd,
0xa2, 0x3b, 0x77, 0x1e, 0xb2, 0xe0, 0x93, 0x65, 0x78, 0x29, 0xef, 0x0e, 0x42, 0x5a, 0xd5, 0x90,
0x79, 0x47, 0x43, 0xf1, 0x7b, 0x12, 0xce, 0x0b, 0x21, 0x15, 0xd3, 0x85, 0xf8, 0x67, 0x17, 0x94,
0xb8, 0x2f, 0x77, 0xd7, 0x9b, 0xfe, 0x6a, 0x7c, 0xde, 0x5d, 0x6f, 0x86, 0x85, 0x3a, 0x17, 0x0b,
0x85, 0xdf, 0xbf, 0xe2, 0x0d, 0x5f, 0x25, 0x66, 0x3a, 0x0e, 0xf3, 0xbe, 0x18, 0xfa, 0xe0, 0x99,
0x57, 0xfe, 0xec, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x02, 0xe9, 0x30, 0xf7, 0x03, 0x00,
0x00,
// 547 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x94, 0xcd, 0x8e, 0xd3, 0x3e,
0x10, 0xc0, 0xe5, 0x26, 0xce, 0x87, 0xfb, 0xd7, 0xfe, 0x91, 0x85, 0x50, 0x84, 0x38, 0x54, 0x11,
0x87, 0x72, 0xd9, 0x03, 0x3c, 0x41, 0xdb, 0x20, 0x54, 0x28, 0xdd, 0xe2, 0x6e, 0xc5, 0x89, 0x83,
0x49, 0x66, 0xb7, 0x81, 0x7c, 0xe1, 0xd8, 0xb4, 0xb9, 0x72, 0x85, 0xb7, 0xe1, 0x05, 0x78, 0x34,
0x64, 0xc7, 0x25, 0x95, 0xf8, 0xd0, 0x1e, 0x7f, 0x33, 0x13, 0xfb, 0x37, 0x33, 0x6e, 0xc9, 0x45,
0x5e, 0x49, 0x10, 0x15, 0x2f, 0x2e, 0x1b, 0x51, 0xcb, 0x9a, 0x06, 0x27, 0x8e, 0xbf, 0x23, 0x32,
0x7e, 0x7e, 0x6c, 0x8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xce, 0x43, 0x16, 0xdc, 0x5a, 0xd6, 0xbf, 0xa2, 0xb7, 0x7b, 0x10, 0x56,
0x35, 0x64, 0xde, 0xc1, 0x50, 0xfc, 0x8e, 0x84, 0xb3, 0x02, 0x84, 0x64, 0xaa, 0x80, 0xdf, 0x76,
0x41, 0x89, 0xfb, 0x72, 0x7b, 0xb5, 0x3e, 0x3d, 0x8d, 0x0f, 0xdb, 0xab, 0xf5, 0xb0, 0x50, 0xe7,
0x6c, 0xa1, 0xfa, 0xf8, 0x57, 0xbc, 0xe1, 0xcb, 0xc4, 0x4c, 0xc7, 0x61, 0xde, 0x47, 0x43, 0xef,
0x3d, 0xf3, 0x0f, 0xf0, 0xec, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0xad, 0x5d, 0x44, 0xfb, 0x13,
0x04, 0x00, 0x00,
}

View File

@ -19,6 +19,7 @@ message Source {
string Password = 5;
string URL = 6; // URL are the connections to the source
bool Default = 7; // Flags an exploration as the default.
string Telegraf = 8; // Telegraf is the db telegraf is written to. By default it is "telegraf"
}
message Server {

View File

@ -39,6 +39,7 @@ func TestMarshalSource(t *testing.T) {
Password: "1 point twenty-one g1g@w@tts",
URL: "http://twin-pines.mall.io:8086",
Default: true,
Telegraf: "telegraf",
}
var vv chronograf.Source

View File

@ -75,6 +75,7 @@ type Source struct {
Password string `json:"password,omitempty"` // Password is in CLEARTEXT
URL string `json:"url"` // URL are the connections to the source
Default bool `json:"default"` // Default specifies the default source for the application
Telegraf string `json:"telegraf"` // Telegraf is the db telegraf is written to. By default it is "telegraf"
}
// SourcesStore stores connection information for a `TimeSeries`

View File

@ -21,6 +21,11 @@ type sourceResponse struct {
}
func newSourceResponse(src chronograf.Source) sourceResponse {
// If telegraf is not set, we'll set it to the default value.
if src.Telegraf == "" {
src.Telegraf = "telegraf"
}
httpAPISrcs := "/chronograf/v1/sources"
return sourceResponse{
Source: src,
@ -39,11 +44,17 @@ func (h *Service) NewSource(w http.ResponseWriter, r *http.Request) {
invalidJSON(w)
return
}
if err := ValidSourceRequest(src); err != nil {
invalidData(w, err)
return
}
// By default the telegraf database will be telegraf
if src.Telegraf == "" {
src.Telegraf = "telegraf"
}
var err error
if src, err = h.SourcesStore.Add(r.Context(), src); err != nil {
msg := fmt.Errorf("Error storing source %v: %v", src, err)
@ -154,6 +165,9 @@ func (h *Service) UpdateSource(w http.ResponseWriter, r *http.Request) {
if req.Type != "" {
src.Type = req.Type
}
if req.Telegraf != "" {
src.Telegraf = req.Telegraf
}
if err := ValidSourceRequest(src); err != nil {
invalidData(w, err)

58
server/sources_test.go Normal file
View File

@ -0,0 +1,58 @@
package server
import (
"reflect"
"testing"
"github.com/influxdata/chronograf"
)
func Test_newSourceResponse(t *testing.T) {
tests := []struct {
name string
src chronograf.Source
want sourceResponse
}{
{
name: "Test empty telegraf",
src: chronograf.Source{
ID: 1,
Telegraf: "",
},
want: sourceResponse{
Source: chronograf.Source{
ID: 1,
Telegraf: "telegraf",
},
Links: sourceLinks{
Self: "/chronograf/v1/sources/1",
Proxy: "/chronograf/v1/sources/1/proxy",
Kapacitors: "/chronograf/v1/sources/1/kapacitors",
},
},
},
{
name: "Test non-default telegraf",
src: chronograf.Source{
ID: 1,
Telegraf: "howdy",
},
want: sourceResponse{
Source: chronograf.Source{
ID: 1,
Telegraf: "howdy",
},
Links: sourceLinks{
Self: "/chronograf/v1/sources/1",
Proxy: "/chronograf/v1/sources/1/proxy",
Kapacitors: "/chronograf/v1/sources/1/kapacitors",
},
},
},
}
for _, tt := range tests {
if got := newSourceResponse(tt.src); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%q. newSourceResponse() = %v, want %v", tt.name, got, tt.want)
}
}
}

View File

@ -1481,6 +1481,11 @@
"type": "boolean",
"description": "Indicates whether this source is the default source"
},
"telegraf": {
"type": "string",
"description": "Database where telegraf information is stored for this source",
"default": "telegraf"
},
"links": {
"type": "object",
"properties": {