2
0
Эх сурвалжийг харах

Sth/kcm 4204 (#3180)

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb 11 сар өмнө
parent
commit
c32e1e95d2

+ 1 - 0
modules/collector-source/pkg/collector/datasource.go

@@ -94,6 +94,7 @@ func NewCollectorDataSource(
 	clusterMap := newCollectorClusterMap(clusterInfo)
 
 	return &collectorDataSource{
+		config:         config,
 		metricsQuerier: metricQuerier,
 		clusterInfo:    clusterInfo,
 		clusterMap:     clusterMap,

+ 5 - 1
modules/collector-source/pkg/metric/aggregator/avgovertime.go

@@ -49,7 +49,11 @@ func (a *averageOverTimeAggregator) Value() []MetricValue {
 	a.lock.Lock()
 	defer a.lock.Unlock()
 	if a.count == 0 {
-		return []MetricValue{}
+		return []MetricValue{
+			{
+				Value: 0,
+			},
+		}
 	}
 	return []MetricValue{
 		{a.total / float64(a.count), nil},

+ 5 - 1
modules/collector-source/pkg/metric/aggregator/avgovertime_test.go

@@ -20,7 +20,11 @@ func TestAvgOverTimeAggregator_Value(t *testing.T) {
 	}{
 		"no update": {
 			updates: []update{},
-			want:    []MetricValue{},
+			want: []MetricValue{
+				{
+					Value: 0,
+				},
+			},
 		},
 		"single update": {
 			updates: []update{

+ 0 - 3
modules/collector-source/pkg/metric/aggregator/increase.go

@@ -58,9 +58,6 @@ func (a *increaseAggregator) Update(value float64, timestamp time.Time, addition
 func (a *increaseAggregator) Value() []MetricValue {
 	a.lock.Lock()
 	defer a.lock.Unlock()
-	if !a.initialized {
-		return []MetricValue{}
-	}
 	return []MetricValue{
 		{Value: a.current - a.initial},
 	}

+ 5 - 1
modules/collector-source/pkg/metric/aggregator/increase_test.go

@@ -20,7 +20,11 @@ func TestIncreaseAggregator_Value(t *testing.T) {
 	}{
 		"no update": {
 			updates: []update{},
-			want:    []MetricValue{},
+			want: []MetricValue{
+				{
+					Value: 0,
+				},
+			},
 		},
 		"single update": {
 			updates: []update{

+ 0 - 3
modules/collector-source/pkg/metric/aggregator/iratemax.go

@@ -69,9 +69,6 @@ func (a *iRateMaxAggregator) Update(value float64, timestamp time.Time, addition
 func (a *iRateMaxAggregator) Value() []MetricValue {
 	a.lock.Lock()
 	defer a.lock.Unlock()
-	if !a.initialized {
-		return []MetricValue{}
-	}
 	return []MetricValue{
 		{Value: a.max},
 	}

+ 5 - 1
modules/collector-source/pkg/metric/aggregator/iratemax_test.go

@@ -22,7 +22,11 @@ func TestIRateMaxAggregator_Value(t *testing.T) {
 	}{
 		"no update": {
 			updates: []update{},
-			want:    []MetricValue{},
+			want: []MetricValue{
+				{
+					Value: 0,
+				},
+			},
 		},
 		"single update": {
 			updates: []update{

+ 0 - 3
modules/collector-source/pkg/metric/aggregator/maxovertime.go

@@ -43,9 +43,6 @@ func (a *maxOverTimeAggregator) Update(value float64, timestamp time.Time, addit
 func (a *maxOverTimeAggregator) Value() []MetricValue {
 	a.lock.Lock()
 	defer a.lock.Unlock()
-	if a.max == 0 {
-		return []MetricValue{}
-	}
 	return []MetricValue{
 		{Value: a.max},
 	}

+ 5 - 1
modules/collector-source/pkg/metric/aggregator/maxovertime_test.go

@@ -19,7 +19,11 @@ func TestMaxOverTimeAggregator_Value(t *testing.T) {
 	}{
 		"no update": {
 			updates: []update{},
-			want:    []MetricValue{},
+			want: []MetricValue{
+				{
+					Value: 0,
+				},
+			},
 		},
 		"single update": {
 			updates: []update{

+ 0 - 3
modules/collector-source/pkg/metric/aggregator/rate.go

@@ -60,9 +60,6 @@ func (a *rateAggregator) Update(value float64, timestamp time.Time, additionalIn
 func (a *rateAggregator) Value() []MetricValue {
 	a.lock.Lock()
 	defer a.lock.Unlock()
-	if !a.initialized {
-		return []MetricValue{}
-	}
 	seconds := a.currentTime.Sub(a.initialTime).Seconds()
 	if seconds == 0 {
 		return []MetricValue{

+ 5 - 1
modules/collector-source/pkg/metric/aggregator/rate_test.go

@@ -21,7 +21,11 @@ func TestRateAggregator_Value(t *testing.T) {
 	}{
 		"no update": {
 			updates: []update{},
-			want:    []MetricValue{},
+			want: []MetricValue{
+				{
+					Value: 0,
+				},
+			},
 		},
 		"single update": {
 			updates: []update{