Skip to content

Commit

Permalink
Fix linter issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
aLekSer committed Apr 3, 2020
1 parent 9f163be commit 88fddd5
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions pkg/metrics/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type expectedMetricData struct {
val interface{}
}

func assertMetricData(t *testing.T, exporter *metricExporter, metricName string, expected []expectedMetricData) error {
func assertMetricData(t *testing.T, exporter *metricExporter, metricName string, expected []expectedMetricData) {

expectedValuesAsMap := make(map[string]expectedMetricData)
for _, e := range expected {
Expand Down Expand Up @@ -74,7 +74,6 @@ func assertMetricData(t *testing.T, exporter *metricExporter, metricName string,
assert.Equal(t, len(tsd.Points), 1, "assertMetricDataValues can only handle a single Point in a TimeSeries")
assert.Equal(t, tsd.Points[0].Value, e.val, "metric: %s, tags: %v, values don't match; got: %v, want: %v", metricName, tsd.LabelValues, tsd.Points[0].Value, e.val)
}
return nil
}

func resetMetrics() {
Expand Down Expand Up @@ -110,12 +109,11 @@ func TestControllerGameServerCount(t *testing.T) {
c.sync()
c.collect()
reader.ReadAndExport(exporter)
err := assertMetricData(t, exporter, "gameservers_count", []expectedMetricData{
assertMetricData(t, exporter, "gameservers_count", []expectedMetricData{
{labels: []string{"test-fleet", "Ready"}, val: int64(0)},
{labels: []string{"test-fleet", "Shutdown"}, val: int64(1)},
{labels: []string{"none", "PortAllocation"}, val: int64(2)},
})
assert.NoError(t, err)
}

func TestControllerGameServersTotal(t *testing.T) {
Expand All @@ -142,7 +140,7 @@ func TestControllerGameServersTotal(t *testing.T) {

c.sync()
reader.ReadAndExport(exporter)
err := assertMetricData(t, exporter, "gameservers_total", []expectedMetricData{
assertMetricData(t, exporter, "gameservers_total", []expectedMetricData{
{labels: []string{"test", "Creating"}, val: int64(16)},
{labels: []string{"test", "Scheduled"}, val: int64(15)},
{labels: []string{"test", "Starting"}, val: int64(10)},
Expand All @@ -152,7 +150,6 @@ func TestControllerGameServersTotal(t *testing.T) {
{labels: []string{"none", "Starting"}, val: int64(16)},
{labels: []string{"none", "Unhealthy"}, val: int64(1)},
})
assert.NoError(t, err)
}

func TestControllerFleetReplicasCount(t *testing.T) {
Expand All @@ -177,7 +174,7 @@ func TestControllerFleetReplicasCount(t *testing.T) {
c.sync()

reader.ReadAndExport(exporter)
err := assertMetricData(t, exporter, "fleets_replicas_count", []expectedMetricData{
assertMetricData(t, exporter, "fleets_replicas_count", []expectedMetricData{
{labels: []string{"fleet-deleted", "allocated"}, val: int64(0)},
{labels: []string{"fleet-deleted", "desired"}, val: int64(0)},
{labels: []string{"fleet-deleted", "ready"}, val: int64(0)},
Expand All @@ -187,7 +184,6 @@ func TestControllerFleetReplicasCount(t *testing.T) {
{labels: []string{"fleet-test", "ready"}, val: int64(1)},
{labels: []string{"fleet-test", "total"}, val: int64(8)},
})
assert.NoError(t, err)
}

func TestControllerFleetAutoScalerState(t *testing.T) {
Expand Down Expand Up @@ -223,45 +219,39 @@ func TestControllerFleetAutoScalerState(t *testing.T) {
c.sync()

reader.ReadAndExport(exporter)
err := assertMetricData(t, exporter, "fleet_autoscalers_able_to_scale", []expectedMetricData{
assertMetricData(t, exporter, "fleet_autoscalers_able_to_scale", []expectedMetricData{
{labels: []string{"first-fleet", "name-switch"}, val: int64(0)},
{labels: []string{"second-fleet", "name-switch"}, val: int64(1)},
{labels: []string{"deleted-fleet", "deleted"}, val: int64(0)},
})
assert.NoError(t, err)
err = assertMetricData(t, exporter, "fleet_autoscalers_buffer_limits", []expectedMetricData{
assertMetricData(t, exporter, "fleet_autoscalers_buffer_limits", []expectedMetricData{
{labels: []string{"first-fleet", "name-switch", "max"}, val: int64(50)},
{labels: []string{"first-fleet", "name-switch", "min"}, val: int64(10)},
{labels: []string{"second-fleet", "name-switch", "max"}, val: int64(50)},
{labels: []string{"second-fleet", "name-switch", "min"}, val: int64(10)},
{labels: []string{"deleted-fleet", "deleted", "max"}, val: int64(150)},
{labels: []string{"deleted-fleet", "deleted", "min"}, val: int64(15)},
})
assert.NoError(t, err)
err = assertMetricData(t, exporter, "fleet_autoscalers_buffer_size", []expectedMetricData{
assertMetricData(t, exporter, "fleet_autoscalers_buffer_size", []expectedMetricData{
{labels: []string{"first-fleet", "name-switch", "count"}, val: int64(10)},
{labels: []string{"second-fleet", "name-switch", "count"}, val: int64(10)},
{labels: []string{"deleted-fleet", "deleted", "percentage"}, val: int64(50)},
})
assert.NoError(t, err)
err = assertMetricData(t, exporter, "fleet_autoscalers_current_replicas_count", []expectedMetricData{
assertMetricData(t, exporter, "fleet_autoscalers_current_replicas_count", []expectedMetricData{
{labels: []string{"first-fleet", "name-switch"}, val: int64(0)},
{labels: []string{"second-fleet", "name-switch"}, val: int64(20)},
{labels: []string{"deleted-fleet", "deleted"}, val: int64(0)},
})
assert.NoError(t, err)
err = assertMetricData(t, exporter, "fleet_autoscalers_desired_replicas_count", []expectedMetricData{
assertMetricData(t, exporter, "fleet_autoscalers_desired_replicas_count", []expectedMetricData{
{labels: []string{"first-fleet", "name-switch"}, val: int64(0)},
{labels: []string{"second-fleet", "name-switch"}, val: int64(10)},
{labels: []string{"deleted-fleet", "deleted"}, val: int64(0)},
})
assert.NoError(t, err)
err = assertMetricData(t, exporter, "fleet_autoscalers_limited", []expectedMetricData{
assertMetricData(t, exporter, "fleet_autoscalers_limited", []expectedMetricData{
{labels: []string{"first-fleet", "name-switch"}, val: int64(0)},
{labels: []string{"second-fleet", "name-switch"}, val: int64(1)},
{labels: []string{"deleted-fleet", "deleted"}, val: int64(0)},
})
assert.NoError(t, err)
}

func TestControllerGameServersNodeState(t *testing.T) {
Expand All @@ -281,18 +271,16 @@ func TestControllerGameServersNodeState(t *testing.T) {
exporter := &metricExporter{}
reader := metricexport.NewReader()
reader.ReadAndExport(exporter)
err := assertMetricData(t, exporter, "gameservers_node_count", []expectedMetricData{
assertMetricData(t, exporter, "gameservers_node_count", []expectedMetricData{
{labels: []string{}, val: &metricdata.Distribution{
Count: 3,
Sum: 3,
SumOfSquaredDeviation: 2,
BucketOptions: &metricdata.BucketOptions{Bounds: []float64{0.00001, 1.00001, 2.00001, 3.00001, 4.00001, 5.00001, 6.00001, 7.00001, 8.00001, 9.00001, 10.00001, 11.00001, 12.00001, 13.00001, 14.00001, 15.00001, 16.00001, 32.00001, 40.00001, 50.00001, 60.00001, 70.00001, 80.00001, 90.00001, 100.00001, 110.00001, 120.00001}},
Buckets: []metricdata.Bucket{{Count: 1}, {Count: 1}, {Count: 1}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}, {Count: 0}}}},
})
assert.NoError(t, err)
err = assertMetricData(t, exporter, "nodes_count", []expectedMetricData{
assertMetricData(t, exporter, "nodes_count", []expectedMetricData{
{labels: []string{"true"}, val: int64(1)},
{labels: []string{"false"}, val: int64(2)},
})
assert.NoError(t, err)
}

0 comments on commit 88fddd5

Please sign in to comment.