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
ee0f1a0f
Commit
ee0f1a0f
authored
Sep 21, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(prometheus): handle more errors
parent
3e73be8d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
pkg/tsdb/prometheus/prometheus.go
+18
-10
pkg/tsdb/prometheus/types.go
+2
-0
No files found.
pkg/tsdb/prometheus/prometheus.go
View file @
ee0f1a0f
...
...
@@ -52,18 +52,14 @@ func (e *PrometheusExecutor) Execute(queries tsdb.QuerySlice, queryContext *tsdb
return
resultWithError
(
result
,
err
)
}
from
,
_
:=
queryContext
.
TimeRange
.
FromTime
()
to
,
_
:=
queryContext
.
TimeRange
.
ToTime
()
query
,
err
:=
parseQuery
(
queries
)
query
,
err
:=
parseQuery
(
queries
,
queryContext
)
if
err
!=
nil
{
return
resultWithError
(
result
,
err
)
}
timeRange
:=
prometheus
.
Range
{
Start
:
from
,
End
:
to
,
Start
:
query
.
Start
,
End
:
query
.
End
,
Step
:
query
.
Step
,
}
...
...
@@ -78,9 +74,9 @@ func (e *PrometheusExecutor) Execute(queries tsdb.QuerySlice, queryContext *tsdb
}
func
formatLegend
(
metric
pmodel
.
Metric
,
query
*
PrometheusQuery
)
string
{
r
,
_
:=
regexp
.
Compile
(
`\{\{\s*(.+?)\s*\}\}`
)
r
eg
,
_
:=
regexp
.
Compile
(
`\{\{\s*(.+?)\s*\}\}`
)
result
:=
r
.
ReplaceAllFunc
([]
byte
(
query
.
LegendFormat
),
func
(
in
[]
byte
)
[]
byte
{
result
:=
r
eg
.
ReplaceAllFunc
([]
byte
(
query
.
LegendFormat
),
func
(
in
[]
byte
)
[]
byte
{
ind
:=
strings
.
Replace
(
strings
.
Replace
(
string
(
in
),
"{{"
,
""
,
1
),
"}}"
,
""
,
1
)
if
val
,
exists
:=
metric
[
pmodel
.
LabelName
(
ind
)];
exists
{
return
[]
byte
(
val
)
...
...
@@ -92,7 +88,7 @@ func formatLegend(metric pmodel.Metric, query *PrometheusQuery) string {
return
string
(
result
)
}
func
parseQuery
(
queries
tsdb
.
QuerySlice
)
(
*
PrometheusQuery
,
error
)
{
func
parseQuery
(
queries
tsdb
.
QuerySlice
,
queryContext
*
tsdb
.
QueryContext
)
(
*
PrometheusQuery
,
error
)
{
queryModel
:=
queries
[
0
]
expr
,
err
:=
queryModel
.
Model
.
Get
(
"expr"
)
.
String
()
...
...
@@ -110,10 +106,22 @@ func parseQuery(queries tsdb.QuerySlice) (*PrometheusQuery, error) {
return
nil
,
err
}
start
,
err
:=
queryContext
.
TimeRange
.
FromTime
()
if
err
!=
nil
{
return
nil
,
err
}
end
,
err
:=
queryContext
.
TimeRange
.
ToTime
()
if
err
!=
nil
{
return
nil
,
err
}
return
&
PrometheusQuery
{
Expr
:
expr
,
Step
:
time
.
Second
*
time
.
Duration
(
step
),
LegendFormat
:
format
,
Start
:
start
,
End
:
end
,
},
nil
}
...
...
pkg/tsdb/prometheus/types.go
View file @
ee0f1a0f
...
...
@@ -6,4 +6,6 @@ type PrometheusQuery struct {
Expr
string
Step
time
.
Duration
LegendFormat
string
Start
time
.
Time
End
time
.
Time
}
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