Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8aebecc2
Commit
8aebecc2
authored
Jan 25, 2016
by
Piotr Szczesniak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed e2e tests
parent
331318b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
49 deletions
+50
-49
initial_resources.go
test/e2e/initial_resources.go
+1
-9
monitoring.go
test/e2e/monitoring.go
+49
-40
No files found.
test/e2e/initial_resources.go
View file @
8aebecc2
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"fmt"
"fmt"
"time"
"time"
influxdb
"github.com/influxdb/influxdb/client"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -30,14 +29,7 @@ var _ = Describe("Initial Resources [Skipped] ", func() {
...
@@ -30,14 +29,7 @@ var _ = Describe("Initial Resources [Skipped] ", func() {
f
:=
NewFramework
(
"initial-resources"
)
f
:=
NewFramework
(
"initial-resources"
)
It
(
"should set initial resources based on historical data"
,
func
()
{
It
(
"should set initial resources based on historical data"
,
func
()
{
// Cleanup data in InfluxDB that left from previous tests.
// TODO(piosz): Add cleanup data in InfluxDB that left from previous tests.
influxdbClient
,
err
:=
getInfluxdbClient
(
f
.
Client
)
expectNoError
(
err
,
"failed to create influxdb client"
)
_
,
err
=
influxdbClient
.
Query
(
"drop series autoscaling.cpu.usage.2m"
,
influxdb
.
Second
)
expectNoError
(
err
)
_
,
err
=
influxdbClient
.
Query
(
"drop series autoscaling.memory.usage.2m"
,
influxdb
.
Second
)
expectNoError
(
err
)
cpu
:=
100
cpu
:=
100
mem
:=
200
mem
:=
200
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
;
i
++
{
...
...
test/e2e/monitoring.go
View file @
8aebecc2
...
@@ -17,6 +17,8 @@ limitations under the License.
...
@@ -17,6 +17,8 @@ limitations under the License.
package
e2e
package
e2e
import
(
import
(
"bytes"
"encoding/json"
"fmt"
"fmt"
"net/url"
"net/url"
"time"
"time"
...
@@ -49,10 +51,8 @@ var _ = Describe("[Flaky] Monitoring", func() {
...
@@ -49,10 +51,8 @@ var _ = Describe("[Flaky] Monitoring", func() {
const
(
const
(
influxdbService
=
"monitoring-influxdb"
influxdbService
=
"monitoring-influxdb"
influxdbDatabaseName
=
"k8s"
influxdbDatabaseName
=
"k8s"
influxdbUser
=
"root"
podlistQuery
=
"show tag values from
\"
cpu/usage
\"
with key = pod_id"
influxdbPW
=
"root"
nodelistQuery
=
"show tag values from
\"
cpu/usage
\"
with key = hostname"
podlistQuery
=
"select distinct(pod_id) from
\"
cpu/usage_ns_cumulative
\"
"
nodelistQuery
=
"select distinct(hostname) from
\"
cpu/usage_ns_cumulative
\"
"
sleepBetweenAttempts
=
5
*
time
.
Second
sleepBetweenAttempts
=
5
*
time
.
Second
testTimeout
=
5
*
time
.
Minute
testTimeout
=
5
*
time
.
Minute
)
)
...
@@ -65,6 +65,35 @@ var (
...
@@ -65,6 +65,35 @@ var (
}
}
)
)
// Query sends a command to the server and returns the Response
func
Query
(
c
*
client
.
Client
,
query
string
)
(
*
influxdb
.
Response
,
error
)
{
result
,
err
:=
c
.
Get
()
.
Prefix
(
"proxy"
)
.
Namespace
(
"kube-system"
)
.
Resource
(
"services"
)
.
Name
(
influxdbService
+
":api"
)
.
Suffix
(
"query"
)
.
Param
(
"q"
,
query
)
.
Param
(
"db"
,
influxdbDatabaseName
)
.
Param
(
"epoch"
,
"s"
)
.
Do
()
.
Raw
()
if
err
!=
nil
{
return
nil
,
err
}
var
response
influxdb
.
Response
dec
:=
json
.
NewDecoder
(
bytes
.
NewReader
(
result
))
dec
.
UseNumber
()
err
=
dec
.
Decode
(
&
response
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
response
,
nil
}
func
verifyExpectedRcsExistAndGetExpectedPods
(
c
*
client
.
Client
)
([]
string
,
error
)
{
func
verifyExpectedRcsExistAndGetExpectedPods
(
c
*
client
.
Client
)
([]
string
,
error
)
{
expectedPods
:=
[]
string
{}
expectedPods
:=
[]
string
{}
// Iterate over the labels that identify the replication controllers that we
// Iterate over the labels that identify the replication controllers that we
...
@@ -135,41 +164,24 @@ func getAllNodesInCluster(c *client.Client) ([]string, error) {
...
@@ -135,41 +164,24 @@ func getAllNodesInCluster(c *client.Client) ([]string, error) {
return
result
,
nil
return
result
,
nil
}
}
func
getInfluxdbClient
(
c
*
client
.
Client
)
(
*
influxdb
.
Client
,
error
)
{
func
getInfluxdbData
(
c
*
client
.
Client
,
query
string
,
tag
string
)
(
map
[
string
]
bool
,
error
)
{
proxyUrl
:=
fmt
.
Sprintf
(
"%s/api/v1/proxy/namespaces/%s/services/%s:api/"
,
getMasterHost
(),
api
.
NamespaceSystem
,
influxdbService
)
response
,
err
:=
Query
(
c
,
query
)
config
:=
&
influxdb
.
ClientConfig
{
Host
:
proxyUrl
,
// TODO(vishh): Infer username and pw from the Pod spec.
Username
:
influxdbUser
,
Password
:
influxdbPW
,
Database
:
influxdbDatabaseName
,
HttpClient
:
c
.
Client
,
IsSecure
:
true
,
}
return
influxdb
.
NewClient
(
config
)
}
func
getInfluxdbData
(
c
*
influxdb
.
Client
,
query
string
)
(
map
[
string
]
bool
,
error
)
{
series
,
err
:=
c
.
Query
(
query
,
influxdb
.
Second
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
len
(
serie
s
)
!=
1
{
if
len
(
response
.
Result
s
)
!=
1
{
return
nil
,
fmt
.
Errorf
(
"expected only one
series from Influxdb for query %q. Got %+v"
,
query
,
series
)
return
nil
,
fmt
.
Errorf
(
"expected only one
result from Influxdb for query %q. Got %+v"
,
query
,
response
)
}
}
if
len
(
series
[
0
]
.
GetColumns
())
!=
2
{
if
len
(
response
.
Results
[
0
]
.
Series
)
!=
1
{
Failf
(
"Expected two columns for query %q. Found %v"
,
query
,
series
[
0
]
.
GetColumns
())
return
nil
,
fmt
.
Errorf
(
"expected exactly one series for query %q."
,
query
)
}
if
len
(
response
.
Results
[
0
]
.
Series
[
0
]
.
Columns
)
!=
1
{
Failf
(
"Expected one column for query %q. Found %v"
,
query
,
response
.
Results
[
0
]
.
Series
[
0
]
.
Columns
)
}
}
result
:=
map
[
string
]
bool
{}
result
:=
map
[
string
]
bool
{}
for
_
,
point
:=
range
series
[
0
]
.
GetPoints
()
{
for
_
,
value
:=
range
response
.
Results
[
0
]
.
Series
[
0
]
.
Values
{
if
len
(
point
)
!=
2
{
name
:=
value
[
0
]
.
(
string
)
Failf
(
"Expected only two entries in a point for query %q. Got %v"
,
query
,
point
)
result
[
name
]
=
true
}
name
,
ok
:=
point
[
1
]
.
(
string
)
if
!
ok
{
Failf
(
"expected %v to be a string, but it is %T"
,
point
[
1
],
point
[
1
])
}
result
[
name
]
=
false
}
}
return
result
,
nil
return
result
,
nil
}
}
...
@@ -186,14 +198,14 @@ func expectedItemsExist(expectedItems []string, actualItems map[string]bool) boo
...
@@ -186,14 +198,14 @@ func expectedItemsExist(expectedItems []string, actualItems map[string]bool) boo
return
true
return
true
}
}
func
validatePodsAndNodes
(
influxdbClient
*
influxdb
.
Client
,
expectedPods
,
expectedNodes
[]
string
)
bool
{
func
validatePodsAndNodes
(
c
*
client
.
Client
,
expectedPods
,
expectedNodes
[]
string
)
bool
{
pods
,
err
:=
getInfluxdbData
(
influxdbClient
,
podlistQuery
)
pods
,
err
:=
getInfluxdbData
(
c
,
podlistQuery
,
"pod_id"
)
if
err
!=
nil
{
if
err
!=
nil
{
// We don't fail the test here because the influxdb service might still not be running.
// We don't fail the test here because the influxdb service might still not be running.
Logf
(
"failed to query list of pods from influxdb. Query: %q, Err: %v"
,
podlistQuery
,
err
)
Logf
(
"failed to query list of pods from influxdb. Query: %q, Err: %v"
,
podlistQuery
,
err
)
return
false
return
false
}
}
nodes
,
err
:=
getInfluxdbData
(
influxdbClient
,
nodelistQuery
)
nodes
,
err
:=
getInfluxdbData
(
c
,
nodelistQuery
,
"hostname"
)
if
err
!=
nil
{
if
err
!=
nil
{
Logf
(
"failed to query list of nodes from influxdb. Query: %q, Err: %v"
,
nodelistQuery
,
err
)
Logf
(
"failed to query list of nodes from influxdb. Query: %q, Err: %v"
,
nodelistQuery
,
err
)
return
false
return
false
...
@@ -222,14 +234,11 @@ func testMonitoringUsingHeapsterInfluxdb(c *client.Client) {
...
@@ -222,14 +234,11 @@ func testMonitoringUsingHeapsterInfluxdb(c *client.Client) {
expectNoError
(
expectedServicesExist
(
c
))
expectNoError
(
expectedServicesExist
(
c
))
// TODO: Wait for all pods and services to be running.
// TODO: Wait for all pods and services to be running.
influxdbClient
,
err
:=
getInfluxdbClient
(
c
)
expectNoError
(
err
,
"failed to create influxdb client"
)
expectedNodes
,
err
:=
getAllNodesInCluster
(
c
)
expectedNodes
,
err
:=
getAllNodesInCluster
(
c
)
expectNoError
(
err
)
expectNoError
(
err
)
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
for
{
for
{
if
validatePodsAndNodes
(
influxdbClient
,
expectedPods
,
expectedNodes
)
{
if
validatePodsAndNodes
(
c
,
expectedPods
,
expectedNodes
)
{
return
return
}
}
if
time
.
Since
(
startTime
)
>=
testTimeout
{
if
time
.
Since
(
startTime
)
>=
testTimeout
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment