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
10d581dd
Commit
10d581dd
authored
Oct 17, 2016
by
utkarshcmu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for query parsing
parent
2374d098
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
176 additions
and
0 deletions
+176
-0
pkg/tsdb/opentsdb/opentsdb_test.go
+176
-0
No files found.
pkg/tsdb/opentsdb/opentsdb_test.go
View file @
10d581dd
package
opentsdb
import
(
"testing"
"github.com/grafana/grafana/pkg/tsdb"
.
"github.com/smartystreets/goconvey/convey"
"github.com/grafana/grafana/pkg/components/simplejson"
)
func
TestOpenTsdbExecutor
(
t
*
testing
.
T
)
{
Convey
(
"OpenTsdb query testing"
,
t
,
func
()
{
exec
:=
&
OpenTsdbExecutor
{}
Convey
(
"Build metric with downsampling enabled"
,
func
()
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
query
.
Model
.
Set
(
"metric"
,
"cpu.average.percent"
)
query
.
Model
.
Set
(
"aggregator"
,
"avg"
)
query
.
Model
.
Set
(
"disableDownsampling"
,
false
)
query
.
Model
.
Set
(
"downsampleInterval"
,
""
)
query
.
Model
.
Set
(
"downsampleAggregator"
,
"avg"
)
query
.
Model
.
Set
(
"downsampleFillPolicy"
,
"none"
)
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"
)
})
Convey
(
"Build metric with downsampling diabled"
,
func
()
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
query
.
Model
.
Set
(
"metric"
,
"cpu.average.percent"
)
query
.
Model
.
Set
(
"aggregator"
,
"avg"
)
query
.
Model
.
Set
(
"disableDownsampling"
,
true
)
query
.
Model
.
Set
(
"downsampleInterval"
,
""
)
query
.
Model
.
Set
(
"downsampleAggregator"
,
"avg"
)
query
.
Model
.
Set
(
"downsampleFillPolicy"
,
"none"
)
metric
:=
exec
.
buildMetric
(
query
)
So
(
len
(
metric
),
ShouldEqual
,
2
)
So
(
metric
[
"metric"
],
ShouldEqual
,
"cpu.average.percent"
)
So
(
metric
[
"aggregator"
],
ShouldEqual
,
"avg"
)
})
Convey
(
"Build metric with downsampling enabled with params"
,
func
()
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
query
.
Model
.
Set
(
"metric"
,
"cpu.average.percent"
)
query
.
Model
.
Set
(
"aggregator"
,
"avg"
)
query
.
Model
.
Set
(
"disableDownsampling"
,
false
)
query
.
Model
.
Set
(
"downsampleInterval"
,
"5m"
)
query
.
Model
.
Set
(
"downsampleAggregator"
,
"sum"
)
query
.
Model
.
Set
(
"downsampleFillPolicy"
,
"null"
)
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"
)
})
Convey
(
"Build metric with tags with downsampling disabled"
,
func
()
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
query
.
Model
.
Set
(
"metric"
,
"cpu.average.percent"
)
query
.
Model
.
Set
(
"aggregator"
,
"avg"
)
query
.
Model
.
Set
(
"disableDownsampling"
,
true
)
query
.
Model
.
Set
(
"downsampleInterval"
,
"5m"
)
query
.
Model
.
Set
(
"downsampleAggregator"
,
"sum"
)
query
.
Model
.
Set
(
"downsampleFillPolicy"
,
"null"
)
tags
:=
simplejson
.
New
()
tags
.
Set
(
"env"
,
"prod"
)
tags
.
Set
(
"app"
,
"grafana"
)
query
.
Model
.
Set
(
"tags"
,
tags
.
MustMap
())
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
)
})
Convey
(
"Build metric with rate enabled but counter disabled"
,
func
()
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
query
.
Model
.
Set
(
"metric"
,
"cpu.average.percent"
)
query
.
Model
.
Set
(
"aggregator"
,
"avg"
)
query
.
Model
.
Set
(
"disableDownsampling"
,
true
)
query
.
Model
.
Set
(
"shouldComputeRate"
,
true
)
query
.
Model
.
Set
(
"isCounter"
,
false
)
tags
:=
simplejson
.
New
()
tags
.
Set
(
"env"
,
"prod"
)
tags
.
Set
(
"app"
,
"grafana"
)
query
.
Model
.
Set
(
"tags"
,
tags
.
MustMap
())
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
)
})
Convey
(
"Build metric with rate and counter enabled"
,
func
()
{
query
:=
&
tsdb
.
Query
{
Model
:
simplejson
.
New
(),
}
query
.
Model
.
Set
(
"metric"
,
"cpu.average.percent"
)
query
.
Model
.
Set
(
"aggregator"
,
"avg"
)
query
.
Model
.
Set
(
"disableDownsampling"
,
true
)
query
.
Model
.
Set
(
"shouldComputeRate"
,
true
)
query
.
Model
.
Set
(
"isCounter"
,
true
)
query
.
Model
.
Set
(
"counterMax"
,
45
)
query
.
Model
.
Set
(
"counterResetValue"
,
60
)
tags
:=
simplejson
.
New
()
tags
.
Set
(
"env"
,
"prod"
)
tags
.
Set
(
"app"
,
"grafana"
)
query
.
Model
.
Set
(
"tags"
,
tags
.
MustMap
())
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
)
})
})
}
\ No newline at end of file
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