Passed first unit test. Waiting for a fix for influxdb/influxdb-go#12
This commit is contained in:
parent
b94c9936d0
commit
7bd8cc2c0b
@ -23,7 +23,6 @@ import (
|
|||||||
"github.com/google/cadvisor/info"
|
"github.com/google/cadvisor/info"
|
||||||
"github.com/google/cadvisor/storage"
|
"github.com/google/cadvisor/storage"
|
||||||
"github.com/influxdb/influxdb-go"
|
"github.com/influxdb/influxdb-go"
|
||||||
"github.com/kr/pretty"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type influxdbStorage struct {
|
type influxdbStorage struct {
|
||||||
@ -221,7 +220,6 @@ func (self *influxdbStorage) AddStats(ref info.ContainerReference, stats *info.C
|
|||||||
series.Columns, series.Points[0] = self.containerStatsToValues(ref, stats)
|
series.Columns, series.Points[0] = self.containerStatsToValues(ref, stats)
|
||||||
|
|
||||||
self.prevStats = stats.Copy(self.prevStats)
|
self.prevStats = stats.Copy(self.prevStats)
|
||||||
pretty.Printf("% #v", series)
|
|
||||||
err := self.client.WriteSeries([]*influxdb.Series{series})
|
err := self.client.WriteSeries([]*influxdb.Series{series})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -232,7 +230,10 @@ func (self *influxdbStorage) AddStats(ref info.ContainerReference, stats *info.C
|
|||||||
func (self *influxdbStorage) RecentStats(containerName string, numStats int) ([]*info.ContainerStats, error) {
|
func (self *influxdbStorage) RecentStats(containerName string, numStats int) ([]*info.ContainerStats, error) {
|
||||||
// TODO(dengnan): select only columns that we need
|
// TODO(dengnan): select only columns that we need
|
||||||
// TODO(dengnan): escape containerName
|
// TODO(dengnan): escape containerName
|
||||||
query := fmt.Sprintf("select * from %v limit %v where container_path=\"%v\"", self.tableName, numStats, containerName)
|
query := fmt.Sprintf("select * from %v where container_path=\"%v\"", self.tableName, containerName)
|
||||||
|
if numStats > 0 {
|
||||||
|
query = fmt.Sprintf("%v limit %v", query, numStats)
|
||||||
|
}
|
||||||
series, err := self.client.Query(query)
|
series, err := self.client.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -248,7 +249,12 @@ func (self *influxdbStorage) RecentStats(containerName string, numStats int) ([]
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *influxdbStorage) Samples(containerName string, numSamples int) ([]*info.ContainerStatsSample, error) {
|
func (self *influxdbStorage) Samples(containerName string, numSamples int) ([]*info.ContainerStatsSample, error) {
|
||||||
query := fmt.Sprintf("select * from %v limit %v where container_path=\"%v\"", self.tableName, numSamples, containerName)
|
// TODO(dengnan): select only columns that we need
|
||||||
|
// TODO(dengnan): escape containerName
|
||||||
|
query := fmt.Sprintf("select * from %v where container_path=\"%v\"", self.tableName, containerName)
|
||||||
|
if numSamples > 0 {
|
||||||
|
query = fmt.Sprintf("%v limit %v", query, numSamples)
|
||||||
|
}
|
||||||
series, err := self.client.Query(query)
|
series, err := self.client.Query(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -287,6 +293,7 @@ func New(machineName,
|
|||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
hostname string,
|
hostname string,
|
||||||
|
isSecure bool,
|
||||||
percentilesDuration time.Duration,
|
percentilesDuration time.Duration,
|
||||||
) (storage.StorageDriver, error) {
|
) (storage.StorageDriver, error) {
|
||||||
config := &influxdb.ClientConfig{
|
config := &influxdb.ClientConfig{
|
||||||
@ -294,12 +301,14 @@ func New(machineName,
|
|||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
Database: database,
|
Database: database,
|
||||||
// IsSecure: true,
|
IsSecure: isSecure,
|
||||||
}
|
}
|
||||||
client, err := influxdb.NewClient(config)
|
client, err := influxdb.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// TODO(monnand): With go 1.3, we cannot compress data now.
|
||||||
|
client.DisableCompression()
|
||||||
if percentilesDuration.Seconds() < 1.0 {
|
if percentilesDuration.Seconds() < 1.0 {
|
||||||
percentilesDuration = 5 * time.Minute
|
percentilesDuration = 5 * time.Minute
|
||||||
}
|
}
|
||||||
@ -308,6 +317,7 @@ func New(machineName,
|
|||||||
client: client,
|
client: client,
|
||||||
windowLen: percentilesDuration,
|
windowLen: percentilesDuration,
|
||||||
machineName: machineName,
|
machineName: machineName,
|
||||||
|
tableName: tablename,
|
||||||
}
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
@ -37,33 +37,20 @@ func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
|
|||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
Database: database,
|
Database: database,
|
||||||
// IsSecure: true,
|
IsSecure: false,
|
||||||
}
|
}
|
||||||
client, err := influxdb.NewClient(config)
|
client, err := influxdb.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
client.DisableCompression()
|
||||||
deleteAll := fmt.Sprintf("drop series %v", tablename)
|
deleteAll := fmt.Sprintf("drop series %v", tablename)
|
||||||
_, err = client.Query(deleteAll)
|
_, err = client.Query(deleteAll)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// delete all data by the end of the call
|
// delete all data by the end of the call
|
||||||
defer client.Query(deleteAll)
|
// defer client.Query(deleteAll)
|
||||||
|
|
||||||
/*
|
|
||||||
series := &influxdb.Series{
|
|
||||||
Name: tablename,
|
|
||||||
Columns: []string{"col1"},
|
|
||||||
Points: [][]interface{}{
|
|
||||||
[]interface{}{1},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
err = client.WriteSeries([]*influxdb.Series{series})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
driver, err := New(machineName,
|
driver, err := New(machineName,
|
||||||
tablename,
|
tablename,
|
||||||
@ -71,6 +58,7 @@ func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
|
|||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
hostname,
|
hostname,
|
||||||
|
false,
|
||||||
percentilesDuration)
|
percentilesDuration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -78,6 +66,6 @@ func runStorageTest(f func(storage.StorageDriver, *testing.T), t *testing.T) {
|
|||||||
f(driver, t)
|
f(driver, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaxMemoryUsage(t *testing.T) {
|
func TestSampleCpuUsage(t *testing.T) {
|
||||||
runStorageTest(test.StorageDriverTestMaxMemoryUsage, t)
|
runStorageTest(test.StorageDriverTestSampleCpuUsage, t)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user