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
885e0366
Commit
885e0366
authored
Oct 11, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(influxdb): support raw queries in alerting
ref #6231
parent
ccee1b3f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
0 deletions
+83
-0
pkg/tsdb/influxdb/model_parser.go
+2
-0
pkg/tsdb/influxdb/model_parser_test.go
+56
-0
pkg/tsdb/influxdb/models.go
+1
-0
pkg/tsdb/influxdb/query_builder.go
+9
-0
pkg/tsdb/influxdb/query_builder_test.go
+15
-0
No files found.
pkg/tsdb/influxdb/model_parser.go
View file @
885e0366
...
@@ -10,6 +10,7 @@ type InfluxdbQueryParser struct{}
...
@@ -10,6 +10,7 @@ type InfluxdbQueryParser struct{}
func
(
qp
*
InfluxdbQueryParser
)
Parse
(
model
*
simplejson
.
Json
)
(
*
Query
,
error
)
{
func
(
qp
*
InfluxdbQueryParser
)
Parse
(
model
*
simplejson
.
Json
)
(
*
Query
,
error
)
{
policy
:=
model
.
Get
(
"policy"
)
.
MustString
(
"default"
)
policy
:=
model
.
Get
(
"policy"
)
.
MustString
(
"default"
)
rawQuery
:=
model
.
Get
(
"query"
)
.
MustString
(
""
)
measurement
,
err
:=
model
.
Get
(
"measurement"
)
.
String
()
measurement
,
err
:=
model
.
Get
(
"measurement"
)
.
String
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -43,6 +44,7 @@ func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json) (*Query, error) {
...
@@ -43,6 +44,7 @@ func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json) (*Query, error) {
GroupBy
:
groupBys
,
GroupBy
:
groupBys
,
Tags
:
tags
,
Tags
:
tags
,
Selects
:
selects
,
Selects
:
selects
,
RawQuery
:
rawQuery
,
},
nil
},
nil
}
}
...
...
pkg/tsdb/influxdb/model_parser_test.go
View file @
885e0366
...
@@ -111,5 +111,61 @@ func TestInfluxdbQueryParser(t *testing.T) {
...
@@ -111,5 +111,61 @@ func TestInfluxdbQueryParser(t *testing.T) {
So
(
len
(
res
.
Selects
),
ShouldEqual
,
3
)
So
(
len
(
res
.
Selects
),
ShouldEqual
,
3
)
So
(
len
(
res
.
Tags
),
ShouldEqual
,
2
)
So
(
len
(
res
.
Tags
),
ShouldEqual
,
2
)
})
})
Convey
(
"can part raw query json model"
,
func
()
{
json
:=
`
{
"dsType": "influxdb",
"groupBy": [
{
"params": [
"$interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"policy": "default",
"query": "RawDummieQuery",
"rawQuery": true,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [
],
"type": "mean"
}
]
],
"tags": [
]
}
`
modelJson
,
err
:=
simplejson
.
NewJson
([]
byte
(
json
))
So
(
err
,
ShouldBeNil
)
res
,
err
:=
parser
.
Parse
(
modelJson
)
So
(
err
,
ShouldBeNil
)
So
(
res
.
RawQuery
,
ShouldEqual
,
"RawDummieQuery"
)
So
(
len
(
res
.
GroupBy
),
ShouldEqual
,
2
)
So
(
len
(
res
.
Selects
),
ShouldEqual
,
2
)
So
(
len
(
res
.
Tags
),
ShouldEqual
,
0
)
})
})
})
}
}
pkg/tsdb/influxdb/models.go
View file @
885e0366
...
@@ -7,6 +7,7 @@ type Query struct {
...
@@ -7,6 +7,7 @@ type Query struct {
Tags
[]
*
Tag
Tags
[]
*
Tag
GroupBy
[]
*
QueryPart
GroupBy
[]
*
QueryPart
Selects
[]
*
Select
Selects
[]
*
Select
RawQuery
string
Interval
string
Interval
string
}
}
...
...
pkg/tsdb/influxdb/query_builder.go
View file @
885e0366
...
@@ -10,6 +10,15 @@ import (
...
@@ -10,6 +10,15 @@ import (
type
QueryBuilder
struct
{}
type
QueryBuilder
struct
{}
func
(
qb
*
QueryBuilder
)
Build
(
query
*
Query
,
queryContext
*
tsdb
.
QueryContext
)
(
string
,
error
)
{
func
(
qb
*
QueryBuilder
)
Build
(
query
*
Query
,
queryContext
*
tsdb
.
QueryContext
)
(
string
,
error
)
{
if
query
.
RawQuery
!=
""
{
q
:=
query
.
RawQuery
q
=
strings
.
Replace
(
q
,
"$timeFilter"
,
qb
.
renderTimeFilter
(
query
,
queryContext
),
1
)
q
=
strings
.
Replace
(
q
,
"$interval"
,
tsdb
.
CalculateInterval
(
queryContext
.
TimeRange
),
1
)
return
q
,
nil
}
res
:=
qb
.
renderSelectors
(
query
,
queryContext
)
res
:=
qb
.
renderSelectors
(
query
,
queryContext
)
res
+=
qb
.
renderMeasurement
(
query
)
res
+=
qb
.
renderMeasurement
(
query
)
res
+=
qb
.
renderWhereClause
(
query
)
res
+=
qb
.
renderWhereClause
(
query
)
...
...
pkg/tsdb/influxdb/query_builder_test.go
View file @
885e0366
...
@@ -68,5 +68,20 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
...
@@ -68,5 +68,20 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
So
(
builder
.
renderTimeFilter
(
&
query
,
queryContext
),
ShouldEqual
,
"time > now() - 10m"
)
So
(
builder
.
renderTimeFilter
(
&
query
,
queryContext
),
ShouldEqual
,
"time > now() - 10m"
)
})
})
})
})
Convey
(
"can build query from raw query"
,
func
()
{
query
:=
&
Query
{
Selects
:
[]
*
Select
{{
*
qp1
,
*
qp2
}},
Measurement
:
"cpu"
,
Policy
:
"policy"
,
GroupBy
:
[]
*
QueryPart
{
groupBy1
,
groupBy3
},
Interval
:
"10s"
,
RawQuery
:
"Raw query"
,
}
rawQuery
,
err
:=
builder
.
Build
(
query
,
queryContext
)
So
(
err
,
ShouldBeNil
)
So
(
rawQuery
,
ShouldEqual
,
`Raw query`
)
})
})
})
}
}
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