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
f0a0e647
Commit
f0a0e647
authored
Nov 09, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(influxdb): backend support for alias by segment
ref #6510
parent
97271514
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletions
+23
-1
pkg/tsdb/influxdb/response_parser.go
+8
-0
pkg/tsdb/influxdb/response_parser_test.go
+15
-1
No files found.
pkg/tsdb/influxdb/response_parser.go
View file @
f0a0e647
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"regexp"
"regexp"
"strconv"
"strings"
"strings"
"github.com/grafana/grafana/pkg/tsdb"
"github.com/grafana/grafana/pkg/tsdb"
...
@@ -61,6 +62,8 @@ func (rp *ResponseParser) formatSerieName(row Row, column string, query *Query)
...
@@ -61,6 +62,8 @@ func (rp *ResponseParser) formatSerieName(row Row, column string, query *Query)
return
rp
.
buildSerieNameFromQuery
(
row
,
column
)
return
rp
.
buildSerieNameFromQuery
(
row
,
column
)
}
}
nameSegment
:=
strings
.
Split
(
row
.
Name
,
"."
)
result
:=
legendFormat
.
ReplaceAllFunc
([]
byte
(
query
.
Alias
),
func
(
in
[]
byte
)
[]
byte
{
result
:=
legendFormat
.
ReplaceAllFunc
([]
byte
(
query
.
Alias
),
func
(
in
[]
byte
)
[]
byte
{
aliasFormat
:=
string
(
in
)
aliasFormat
:=
string
(
in
)
aliasFormat
=
strings
.
Replace
(
aliasFormat
,
"[["
,
""
,
1
)
aliasFormat
=
strings
.
Replace
(
aliasFormat
,
"[["
,
""
,
1
)
...
@@ -74,6 +77,11 @@ func (rp *ResponseParser) formatSerieName(row Row, column string, query *Query)
...
@@ -74,6 +77,11 @@ func (rp *ResponseParser) formatSerieName(row Row, column string, query *Query)
return
[]
byte
(
column
)
return
[]
byte
(
column
)
}
}
pos
,
err
:=
strconv
.
Atoi
(
aliasFormat
)
if
err
==
nil
&&
len
(
nameSegment
)
>=
pos
{
return
[]
byte
(
nameSegment
[
pos
])
}
if
!
strings
.
HasPrefix
(
aliasFormat
,
"tag_"
)
{
if
!
strings
.
HasPrefix
(
aliasFormat
,
"tag_"
)
{
return
in
return
in
}
}
...
...
pkg/tsdb/influxdb/response_parser_test.go
View file @
f0a0e647
...
@@ -72,7 +72,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
...
@@ -72,7 +72,7 @@ func TestInfluxdbResponseParser(t *testing.T) {
Result
{
Result
{
Series
:
[]
Row
{
Series
:
[]
Row
{
{
{
Name
:
"cpu"
,
Name
:
"cpu
.upc
"
,
Columns
:
[]
string
{
"time"
,
"mean"
,
"sum"
},
Columns
:
[]
string
{
"time"
,
"mean"
,
"sum"
},
Tags
:
map
[
string
]
string
{
"datacenter"
:
"America"
},
Tags
:
map
[
string
]
string
{
"datacenter"
:
"America"
},
Values
:
[][]
interface
{}{
Values
:
[][]
interface
{}{
...
@@ -113,6 +113,20 @@ func TestInfluxdbResponseParser(t *testing.T) {
...
@@ -113,6 +113,20 @@ func TestInfluxdbResponseParser(t *testing.T) {
So
(
result
.
Series
[
0
]
.
Name
,
ShouldEqual
,
"alias America"
)
So
(
result
.
Series
[
0
]
.
Name
,
ShouldEqual
,
"alias America"
)
})
})
Convey
(
"segment alias"
,
func
()
{
query
:=
&
Query
{
Alias
:
"alias $1"
}
result
:=
parser
.
Parse
(
response
,
query
)
So
(
result
.
Series
[
0
]
.
Name
,
ShouldEqual
,
"alias upc"
)
})
Convey
(
"segment position out of bound"
,
func
()
{
query
:=
&
Query
{
Alias
:
"alias $5"
}
result
:=
parser
.
Parse
(
response
,
query
)
So
(
result
.
Series
[
0
]
.
Name
,
ShouldEqual
,
"alias $5"
)
})
})
})
Convey
(
"[[]] alias"
,
func
()
{
Convey
(
"[[]] alias"
,
func
()
{
...
...
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