diff --git a/blip.go b/blip.go index 3b5a6e9..a81629f 100644 --- a/blip.go +++ b/blip.go @@ -19,7 +19,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" ) -const VERSION = "1.2.0" +const VERSION = "1.2.1" var SHA = "" diff --git a/docs/content/about/release-notes.md b/docs/content/about/release-notes.md index d9a2be2..3423ba2 100644 --- a/docs/content/about/release-notes.md +++ b/docs/content/about/release-notes.md @@ -37,6 +37,11 @@ func(metrics []*blip.Metrics) error { 2. If using an integration that works with Blip events, see [event/list.go](https://github.com/cashapp/blip/blob/main/event/list.go) for the new event names. +### v1.2.1 (19 Jul 2024) + +* Fixed bug (panic) in `monitor/level_collector` when plan has no levels. +* Added `plan/default.None`. + ### v1.2.0 (2 Jul 2024) * Rewrote monitor.Engine ("engine v2") and some of level collector (LCO) diff --git a/monitor/level_collector.go b/monitor/level_collector.go index 505b2bc..9361251 100644 --- a/monitor/level_collector.go +++ b/monitor/level_collector.go @@ -421,7 +421,9 @@ func (c *lco) changePlan(ctx context.Context, doneChan chan struct{}, newState, c.state = newState c.plan = newPlan c.levels = levels - c.emr = blip.TimeLimit(0.1, levels[0].Freq, time.Second) // interval minus 10% (max 1s) + if len(levels) > 0 { // there can be 0 levels, e.g. plan/default.None + c.emr = blip.TimeLimit(0.1, levels[0].Freq, time.Second) // interval minus 10% (max 1s) + } // Changing state/plan always resumes (if paused); in fact, it's the // only way to resume after Pause is called diff --git a/plan/default/none.go b/plan/default/none.go new file mode 100644 index 0000000..e7ff797 --- /dev/null +++ b/plan/default/none.go @@ -0,0 +1,14 @@ +// Copyright 2024 Block, Inc. + +package default_plan + +import "github.com/cashapp/blip" + +// None returns an empty plan usual for standby instances of Blip. +func None() blip.Plan { + return blip.Plan{ + Name: "default-none", + Source: "blip", + Levels: map[string]blip.Level{}, + } +} diff --git a/plan/sort_test.go b/plan/sort_test.go index 80234d3..691c6bc 100644 --- a/plan/sort_test.go +++ b/plan/sort_test.go @@ -12,6 +12,7 @@ import ( "github.com/cashapp/blip" "github.com/cashapp/blip/plan" + defaultPlan "github.com/cashapp/blip/plan/default" ) // -------------------------------------------------------------------------- @@ -471,3 +472,14 @@ func TestSortComplex(t *testing.T) { t.Error(diff) } } + +func TestSortDefault_None(t *testing.T) { + p := defaultPlan.None() + gotLevels := plan.Sort(&p) + if gotLevels == nil { + t.Errorf("got nil sorted levels, execpted non-nil return value") + } + if len(gotLevels) != 0 { + t.Errorf("got %d levels from default.None plan, expected 0", len(gotLevels)) + } +}