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
481b8653
Commit
481b8653
authored
Sep 27, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: update alignment period rules according to stackdriver
parent
3c6c4565
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
2 deletions
+58
-2
pkg/tsdb/stackdriver/stackdriver.go
+4
-2
pkg/tsdb/stackdriver/stackdriver_test.go
+54
-0
No files found.
pkg/tsdb/stackdriver/stackdriver.go
View file @
481b8653
...
...
@@ -18,6 +18,7 @@ import (
"golang.org/x/net/context/ctxhttp"
"github.com/grafana/grafana/pkg/api/pluginproxy"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/components/null"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/log"
...
...
@@ -193,9 +194,10 @@ func setAggParams(params *url.Values, query *tsdb.Query, durationSeconds int) {
if
alignmentPeriod
==
"stackdriver-auto"
{
alignmentPeriodValue
:=
int
(
math
.
Max
(
float64
(
durationSeconds
),
60.0
))
if
alignmentPeriodValue
<=
60
*
60
*
5
{
logger
.
Info
(
"alignmentPeriodValue"
,
"alignmentPeriodValue"
,
alignmentPeriodValue
)
if
alignmentPeriodValue
<
60
*
60
*
23
{
alignmentPeriod
=
"+60s"
}
else
if
alignmentPeriodValue
<
=
60
*
60
*
23
{
}
else
if
alignmentPeriodValue
<
60
*
60
*
24
*
6
{
alignmentPeriod
=
"+300s"
}
else
{
alignmentPeriod
=
"+3600s"
...
...
pkg/tsdb/stackdriver/stackdriver_test.go
View file @
481b8653
...
...
@@ -94,6 +94,60 @@ func TestStackdriver(t *testing.T) {
})
})
Convey
(
"and alignmentPeriod is set to stackdriver-auto"
,
func
()
{
Convey
(
"and range is two hours"
,
func
()
{
tsdbQuery
.
TimeRange
.
From
=
"1538033322461"
tsdbQuery
.
TimeRange
.
To
=
"1538040522461"
tsdbQuery
.
Queries
[
0
]
.
Model
=
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"target"
:
"target"
,
"alignmentPeriod"
:
"stackdriver-auto"
,
})
queries
,
err
:=
executor
.
buildQueries
(
tsdbQuery
)
So
(
err
,
ShouldBeNil
)
So
(
queries
[
0
]
.
Params
[
"aggregation.alignmentPeriod"
][
0
],
ShouldEqual
,
`+60s`
)
})
Convey
(
"and range is 22 hours"
,
func
()
{
tsdbQuery
.
TimeRange
.
From
=
"1538034524922"
tsdbQuery
.
TimeRange
.
To
=
"1538113724922"
tsdbQuery
.
Queries
[
0
]
.
Model
=
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"target"
:
"target"
,
"alignmentPeriod"
:
"stackdriver-auto"
,
})
queries
,
err
:=
executor
.
buildQueries
(
tsdbQuery
)
So
(
err
,
ShouldBeNil
)
So
(
queries
[
0
]
.
Params
[
"aggregation.alignmentPeriod"
][
0
],
ShouldEqual
,
`+60s`
)
})
Convey
(
"and range is 23 hours"
,
func
()
{
tsdbQuery
.
TimeRange
.
From
=
"1538034567985"
tsdbQuery
.
TimeRange
.
To
=
"1538117367985"
tsdbQuery
.
Queries
[
0
]
.
Model
=
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"target"
:
"target"
,
"alignmentPeriod"
:
"stackdriver-auto"
,
})
queries
,
err
:=
executor
.
buildQueries
(
tsdbQuery
)
So
(
err
,
ShouldBeNil
)
So
(
queries
[
0
]
.
Params
[
"aggregation.alignmentPeriod"
][
0
],
ShouldEqual
,
`+300s`
)
})
Convey
(
"and range is 7 days"
,
func
()
{
tsdbQuery
.
TimeRange
.
From
=
"1538036324073"
tsdbQuery
.
TimeRange
.
To
=
"1538641124073"
tsdbQuery
.
Queries
[
0
]
.
Model
=
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"target"
:
"target"
,
"alignmentPeriod"
:
"stackdriver-auto"
,
})
queries
,
err
:=
executor
.
buildQueries
(
tsdbQuery
)
So
(
err
,
ShouldBeNil
)
So
(
queries
[
0
]
.
Params
[
"aggregation.alignmentPeriod"
][
0
],
ShouldEqual
,
`+3600s`
)
})
})
Convey
(
"and alignmentPeriod is set in frontend"
,
func
()
{
Convey
(
"and alignment period is too big"
,
func
()
{
tsdbQuery
.
Queries
[
0
]
.
IntervalMs
=
1000
...
...
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