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
df3adbc0
Commit
df3adbc0
authored
Dec 16, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(mqe): reduce duplication
parent
830bf5a9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
43 deletions
+34
-43
pkg/tsdb/mqe/types.go
+34
-43
No files found.
pkg/tsdb/mqe/types.go
View file @
df3adbc0
...
...
@@ -42,63 +42,54 @@ func (q *Query) Build(availableSeries []string) ([]QueryToSend, error) {
where
:=
q
.
buildWhereClause
()
functions
:=
q
.
buildFunctionList
()
for
_
,
v
:=
range
q
.
Metrics
{
if
!
containsWildcardPattern
.
Match
([]
byte
(
v
.
Metric
))
{
alias
:=
""
if
v
.
Alias
!=
""
{
alias
=
fmt
.
Sprintf
(
" {%s}"
,
v
.
Alias
)
}
for
_
,
metric
:=
range
q
.
Metrics
{
alias
:=
""
if
metric
.
Alias
!=
""
{
alias
=
fmt
.
Sprintf
(
" {%s}"
,
metric
.
Alias
)
}
rawQuery
:=
fmt
.
Sprintf
(
"`%s`%s%s %s from %v to %v"
,
v
.
Metric
,
functions
,
alias
,
where
,
q
.
TimeRange
.
GetFromAsMsEpoch
(),
q
.
TimeRange
.
GetToAsMsEpoch
())
if
!
containsWildcardPattern
.
Match
([]
byte
(
metric
.
Metric
))
{
rawQuery
:=
q
.
renderQuerystring
(
metric
.
Metric
,
functions
,
alias
,
where
,
q
.
TimeRange
)
queriesToSend
=
append
(
queriesToSend
,
QueryToSend
{
RawQuery
:
rawQuery
,
QueryRef
:
q
,
})
continue
}
}
else
{
m
:=
strings
.
Replace
(
metric
.
Metric
,
"*"
,
".*"
,
-
1
)
mp
,
err
:=
regexp
.
Compile
(
m
)
m
:=
strings
.
Replace
(
v
.
Metric
,
"*"
,
".*"
,
-
1
)
mp
,
err
:=
regexp
.
Compile
(
m
)
if
err
!=
nil
{
log
.
Error2
(
"failed to compile regex for "
,
"metric"
,
m
)
continue
}
if
err
!=
nil
{
log
.
Error2
(
"failed to compile regex for "
,
"metric"
,
m
)
continue
}
//TODO: this lookup should be cached
for
_
,
a
:=
range
availableSeries
{
if
mp
.
Match
([]
byte
(
a
))
{
alias
:=
""
if
v
.
Alias
!=
""
{
alias
=
fmt
.
Sprintf
(
" {%s}"
,
v
.
Alias
)
//TODO: this lookup should be cached
for
_
,
wildcardMatch
:=
range
availableSeries
{
if
mp
.
Match
([]
byte
(
wildcardMatch
))
{
rawQuery
:=
q
.
renderQuerystring
(
wildcardMatch
,
functions
,
alias
,
where
,
q
.
TimeRange
)
queriesToSend
=
append
(
queriesToSend
,
QueryToSend
{
RawQuery
:
rawQuery
,
QueryRef
:
q
,
})
}
rawQuery
:=
fmt
.
Sprintf
(
"`%s`%s%s %s from %v to %v"
,
a
,
functions
,
alias
,
where
,
q
.
TimeRange
.
GetFromAsMsEpoch
(),
q
.
TimeRange
.
GetToAsMsEpoch
())
queriesToSend
=
append
(
queriesToSend
,
QueryToSend
{
RawQuery
:
rawQuery
,
QueryRef
:
q
,
})
}
}
}
return
queriesToSend
,
nil
}
func
(
q
*
Query
)
renderQuerystring
(
path
,
functions
,
alias
,
where
string
,
timerange
*
tsdb
.
TimeRange
)
string
{
return
fmt
.
Sprintf
(
"`%s`%s%s %s from %v to %v"
,
path
,
functions
,
alias
,
where
,
q
.
TimeRange
.
GetFromAsMsEpoch
(),
q
.
TimeRange
.
GetToAsMsEpoch
())
}
func
(
q
*
Query
)
buildFunctionList
()
string
{
functions
:=
""
for
_
,
v
:=
range
q
.
FunctionList
{
...
...
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