From 38eec5793f1f668359295ba5dcba0da456e4dca5 Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Tue, 10 Jul 2018 13:26:18 -0500 Subject: [PATCH 1/4] make sure time range views are calculated correctly across months --- executor_test.go | 2 +- time.go | 17 +++++++++++++++-- time_internal_test.go | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/executor_test.go b/executor_test.go index 6e01f111f..034e5bc70 100644 --- a/executor_test.go +++ b/executor_test.go @@ -1279,7 +1279,7 @@ func TestExecutor_Time_Clear_Quantums(t *testing.T) { expected []uint64 }{ {quantum: "Y", expected: []uint64{3, 4, 5, 6}}, - {quantum: "M", expected: []uint64{3, 4, 6}}, + {quantum: "M", expected: []uint64{3, 4, 5, 6}}, {quantum: "D", expected: []uint64{3, 4, 5, 6}}, {quantum: "H", expected: []uint64{3, 4, 5, 6, 7}}, {quantum: "YM", expected: []uint64{3, 4, 5, 6}}, diff --git a/time.go b/time.go index ecfdcad3d..bb3c1b7c2 100644 --- a/time.go +++ b/time.go @@ -140,7 +140,7 @@ func viewsByTimeRange(name string, start, end time.Time, q TimeQuantum) []string break } else if t.Month() != 1 { results = append(results, viewByTimeUnit(name, t, 'M')) - t = t.AddDate(0, 1, 0) + t = addMonth(t) continue } } @@ -159,7 +159,7 @@ func viewsByTimeRange(name string, start, end time.Time, q TimeQuantum) []string t = t.AddDate(1, 0, 0) } else if hasMonth && nextMonthGTE(t, end) { results = append(results, viewByTimeUnit(name, t, 'M')) - t = t.AddDate(0, 1, 0) + t = addMonth(t) } else if hasDay && nextDayGTE(t, end) { results = append(results, viewByTimeUnit(name, t, 'D')) t = t.AddDate(0, 0, 1) @@ -174,6 +174,19 @@ func viewsByTimeRange(name string, start, end time.Time, q TimeQuantum) []string return results } +// addMonth adds a month similar to time.AddDate(0, 1, 0), but +// in certain edge cases it doesn't normalize for days late in the month. +// In the "YM" case where t.Day is greater than 28, there are +// edge cases where using time.AddDate() to add a month will result +// in two "months" being added (Jan 31 + 1mo = March 2). +func addMonth(t time.Time) time.Time { + if t.Day() > 28 { + t = time.Date(t.Year(), t.Month(), 1, t.Hour(), 0, 0, 0, t.Location()) + } + t = t.AddDate(0, 1, 0) + return t +} + func nextYearGTE(t time.Time, end time.Time) bool { next := t.AddDate(1, 0, 0) if next.Year() == end.Year() { diff --git a/time_internal_test.go b/time_internal_test.go index bd4afae43..18d5933be 100644 --- a/time_internal_test.go +++ b/time_internal_test.go @@ -97,6 +97,24 @@ func TestViewsByTimeRange(t *testing.T) { t.Fatalf("unexpected fields: %#v", a) } }) + t.Run("YM31up", func(t *testing.T) { + a := viewsByTimeRange("F", mustParseTime("2001-10-31 00:00"), mustParseTime("2003-04-01 00:00"), mustParseTimeQuantum("YM")) + if !reflect.DeepEqual(a, []string{"F_200110", "F_200111", "F_200112", "F_2002", "F_200301", "F_200302", "F_200303"}) { + t.Fatalf("unexpected fields: %#v", a) + } + }) + t.Run("YM31mid", func(t *testing.T) { + a := viewsByTimeRange("F", mustParseTime("1999-12-31 00:00"), mustParseTime("2000-04-01 00:00"), mustParseTimeQuantum("YM")) + if !reflect.DeepEqual(a, []string{"F_199912", "F_200001", "F_200002", "F_200003"}) { + t.Fatalf("unexpected fields: %#v", a) + } + }) + t.Run("YM31down", func(t *testing.T) { + a := viewsByTimeRange("F", mustParseTime("2000-01-31 00:00"), mustParseTime("2001-04-01 00:00"), mustParseTimeQuantum("YM")) + if !reflect.DeepEqual(a, []string{"F_2000", "F_200101", "F_200102", "F_200103"}) { + t.Fatalf("unexpected fields: %#v", a) + } + }) t.Run("YMD", func(t *testing.T) { a := viewsByTimeRange("F", mustParseTime("2000-11-28 00:00"), mustParseTime("2003-03-02 00:00"), mustParseTimeQuantum("YMD")) if !reflect.DeepEqual(a, []string{"F_20001128", "F_20001129", "F_20001130", "F_200012", "F_2001", "F_2002", "F_200301", "F_200302", "F_20030301"}) { From 96cabf1a0af748f615746c3f7bc4476ec67bac41 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Wed, 11 Jul 2018 11:38:50 -0500 Subject: [PATCH 2/4] Use `dep ensure -vendor-only` for build repeatability. Fixes #1490. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 90e4700df..1e4046bbc 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ clean: # Set up vendor directory using `dep` vendor: Gopkg.toml $(MAKE) require-dep - dep ensure + dep ensure -vendor-only touch vendor # Run test suite From 8196fae7bcfd55c0eaab02eaf25d3be6565b6e68 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Wed, 11 Jul 2018 12:15:15 -0500 Subject: [PATCH 3/4] Rename WebUI to Console, update installation instructions. --- docs/{webui.md => console.md} | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) rename docs/{webui.md => console.md} (62%) diff --git a/docs/webui.md b/docs/console.md similarity index 62% rename from docs/webui.md rename to docs/console.md index a07132852..22556591b 100644 --- a/docs/webui.md +++ b/docs/console.md @@ -1,42 +1,44 @@ +++ -title = "WebUI" +title = "Console" weight = 9 nav = [ - "Console", + "Installation", + "Query", "Cluster Admin", ] +++ -## WebUI +## Console -A web-based app called Pilosa WebUI is available in a separate package. This can be used for constructing queries and viewing the cluster status. +A web-based app called Pilosa Console is available in a separate package. This can be used for constructing queries and viewing the cluster status. ### Installation -Releases are [available on Github](https://github.com/pilosa/webui/releases) as well as on [Homebrew](https://brew.sh/) for Mac. +Releases are [available on Github](https://github.com/pilosa/console/releases) as well as on [Homebrew](https://brew.sh/) for Mac. Installing on a Mac with Homebrew is simple; just run: ``` -brew install pilosa-webui +brew tap pilosa/homebrew-pilosa +brew install pilosa-console ``` -You may also build from source by checking out the [repo on Github](https://github.com/pilosa/webui) and running: +You may also build from source by checking out the [repo on Github](https://github.com/pilosa/console) and running: ``` make install ``` -### Console +### Query -The Console view allows you to enter [PQL](../query-language/) queries and run them against your locally running server. First you must select an Index with the Select index dropdown. +The Query tab allows you to enter [PQL](../query-language/) queries and run them against your locally running server. First you must select an Index with the Select index dropdown. Each query's result will be displayed in the Output section along with the query time. The Console will keep a record of each query and its result with the latest query on top. ![webUI console screenshot](/img/docs/webui-console.png) -*WebUI console screenshot* +*Console query screenshot* In addition to standard PQL, the console supports a few special commands, prefixed with `:`. From 42c935395b21d65ecb73077824a4713bb3b992e1 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Wed, 11 Jul 2018 12:30:39 -0500 Subject: [PATCH 4/4] Update alt text --- docs/console.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/console.md b/docs/console.md index 22556591b..18c6a89c4 100644 --- a/docs/console.md +++ b/docs/console.md @@ -37,7 +37,7 @@ Each query's result will be displayed in the Output section along with the query The Console will keep a record of each query and its result with the latest query on top. -![webUI console screenshot](/img/docs/webui-console.png) +![Console screenshot](/img/docs/webui-console.png) *Console query screenshot* In addition to standard PQL, the console supports a few special commands, prefixed with `:`.