Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
24ead3a4
Commit
24ead3a4
authored
Mar 15, 2019
by
ryan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add random_walk_table scenario
parent
2b5ac6ba
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
4 deletions
+131
-4
pkg/tsdb/testdata/scenarios.go
+68
-0
pkg/tsdb/testdata/scenarios_test.go
+63
-4
No files found.
pkg/tsdb/testdata/scenarios.go
View file @
24ead3a4
...
...
@@ -2,6 +2,7 @@ package testdata
import
(
"encoding/json"
"math"
"math/rand"
"strconv"
"strings"
...
...
@@ -101,6 +102,15 @@ func init() {
})
registerScenario
(
&
Scenario
{
Id
:
"random_walk_table"
,
Name
:
"Random Walk Table"
,
Handler
:
func
(
query
*
tsdb
.
Query
,
context
*
tsdb
.
TsdbQuery
)
*
tsdb
.
QueryResult
{
return
getRandomWalkTable
(
query
,
context
)
},
})
registerScenario
(
&
Scenario
{
Id
:
"slow_query"
,
Name
:
"Slow Query"
,
StringInput
:
"5s"
,
...
...
@@ -267,6 +277,64 @@ func getRandomWalk(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery) *tsdb.QueryResu
return
queryRes
}
func
getRandomWalkTable
(
query
*
tsdb
.
Query
,
tsdbQuery
*
tsdb
.
TsdbQuery
)
*
tsdb
.
QueryResult
{
timeWalkerMs
:=
tsdbQuery
.
TimeRange
.
GetFromAsMsEpoch
()
to
:=
tsdbQuery
.
TimeRange
.
GetToAsMsEpoch
()
table
:=
tsdb
.
Table
{
Columns
:
[]
tsdb
.
TableColumn
{
{
Text
:
"Time"
},
{
Text
:
"Value"
},
{
Text
:
"Min"
},
{
Text
:
"Max"
},
{
Text
:
"Info"
},
},
Rows
:
[]
tsdb
.
RowValues
{},
}
withNil
:=
query
.
Model
.
Get
(
"withNil"
)
.
MustBool
(
false
)
walker
:=
query
.
Model
.
Get
(
"startValue"
)
.
MustFloat64
(
rand
.
Float64
()
*
100
)
spread
:=
2.5
var
info
strings
.
Builder
for
i
:=
int64
(
0
);
i
<
query
.
MaxDataPoints
&&
timeWalkerMs
<
to
;
i
++
{
delta
:=
rand
.
Float64
()
-
0.5
walker
+=
delta
info
.
Reset
()
if
delta
>
0
{
info
.
WriteString
(
"up"
)
}
else
{
info
.
WriteString
(
"down"
)
}
if
math
.
Abs
(
delta
)
>
.4
{
info
.
WriteString
(
" fast"
)
}
row
:=
tsdb
.
RowValues
{
float64
(
timeWalkerMs
),
walker
,
walker
-
((
rand
.
Float64
()
*
spread
)
+
0.01
),
// Min
walker
+
((
rand
.
Float64
()
*
spread
)
+
0.01
),
// Max
info
.
String
(),
}
// Add some random null values
if
withNil
&&
rand
.
Float64
()
>
0.8
{
for
i
:=
1
;
i
<
4
;
i
++
{
if
rand
.
Float64
()
>
.2
{
row
[
i
]
=
nil
}
}
}
table
.
Rows
=
append
(
table
.
Rows
,
row
)
timeWalkerMs
+=
query
.
IntervalMs
}
queryRes
:=
tsdb
.
NewQueryResult
()
queryRes
.
Tables
=
append
(
queryRes
.
Tables
,
&
table
)
return
queryRes
}
func
registerScenario
(
scenario
*
Scenario
)
{
ScenarioRegistry
[
scenario
.
Id
]
=
scenario
}
...
...
pkg/tsdb/testdata/scenarios_test.go
View file @
24ead3a4
...
...
@@ -11,13 +11,14 @@ import (
func
TestTestdataScenarios
(
t
*
testing
.
T
)
{
Convey
(
"random walk "
,
t
,
func
()
{
if
scenario
,
exist
:=
ScenarioRegistry
[
"random_walk"
];
exist
{
scenario
,
exist
:=
ScenarioRegistry
[
"random_walk"
]
So
(
exist
,
ShouldBeTrue
)
Convey
(
"Should start at the requested value"
,
func
()
{
req
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
tsdb
.
NewFakeTimeRange
(
"5m"
,
"now"
,
time
.
Now
()),
Queries
:
[]
*
tsdb
.
Query
{
{
RefId
:
"A"
,
IntervalMs
:
100
,
MaxDataPoints
:
1
0
,
Model
:
simplejson
.
New
()},
{
RefId
:
"A"
,
IntervalMs
:
100
,
MaxDataPoints
:
10
0
,
Model
:
simplejson
.
New
()},
},
}
query
:=
req
.
Queries
[
0
]
...
...
@@ -29,9 +30,67 @@ func TestTestdataScenarios(t *testing.T) {
So
(
result
.
Series
,
ShouldNotBeNil
)
So
(
points
[
0
][
0
]
.
Float64
,
ShouldEqual
,
1.234
)
})
})
Convey
(
"random walk table"
,
t
,
func
()
{
scenario
,
exist
:=
ScenarioRegistry
[
"random_walk_table"
]
So
(
exist
,
ShouldBeTrue
)
}
else
{
t
.
Fail
()
Convey
(
"Should return a table that looks like value/min/max"
,
func
()
{
req
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
tsdb
.
NewFakeTimeRange
(
"5m"
,
"now"
,
time
.
Now
()),
Queries
:
[]
*
tsdb
.
Query
{
{
RefId
:
"A"
,
IntervalMs
:
100
,
MaxDataPoints
:
100
,
Model
:
simplejson
.
New
()},
},
}
result
:=
scenario
.
Handler
(
req
.
Queries
[
0
],
req
)
table
:=
result
.
Tables
[
0
]
So
(
len
(
table
.
Rows
),
ShouldBeGreaterThan
,
50
)
for
_
,
row
:=
range
table
.
Rows
{
value
:=
row
[
1
]
min
:=
row
[
2
]
max
:=
row
[
3
]
So
(
min
,
ShouldBeLessThan
,
value
)
So
(
max
,
ShouldBeGreaterThan
,
value
)
}
})
Convey
(
"Should return a table with some nil values"
,
func
()
{
req
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
tsdb
.
NewFakeTimeRange
(
"5m"
,
"now"
,
time
.
Now
()),
Queries
:
[]
*
tsdb
.
Query
{
{
RefId
:
"A"
,
IntervalMs
:
100
,
MaxDataPoints
:
100
,
Model
:
simplejson
.
New
()},
},
}
query
:=
req
.
Queries
[
0
]
query
.
Model
.
Set
(
"withNil"
,
true
)
result
:=
scenario
.
Handler
(
req
.
Queries
[
0
],
req
)
table
:=
result
.
Tables
[
0
]
nil1
:=
false
nil2
:=
false
nil3
:=
false
So
(
len
(
table
.
Rows
),
ShouldBeGreaterThan
,
50
)
for
_
,
row
:=
range
table
.
Rows
{
if
row
[
1
]
==
nil
{
nil1
=
true
}
if
row
[
2
]
==
nil
{
nil2
=
true
}
if
row
[
3
]
==
nil
{
nil3
=
true
}
}
So
(
nil1
,
ShouldBeTrue
)
So
(
nil2
,
ShouldBeTrue
)
So
(
nil3
,
ShouldBeTrue
)
})
})
}
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