Skip to content

Commit

Permalink
Branch that have jjneely#20 commit and is buildable from this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Smirnov authored and Alexey Zhiltsov committed Dec 1, 2017
1 parent 0cb4e82 commit d306b40
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cmd/bucky-fill/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strings"
)

import "github.com/jjneely/buckytools"
import "github.com/jjneely/buckytools/fill"
import "github.com/Civil/buckytools"
import "github.com/Civil/buckytools/fill"

var (
deleteSourceFiles bool
Expand Down
6 changes: 3 additions & 3 deletions cmd/bucky-isempty/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

import (
"github.com/jjneely/buckytools"
"github.com/jjneely/buckytools/metrics"
"github.com/jjneely/buckytools/whisper"
"github.com/Civil/buckytools"
"github.com/Civil/buckytools/metrics"
"github.com/Civil/buckytools/whisper"
)

// Command Line Flags
Expand Down
4 changes: 2 additions & 2 deletions cmd/bucky-sparsify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

import (
"github.com/jjneely/buckytools"
"github.com/jjneely/buckytools/lock"
"github.com/Civil/buckytools"
"github.com/Civil/buckytools/lock"
)

// Command Line Flags
Expand Down
2 changes: 1 addition & 1 deletion cmd/bucky/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"
)

// import "github.com/jjneely/buckytools/hashing"
// import "github.com/Civil/buckytools/hashing"

type MigrateWork struct {
oldName string
Expand Down
2 changes: 1 addition & 1 deletion cmd/bucky/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net"
)

import "github.com/jjneely/buckytools/hashing"
import "github.com/Civil/buckytools/hashing"

type ClusterConfig struct {
// Port is the port remote buckyd daemons listen on
Expand Down
4 changes: 2 additions & 2 deletions cmd/bucky/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

import "github.com/golang/snappy"

import . "github.com/jjneely/buckytools/metrics"
import "github.com/jjneely/buckytools/hashing"
import . "github.com/Civil/buckytools/metrics"
import "github.com/Civil/buckytools/hashing"

// HostPort is a convenience variable for sub-commands. This holds the
// HOST:PORT to connect to if SetupHostname() is called in init()
Expand Down
2 changes: 1 addition & 1 deletion cmd/bucky/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
)

import . "github.com/jjneely/buckytools"
import . "github.com/Civil/buckytools"

func init() {
usage := "[sub-command]"
Expand Down
2 changes: 1 addition & 1 deletion cmd/bucky/inconsistent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"
)

// import "github.com/jjneely/buckytools/hashing"
// import "github.com/Civil/buckytools/hashing"

func init() {
usage := "[options]"
Expand Down
2 changes: 1 addition & 1 deletion cmd/bucky/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
)

import . "github.com/jjneely/buckytools"
import . "github.com/Civil/buckytools"

// We use STDIN and STDOUT as much as possible for handing lists, and
// other data. Status, errors, and other data not related to pushing
Expand Down
2 changes: 1 addition & 1 deletion cmd/bucky/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"
)

import . "github.com/jjneely/buckytools/metrics"
import . "github.com/Civil/buckytools/metrics"

var tarPrefix string

Expand Down
2 changes: 1 addition & 1 deletion cmd/bucky/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"
)

import . "github.com/jjneely/buckytools/metrics"
import . "github.com/Civil/buckytools/metrics"

func init() {
usage := "[options] <metric expression>"
Expand Down
2 changes: 1 addition & 1 deletion cmd/bucky/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

import "github.com/golang/crypto/ssh/terminal"
import "github.com/jjneely/buckytools/metrics"
import "github.com/Civil/buckytools/metrics"

var metricWorkers int
var workerErrors bool
Expand Down
6 changes: 3 additions & 3 deletions cmd/buckyd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"strings"
)

import . "github.com/jjneely/buckytools"
import "github.com/jjneely/buckytools/metrics"
import "github.com/jjneely/buckytools/hashing"
import . "github.com/Civil/buckytools"
import "github.com/Civil/buckytools/metrics"
import "github.com/Civil/buckytools/hashing"

var metricsCache *metrics.MetricsCacheType
var tmpDir string
Expand Down
4 changes: 2 additions & 2 deletions cmd/buckyd/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

import "github.com/golang/snappy"

import . "github.com/jjneely/buckytools/metrics"
import "github.com/jjneely/buckytools/fill"
import . "github.com/Civil/buckytools/metrics"
import "github.com/Civil/buckytools/fill"

// listMetrics retrieves a list of metrics on the localhost and sends
// it to the client.
Expand Down
2 changes: 1 addition & 1 deletion cmd/findhash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
)

import "github.com/jjneely/buckytools/hashing"
import "github.com/Civil/buckytools/hashing"
import "github.com/pborman/uuid"

func getConfig(file string) []string {
Expand Down
2 changes: 1 addition & 1 deletion datapoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

import "github.com/jjneely/buckytools/whisper"
import "github.com/Civil/buckytools/whisper"

// FindValidDataPoints does a backwards walk through time to examine the
// highest resolution data for each archive / time period. We collect valid
Expand Down
4 changes: 2 additions & 2 deletions fill/fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

import "github.com/jjneely/buckytools/whisper"
import "github.com/Civil/buckytools/whisper"

// fillArchive() is a private function that fills data points from srcWSP
// into dstWsp. Used by FIll()
Expand Down Expand Up @@ -54,7 +54,7 @@ func fillArchive(srcWsp, dstWsp *whisper.Whisper, start, stop int) error {
}
tsStart += ts.Step()
}
dstWsp.UpdateMany(points)
dstWsp.UpdateManyWithRetention(points, v.MaxRetention())

stop = fromTime
if start >= stop {
Expand Down
162 changes: 158 additions & 4 deletions fill/fill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"
)

import "github.com/jjneely/buckytools/whisper"
import "github.com/Civil/buckytools/whisper"

func whisperCreateData(path string, ts []*whisper.TimeSeriesPoint) error {
os.Remove(path) // Don't care if it fails
Expand Down Expand Up @@ -113,7 +113,9 @@ func validateWhisper(path string, ts []*whisper.TimeSeriesPoint) error {
}
defer wsp.Close()

wspData, err := wsp.Fetch(0, int(time.Now().Unix()))
now := int(time.Now().Unix())
fromTime := now - wsp.Retentions()[0].MaxRetention()
wspData, err := wsp.Fetch(fromTime, now)
if err != nil {
return err
}
Expand Down Expand Up @@ -151,8 +153,11 @@ func fetchFromFile(path string) ([]*whisper.TimeSeriesPoint, error) {
}
defer wsp.Close()

now := int(time.Now().Unix())
fromTime := now - wsp.Retentions()[0].MaxRetention()

// Parse and fetch data from it
ts, err := wsp.Fetch(0, int(time.Now().Unix()))
ts, err := wsp.Fetch(fromTime, now)
if err != nil {
return tsp, err
}
Expand All @@ -164,7 +169,7 @@ func simulateFill(a, b []*whisper.TimeSeriesPoint) []*whisper.TimeSeriesPoint {
// Assume that we are simulating the fill operation on WSP DBs created
// with the above functions.
// This is a shallow copy operation.
dataMerged := make([]*whisper.TimeSeriesPoint, 30)
dataMerged := make([]*whisper.TimeSeriesPoint, len(b))
// copy everything in b over to our return value
copy(dataMerged, b)
gapstart := -1
Expand Down Expand Up @@ -240,6 +245,155 @@ func TestFill(t *testing.T) {
fmt.Println()
}

func whisperCreateDataMany(path string, ts []*whisper.TimeSeriesPoint) error {
os.Remove(path) // Don't care if it fails
retentions, err := whisper.ParseRetentionDefs("1m:30m,5m:60m,15m:150m")
if err != nil {
return err
}
wsp, err := whisper.Create(path, retentions, whisper.Sum, 0)
if err != nil {
return err
}
defer wsp.Close()

// Iterate through the slice so we can support null values
wsp.UpdateMany(ts)

return nil
}

func whisperCreateNullsManyArchives(path string) ([]*whisper.TimeSeriesPoint, error) {
values := []float64{
math.NaN(),
math.NaN(),
math.NaN(),
0.0,
7.0,
1.0,
7.0,
2.0,
9.0,
9.0,
9.0,
4.0,
3.0,
2.0,
7.0,
5.0,
1.0,
9.0,
4.0,
4.0,
1.0,
5.0,
5.0,
8.0,
4.0,
2.0,
6.0,
0.0,
math.NaN(),
math.NaN(),
}

now := int(time.Now().Unix())
ts := make([]*whisper.TimeSeriesPoint, 0, len(values))
for _, v := range values {
ts = append(ts, &whisper.TimeSeriesPoint{Value: v, Time: now})
now -= 60
}

os.Remove(path) // Don't care if it fails
retentions, err := whisper.ParseRetentionDefs("1m:30m,5m:60m,15m:150m")
if err != nil {
return ts, err
}
wsp, err := whisper.Create(path, retentions, whisper.Sum, 0)
if err != nil {
return ts, err
}
defer wsp.Close()

for _, point := range ts {
_ = wsp.Update(point.Value, point.Time)
}

return ts, nil
}

func TestTwoArchives(t *testing.T) {
dataC, err := whisperCreateNullsManyArchives("c1.wsp")
if err != nil {
t.Fatal(err)
}

// Create an identical set of test data
err = whisperCreateDataMany("c2.wsp", dataC)
if err != nil {
t.Fatal(err)
}

err = whisperCreateDataMany("d1.wsp", dataC)
if err != nil {
t.Fatal(err)
}

err = whisperCreateDataMany("d2.wsp", dataC)
if err != nil {
t.Fatal(err)
}

// whisper-fill.py needs to be in the PATH somewhere
log.Println("Running whisper-fill.py...")
c := exec.Command("whisper-fill.py", "c1.wsp", "d1.wsp")

reference_err := c.Run()
pythonFill, err := fetchFromFile("d1.wsp")

// Run my version
err = Files("c2.wsp", "d2.wsp", int(time.Now().Unix()))
if err != nil {
t.Error(err)
}
goFill, err := fetchFromFile("d2.wsp")
if err != nil {
t.Error(err)
}

// Compare to what we think our version should be
simuFill := simulateFill(dataC, dataC)

err = validateWhisper("d2.wsp", simuFill)
if err != nil {
t.Error(err)
}

// Validate the reference if whisper-fill.py was found
if reference_err == nil {
err = validateWhisper("d1.wsp", simuFill)
if err != nil {
t.Error(err)
}
}

if len(goFill) != len(pythonFill) {
t.Fatalf("length mismatch, python=%v, go=%v, expected=%v", len(goFill), len(pythonFill))
}

// Now try to print out a table of C, D, Python, Go, Simu
fmt.Printf("C \tD \tPython\tGo \tSimu\n")
fmt.Printf("======\t======\t======\t======\t======\n")
for i := 0; i < len(goFill); i++ {
if reference_err != nil {
fmt.Printf("%6.1f\t%6.1f\t%6.1f\t%6.1f\t%6.1f\n", dataC[i].Value, dataC[i].Value, math.NaN(), goFill[i].Value, simuFill[i].Value)
} else {
fmt.Printf("%6.1f\t%6.1f\t%6.1f\t%6.1f\t%6.1f\n", dataC[i].Value, dataC[i].Value, pythonFill[i].Value, goFill[i].Value, simuFill[i].Value)
}
}
fmt.Println()
}

func TestReference(t *testing.T) {
// Create our random test data
dataA, err := whisperCreate("a1.wsp")
Expand Down
Loading

0 comments on commit d306b40

Please sign in to comment.