-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance(metrics): include route specific queue length
- Loading branch information
Showing
4 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package redis | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// RouteLength returns count of all items present in the given route. | ||
func (c *client) RouteLength(ctx context.Context, channel string) (int64, error) { | ||
c.Logger.Tracef("reading length of all configured routes in queue") | ||
|
||
items, err := c.Redis.LLen(ctx, channel).Result() | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return items, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package redis | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/go-vela/server/queue/models" | ||
) | ||
|
||
func TestRedis_RouteLength(t *testing.T) { | ||
// setup types | ||
// use global variables in redis_test.go | ||
_item := &models.Item{ | ||
Build: _build, | ||
} | ||
|
||
// setup queue item | ||
bytes, err := json.Marshal(_item) | ||
if err != nil { | ||
t.Errorf("unable to marshal queue item: %v", err) | ||
} | ||
|
||
// setup redis mock | ||
_redis, err := NewTest(_signingPrivateKey, _signingPublicKey, "vela", "vela:second", "vela:third") | ||
if err != nil { | ||
t.Errorf("unable to create queue service: %v", err) | ||
} | ||
|
||
// setup tests | ||
tests := []struct { | ||
routes []string | ||
want int64 | ||
}{ | ||
{ | ||
routes: []string{"vela"}, | ||
want: 1, | ||
}, | ||
{ | ||
routes: []string{"vela", "vela:second", "vela:third"}, | ||
want: 2, | ||
}, | ||
{ | ||
routes: []string{"vela", "vela:second", "phony"}, | ||
want: 3, | ||
}, | ||
} | ||
|
||
// run tests | ||
for _, test := range tests { | ||
for _, channel := range test.routes { | ||
err := _redis.Push(context.Background(), channel, bytes) | ||
if err != nil { | ||
t.Errorf("unable to push item to queue: %v", err) | ||
} | ||
} | ||
got, err := _redis.RouteLength(context.Background(), "vela") | ||
if err != nil { | ||
t.Errorf("RouteLength returned err: %v", err) | ||
} | ||
|
||
if got != test.want { | ||
t.Errorf("Length is %v, want %v", got, test.want) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters