diff --git a/CHANGELOG.md b/CHANGELOG.md index c501f339ce5..f2ff63bf601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features - [#2058](https://github.com/influxdb/influxdb/pull/2058): Track number of queries executed in stats. +- [#2059](https://github.com/influxdb/influxdb/pull/2059): Retention policies sorted by name on return to client. ### Bugfixes - [#2037](https://github.com/influxdb/influxdb/pull/2037): Don't check 'configExists' at Run() level diff --git a/database.go b/database.go index ec31c663f63..54d7479b32a 100644 --- a/database.go +++ b/database.go @@ -1073,6 +1073,12 @@ type RetentionPolicy struct { shardGroups []*ShardGroup } +type RetentionPolicies []*RetentionPolicy + +func (a RetentionPolicies) Len() int { return len(a) } +func (a RetentionPolicies) Less(i, j int) bool { return a[i].Name < a[j].Name } +func (a RetentionPolicies) Swap(i, j int) { a[i], a[j] = a[j], a[i] } + // NewRetentionPolicy returns a new instance of RetentionPolicy with defaults set. func NewRetentionPolicy(name string) *RetentionPolicy { return &RetentionPolicy{ diff --git a/httpd/handler_test.go b/httpd/handler_test.go index 895d1c90937..32d7cc50426 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -303,7 +303,7 @@ func TestHandler_RetentionPolicies(t *testing.T) { if status != http.StatusOK { t.Fatalf("unexpected status: %d", status) - } else if !strings.Contains(body, `{"results":[{"series":[{"columns":["name","duration","replicaN","default"],"values":[["default","0",1,true],["bar","168h0m0s",1,false]]}]}]}`) { + } else if !strings.Contains(body, `{"results":[{"series":[{"columns":["name","duration","replicaN","default"],"values":[["bar","168h0m0s",1,false],["default","0",1,true]]}]}]}`) { t.Fatalf("Missing retention policy: %s", body) } } diff --git a/server.go b/server.go index a2dab7de905..1d5b7191770 100644 --- a/server.go +++ b/server.go @@ -1331,10 +1331,11 @@ func (s *Server) RetentionPolicies(database string) ([]*RetentionPolicy, error) } // Retrieve the policies. - a := make([]*RetentionPolicy, 0, len(db.policies)) + a := make(RetentionPolicies, 0, len(db.policies)) for _, p := range db.policies { a = append(a, p) } + sort.Sort(a) return a, nil }