From 4f83aae835097b2675f98b35d56aa37f6db6878a Mon Sep 17 00:00:00 2001 From: anushree-n Date: Mon, 13 Jul 2015 16:13:56 -0700 Subject: [PATCH] Include custom metrics in ContainerStats structure --- collector/collector_manager.go | 6 +++--- collector/collector_manager_test.go | 6 +++--- collector/fakes.go | 6 +++--- collector/generic_collector.go | 4 ++-- collector/types.go | 6 +++--- info/v1/container.go | 3 +++ info/{v2 => v1}/metric.go | 2 +- 7 files changed, 18 insertions(+), 15 deletions(-) rename info/{v2 => v1}/metric.go (99%) diff --git a/collector/collector_manager.go b/collector/collector_manager.go index a3df12ccbd..e7529e198f 100644 --- a/collector/collector_manager.go +++ b/collector/collector_manager.go @@ -19,7 +19,7 @@ import ( "strings" "time" - "github.com/google/cadvisor/info/v2" + "github.com/google/cadvisor/info/v1" ) type collectorManager struct { @@ -48,12 +48,12 @@ func (cm *collectorManager) RegisterCollector(collector Collector) error { return nil } -func (cm *collectorManager) Collect() (time.Time, []v2.Metric, error) { +func (cm *collectorManager) Collect() (time.Time, []v1.Metric, error) { var errors []error // Collect from all collectors that are ready. var next time.Time - var metrics []v2.Metric + var metrics []v1.Metric for _, c := range cm.collectors { if c.nextCollectionTime.Before(time.Now()) { nextCollection, newMetrics, err := c.collector.Collect() diff --git a/collector/collector_manager_test.go b/collector/collector_manager_test.go index 49877032e4..6f9423ac37 100644 --- a/collector/collector_manager_test.go +++ b/collector/collector_manager_test.go @@ -18,7 +18,7 @@ import ( "testing" "time" - "github.com/google/cadvisor/info/v2" + "github.com/google/cadvisor/info/v1" "github.com/stretchr/testify/assert" ) @@ -28,9 +28,9 @@ type fakeCollector struct { collectedFrom int } -func (fc *fakeCollector) Collect() (time.Time, []v2.Metric, error) { +func (fc *fakeCollector) Collect() (time.Time, []v1.Metric, error) { fc.collectedFrom++ - return fc.nextCollectionTime, []v2.Metric{}, fc.err + return fc.nextCollectionTime, []v1.Metric{}, fc.err } func (fc *fakeCollector) Name() string { diff --git a/collector/fakes.go b/collector/fakes.go index 388f3fc0bf..69b9787ea5 100644 --- a/collector/fakes.go +++ b/collector/fakes.go @@ -17,7 +17,7 @@ package collector import ( "time" - "github.com/google/cadvisor/info/v2" + "github.com/google/cadvisor/info/v1" ) type FakeCollectorManager struct { @@ -27,7 +27,7 @@ func (fkm *FakeCollectorManager) RegisterCollector(collector Collector) error { return nil } -func (fkm *FakeCollectorManager) Collect() (time.Time, []v2.Metric, error) { +func (fkm *FakeCollectorManager) Collect() (time.Time, []v1.Metric, error) { var zero time.Time - return zero, []v2.Metric{}, nil + return zero, []v1.Metric{}, nil } diff --git a/collector/generic_collector.go b/collector/generic_collector.go index a7d5f7ce85..1bb06601b7 100644 --- a/collector/generic_collector.go +++ b/collector/generic_collector.go @@ -19,7 +19,7 @@ import ( "io/ioutil" "time" - "github.com/google/cadvisor/info/v2" + "github.com/google/cadvisor/info/v1" ) type GenericCollector struct { @@ -56,7 +56,7 @@ func (collector *GenericCollector) Name() string { } //Returns collected metrics and the next collection time of the collector -func (collector *GenericCollector) Collect() (time.Time, []v2.Metric, error) { +func (collector *GenericCollector) Collect() (time.Time, []v1.Metric, error) { //TO BE IMPLEMENTED return time.Now(), nil, nil } diff --git a/collector/types.go b/collector/types.go index 8bd29d0604..de977bbb37 100644 --- a/collector/types.go +++ b/collector/types.go @@ -15,7 +15,7 @@ package collector import ( - "github.com/google/cadvisor/info/v2" + "github.com/google/cadvisor/info/v1" "time" ) @@ -27,7 +27,7 @@ type Collector interface { // Returns the next time this collector should be collected from. // Next collection time is always returned, even when an error occurs. // A collection time of zero means no more collection. - Collect() (time.Time, []v2.Metric, error) + Collect() (time.Time, []v1.Metric, error) // Name of this collector. Name() string @@ -42,5 +42,5 @@ type CollectorManager interface { // at which a collector will be ready to collect from. // Next collection time is always returned, even when an error occurs. // A collection time of zero means no more collection. - Collect() (time.Time, []v2.Metric, error) + Collect() (time.Time, []v1.Metric, error) } diff --git a/info/v1/container.go b/info/v1/container.go index e9afe26a71..1f22c35e8c 100644 --- a/info/v1/container.go +++ b/info/v1/container.go @@ -419,6 +419,9 @@ type ContainerStats struct { // Task load stats TaskStats LoadStats `json:"task_stats,omitempty"` + + //Custom metrics from all collectors + CustomMetrics []Metric `json:"custom_metrics,omitempty"` } func timeEq(t1, t2 time.Time, tolerance time.Duration) bool { diff --git a/info/v2/metric.go b/info/v1/metric.go similarity index 99% rename from info/v2/metric.go rename to info/v1/metric.go index 1057980ce3..0311eed97d 100644 --- a/info/v2/metric.go +++ b/info/v1/metric.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package v2 +package v1 import ( "time"