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
1afe0e90
Commit
1afe0e90
authored
Nov 03, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(tsdb): fixes broken legend buidler for prometheus
closes #6456
parent
0059beb8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
pkg/tsdb/prometheus/prometheus.go
+5
-4
pkg/tsdb/prometheus/prometheus_test.go
+13
-0
No files found.
pkg/tsdb/prometheus/prometheus.go
View file @
1afe0e90
...
...
@@ -81,6 +81,10 @@ func (e *PrometheusExecutor) Execute(ctx context.Context, queries tsdb.QuerySlic
func
formatLegend
(
metric
pmodel
.
Metric
,
query
*
PrometheusQuery
)
string
{
reg
,
_
:=
regexp
.
Compile
(
`\{\{\s*(.+?)\s*\}\}`
)
if
query
.
LegendFormat
==
""
{
return
metric
.
String
()
}
result
:=
reg
.
ReplaceAllFunc
([]
byte
(
query
.
LegendFormat
),
func
(
in
[]
byte
)
[]
byte
{
labelName
:=
strings
.
Replace
(
string
(
in
),
"{{"
,
""
,
1
)
labelName
=
strings
.
Replace
(
labelName
,
"}}"
,
""
,
1
)
...
...
@@ -108,10 +112,7 @@ func parseQuery(queries tsdb.QuerySlice, queryContext *tsdb.QueryContext) (*Prom
return
nil
,
err
}
format
,
err
:=
queryModel
.
Model
.
Get
(
"legendFormat"
)
.
String
()
if
err
!=
nil
{
return
nil
,
err
}
format
:=
queryModel
.
Model
.
Get
(
"legendFormat"
)
.
MustString
(
""
)
start
,
err
:=
queryContext
.
TimeRange
.
ParseFrom
()
if
err
!=
nil
{
...
...
pkg/tsdb/prometheus/prometheus_test.go
View file @
1afe0e90
...
...
@@ -22,5 +22,18 @@ func TestPrometheus(t *testing.T) {
So
(
formatLegend
(
metric
,
query
),
ShouldEqual
,
"legend backend mobile {{broken}}"
)
})
Convey
(
"build full serie name"
,
func
()
{
metric
:=
map
[
p
.
LabelName
]
p
.
LabelValue
{
p
.
LabelName
(
"app"
)
:
p
.
LabelValue
(
"backend"
),
p
.
LabelName
(
"device"
)
:
p
.
LabelValue
(
"mobile"
),
}
query
:=
&
PrometheusQuery
{
LegendFormat
:
""
,
}
So
(
formatLegend
(
metric
,
query
),
ShouldEqual
,
`http_request_total{app="backend", device="mobile"}`
)
})
})
}
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