Merge pull request #561 from influxdata/fix-layout-uniqueness

Fix layouts to enforce uniqueness
pull/10616/head
Nathan Haugo 2016-11-14 20:41:08 -08:00 committed by GitHub
commit 6c2c90c8b8
2 changed files with 11 additions and 2 deletions

View File

@ -16,6 +16,7 @@ type MultiLayoutStore struct {
// All returns the set of all layouts
func (s *MultiLayoutStore) All(ctx context.Context) ([]chronograf.Layout, error) {
all := []chronograf.Layout{}
layoutSet := map[string]chronograf.Layout{}
ok := false
var err error
for _, store := range s.Stores {
@ -26,7 +27,14 @@ func (s *MultiLayoutStore) All(ctx context.Context) ([]chronograf.Layout, error)
continue
}
ok = true
all = append(all, layouts...)
for _, l := range layouts {
// Enforce that the layout has a unique ID
// If the layout has been seen before then skip
if _, okay := layoutSet[l.ID]; !okay {
layoutSet[l.ID] = l
all = append(all, l)
}
}
}
if !ok {
return nil, err

View File

@ -117,7 +117,7 @@ func openService(boltPath, cannedPath string, logger chronograf.Logger) Service
// These apps are those handled from a directory
apps := canned.NewApps(cannedPath, &uuid.V4{}, logger)
// These apps are statically compiled into chronograf
_ = &canned.BinLayoutStore{
binApps := &canned.BinLayoutStore{
Logger: logger,
}
@ -128,6 +128,7 @@ func openService(boltPath, cannedPath string, logger chronograf.Logger) Service
Stores: []chronograf.LayoutStore{
db.LayoutStore,
apps,
binApps,
},
}