Skip to content

Commit

Permalink
add order option to the memory backend
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Jun 20, 2017
1 parent 3cbaf6a commit ebf21c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions backend/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *Backend) GetRawData(tenant string, id string, end int64, start int64, l
}

// sanity check pEnd
if pEnd < pStart {
if pEnd <= pStart {
pEnd += arraySize
}

Expand All @@ -134,7 +134,7 @@ func (r *Backend) GetRawData(tenant string, id string, end int64, start int64, l

// fill data out array
count := int64(0)
for i := pStart; count < limit && i <= pEnd; i++ {
for i := pEnd; count < limit && i > pStart; i-- {
d := r.tenant[tenant].ts[id].data[i%arraySize]

// if this is a valid point
Expand All @@ -147,6 +147,14 @@ func (r *Backend) GetRawData(tenant string, id string, end int64, start int64, l
}
}

// order
if order == "ASC" {
for i := 0; i < len(res)/2; i++ {
j := len(res) - i - 1
res[i], res[j] = res[j], res[i]
}
}

return res
}

Expand Down Expand Up @@ -174,7 +182,7 @@ func (r Backend) GetStatData(tenant string, id string, end int64, start int64, l
pEnd := r.getPosForTimestamp(end)

// sanity check pEnd
if pEnd < pStart {
if pEnd <= pStart {
pEnd += arraySize
}

Expand Down Expand Up @@ -242,6 +250,14 @@ func (r Backend) GetStatData(tenant string, id string, end int64, start int64, l
}
}

// order
if order == "ASC" {
for i := 0; i < len(res)/2; i++ {
j := len(res) - i - 1
res[i], res[j] = res[j], res[i]
}
}

return res
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

// VER the server version
const VER = "0.12.7"
const VER = "0.13.1"

// defaults
const defaultPort = 8080
Expand Down
2 changes: 1 addition & 1 deletion mohawk.spec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%global shortcommit %(c=%{commit}; echo ${c:0:7})

Name: %{repo}
Version: 0.12.7
Version: 0.13.1
Release: 6%{?dist}
Summary: Mock Hawkular server
License: MIT
Expand Down

0 comments on commit ebf21c1

Please sign in to comment.