Skip to content

Commit

Permalink
Use a better aggregator name
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhike authored and Buddhike de Silva committed Mar 22, 2023
1 parent 00bca87 commit 485cb68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/aws/aws-sdk-go-v2/service/kinesis/types"
)

// CountPerSecond is an Aggregator to count number of records
// RecordsPerSecond is an Aggregator to count number of records
// received per second (based on ApproximateArrivalTimestamp).
type CountPerSecond struct {
type RecordsPerSecond struct {
min int64 // Start time of aggregation in Unix time format
max int64 // End time of aggregation in Unix time format
timeSeries []int // Store usage value for each shard as an array. Array index is the ordinal value of second within the specified range.
Expand All @@ -25,11 +25,11 @@ type IngressCountStats struct {
Max int `json:"max"`
}

func (i *CountPerSecond) Name() string {
func (i *RecordsPerSecond) Name() string {
return "ingress-count"
}

func (i *CountPerSecond) Aggregate(record *types.Record) {
func (i *RecordsPerSecond) Aggregate(record *types.Record) {
an := record.ApproximateArrivalTimestamp.Unix()
offset := (an - i.min)
if offset < 0 || an > i.max {
Expand All @@ -42,23 +42,23 @@ func (i *CountPerSecond) Aggregate(record *types.Record) {
}
}

func (i *CountPerSecond) Result() interface{} {
func (i *RecordsPerSecond) Result() interface{} {
return IngressCountStats{
i.timeSeries,
i.sum,
i.maxIngressCount,
}
}

func (i *CountPerSecond) MaxUtilisation() float32 {
func (i *RecordsPerSecond) MaxUtilisation() float32 {
const maxRecordsPerSecond = float32(1000)
return float32(i.maxIngressCount) / maxRecordsPerSecond
}

func NewCountPerSecond(start, end time.Time) *CountPerSecond {
func NewCountPerSecond(start, end time.Time) *RecordsPerSecond {
min := start.Unix()
max := end.Unix()
return &CountPerSecond{
return &RecordsPerSecond{
min: min,
max: max,
timeSeries: make([]int, int(max-min)+1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestCountPerSecond(t *testing.T) {
func TestRecordsPerSecond(t *testing.T) {
end := time.Now()
start := time.Now().Add(time.Second * -3)
type w struct {
Expand Down

0 comments on commit 485cb68

Please sign in to comment.