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
cedaf41a
Unverified
Commit
cedaf41a
authored
Dec 14, 2020
by
Emil Hessman
Committed by
GitHub
Dec 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite opentsdb test to standard library (#29792)
parent
2b5a88bf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
49 deletions
+56
-49
pkg/tsdb/opentsdb/opentsdb_test.go
+56
-49
No files found.
pkg/tsdb/opentsdb/opentsdb_test.go
View file @
cedaf41a
...
...
@@ -5,14 +5,13 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
.
"github.com/smartystreets/goconvey/convey
"
"github.com/stretchr/testify/require
"
)
func
TestOpenTsdbExecutor
(
t
*
testing
.
T
)
{
Convey
(
"OpenTsdb query testing"
,
t
,
func
()
{
exec
:=
&
OpenTsdbExecutor
{}
Convey
(
"Build metric with downsampling enabled"
,
func
(
)
{
t
.
Run
(
"Build metric with downsampling enabled"
,
func
(
t
*
testing
.
T
)
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
...
...
@@ -26,13 +25,13 @@ func TestOpenTsdbExecutor(t *testing.T) {
metric
:=
exec
.
buildMetric
(
query
)
So
(
len
(
metric
),
ShouldEqual
,
3
)
So
(
metric
[
"metric"
],
ShouldEqual
,
"cpu.average.percent"
)
So
(
metric
[
"aggregator"
],
ShouldEqual
,
"avg"
)
So
(
metric
[
"downsample"
],
ShouldEqual
,
"1m-avg"
)
require
.
Len
(
t
,
metric
,
3
)
require
.
Equal
(
t
,
"cpu.average.percent"
,
metric
[
"metric"
]
)
require
.
Equal
(
t
,
"avg"
,
metric
[
"aggregator"
]
)
require
.
Equal
(
t
,
"1m-avg"
,
metric
[
"downsample"
]
)
})
Convey
(
"Build metric with downsampling disabled"
,
func
(
)
{
t
.
Run
(
"Build metric with downsampling disabled"
,
func
(
t
*
testing
.
T
)
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
...
...
@@ -46,12 +45,12 @@ func TestOpenTsdbExecutor(t *testing.T) {
metric
:=
exec
.
buildMetric
(
query
)
So
(
len
(
metric
),
ShouldEqual
,
2
)
So
(
metric
[
"metric"
],
ShouldEqual
,
"cpu.average.percent"
)
So
(
metric
[
"aggregator"
],
ShouldEqual
,
"avg"
)
require
.
Len
(
t
,
metric
,
2
)
require
.
Equal
(
t
,
"cpu.average.percent"
,
metric
[
"metric"
]
)
require
.
Equal
(
t
,
"avg"
,
metric
[
"aggregator"
]
)
})
Convey
(
"Build metric with downsampling enabled with params"
,
func
(
)
{
t
.
Run
(
"Build metric with downsampling enabled with params"
,
func
(
t
*
testing
.
T
)
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
...
...
@@ -65,13 +64,13 @@ func TestOpenTsdbExecutor(t *testing.T) {
metric
:=
exec
.
buildMetric
(
query
)
So
(
len
(
metric
),
ShouldEqual
,
3
)
So
(
metric
[
"metric"
],
ShouldEqual
,
"cpu.average.percent"
)
So
(
metric
[
"aggregator"
],
ShouldEqual
,
"avg"
)
So
(
metric
[
"downsample"
],
ShouldEqual
,
"5m-sum-null"
)
require
.
Len
(
t
,
metric
,
3
)
require
.
Equal
(
t
,
"cpu.average.percent"
,
metric
[
"metric"
]
)
require
.
Equal
(
t
,
"avg"
,
metric
[
"aggregator"
]
)
require
.
Equal
(
t
,
"5m-sum-null"
,
metric
[
"downsample"
]
)
})
Convey
(
"Build metric with tags with downsampling disabled"
,
func
(
)
{
t
.
Run
(
"Build metric with tags with downsampling disabled"
,
func
(
t
*
testing
.
T
)
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
...
...
@@ -90,17 +89,19 @@ func TestOpenTsdbExecutor(t *testing.T) {
metric
:=
exec
.
buildMetric
(
query
)
So
(
len
(
metric
),
ShouldEqual
,
3
)
So
(
metric
[
"metric"
],
ShouldEqual
,
"cpu.average.percent"
)
So
(
metric
[
"aggregator"
],
ShouldEqual
,
"avg"
)
So
(
metric
[
"downsample"
],
ShouldEqual
,
nil
)
So
(
len
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})),
ShouldEqual
,
2
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"env"
],
ShouldEqual
,
"prod"
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"app"
],
ShouldEqual
,
"grafana"
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"ip"
],
ShouldEqual
,
nil
)
require
.
Len
(
t
,
metric
,
3
)
require
.
Equal
(
t
,
"cpu.average.percent"
,
metric
[
"metric"
])
require
.
Equal
(
t
,
"avg"
,
metric
[
"aggregator"
])
require
.
Nil
(
t
,
metric
[
"downsample"
])
metricTags
:=
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})
require
.
Len
(
t
,
metricTags
,
2
)
require
.
Equal
(
t
,
"prod"
,
metricTags
[
"env"
])
require
.
Equal
(
t
,
"grafana"
,
metricTags
[
"app"
])
require
.
Nil
(
t
,
metricTags
[
"ip"
])
})
Convey
(
"Build metric with rate enabled but counter disabled"
,
func
(
)
{
t
.
Run
(
"Build metric with rate enabled but counter disabled"
,
func
(
t
*
testing
.
T
)
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
...
...
@@ -118,18 +119,21 @@ func TestOpenTsdbExecutor(t *testing.T) {
metric
:=
exec
.
buildMetric
(
query
)
So
(
len
(
metric
),
ShouldEqual
,
5
)
So
(
metric
[
"metric"
],
ShouldEqual
,
"cpu.average.percent"
)
So
(
metric
[
"aggregator"
],
ShouldEqual
,
"avg"
)
So
(
len
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})),
ShouldEqual
,
2
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"env"
],
ShouldEqual
,
"prod"
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"app"
],
ShouldEqual
,
"grafana"
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"ip"
],
ShouldEqual
,
nil
)
So
(
metric
[
"rate"
],
ShouldEqual
,
true
)
So
(
metric
[
"rateOptions"
]
.
(
map
[
string
]
interface
{})[
"counter"
],
ShouldEqual
,
false
)
require
.
Len
(
t
,
metric
,
5
)
require
.
Equal
(
t
,
"cpu.average.percent"
,
metric
[
"metric"
])
require
.
Equal
(
t
,
"avg"
,
metric
[
"aggregator"
])
metricTags
:=
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})
require
.
Len
(
t
,
metricTags
,
2
)
require
.
Equal
(
t
,
"prod"
,
metricTags
[
"env"
])
require
.
Equal
(
t
,
"grafana"
,
metricTags
[
"app"
])
require
.
Nil
(
t
,
metricTags
[
"ip"
])
require
.
True
(
t
,
metric
[
"rate"
]
.
(
bool
))
require
.
False
(
t
,
metric
[
"rateOptions"
]
.
(
map
[
string
]
interface
{})[
"counter"
]
.
(
bool
))
})
Convey
(
"Build metric with rate and counter enabled"
,
func
(
)
{
t
.
Run
(
"Build metric with rate and counter enabled"
,
func
(
t
*
testing
.
T
)
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
...
...
@@ -149,18 +153,21 @@ func TestOpenTsdbExecutor(t *testing.T) {
metric
:=
exec
.
buildMetric
(
query
)
So
(
len
(
metric
),
ShouldEqual
,
5
)
So
(
metric
[
"metric"
],
ShouldEqual
,
"cpu.average.percent"
)
So
(
metric
[
"aggregator"
],
ShouldEqual
,
"avg"
)
So
(
len
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})),
ShouldEqual
,
2
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"env"
],
ShouldEqual
,
"prod"
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"app"
],
ShouldEqual
,
"grafana"
)
So
(
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})[
"ip"
],
ShouldEqual
,
nil
)
So
(
metric
[
"rate"
],
ShouldEqual
,
true
)
So
(
len
(
metric
[
"rateOptions"
]
.
(
map
[
string
]
interface
{})),
ShouldEqual
,
3
)
So
(
metric
[
"rateOptions"
]
.
(
map
[
string
]
interface
{})[
"counter"
],
ShouldEqual
,
true
)
So
(
metric
[
"rateOptions"
]
.
(
map
[
string
]
interface
{})[
"counterMax"
],
ShouldEqual
,
45
)
So
(
metric
[
"rateOptions"
]
.
(
map
[
string
]
interface
{})[
"resetValue"
],
ShouldEqual
,
60
)
})
require
.
Len
(
t
,
metric
,
5
)
require
.
Equal
(
t
,
"cpu.average.percent"
,
metric
[
"metric"
])
require
.
Equal
(
t
,
"avg"
,
metric
[
"aggregator"
])
metricTags
:=
metric
[
"tags"
]
.
(
map
[
string
]
interface
{})
require
.
Len
(
t
,
metricTags
,
2
)
require
.
Equal
(
t
,
"prod"
,
metricTags
[
"env"
])
require
.
Equal
(
t
,
"grafana"
,
metricTags
[
"app"
])
require
.
Nil
(
t
,
metricTags
[
"ip"
])
require
.
True
(
t
,
metric
[
"rate"
]
.
(
bool
))
metricRateOptions
:=
metric
[
"rateOptions"
]
.
(
map
[
string
]
interface
{})
require
.
Len
(
t
,
metricRateOptions
,
3
)
require
.
True
(
t
,
metricRateOptions
[
"counter"
]
.
(
bool
))
require
.
Equal
(
t
,
float64
(
45
),
metricRateOptions
[
"counterMax"
])
require
.
Equal
(
t
,
float64
(
60
),
metricRateOptions
[
"resetValue"
])
})
}
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