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
71545320
Commit
71545320
authored
Apr 14, 2017
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make sure graphite queries containing references are properly updated
parent
aa47b9bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
17 deletions
+43
-17
public/app/plugins/datasource/graphite/partials/query.editor.html
+1
-1
public/app/plugins/datasource/graphite/query_ctrl.ts
+42
-16
No files found.
public/app/plugins/datasource/graphite/partials/query.editor.html
View file @
71545320
<query-editor-row
query-ctrl=
"ctrl"
has-text-edit-mode=
"true"
>
<div
class=
"gf-form"
ng-show=
"ctrl.target.textEditor"
>
<input
type=
"text"
class=
"gf-form-input"
ng-model=
"ctrl.target.target"
spellcheck=
"false"
ng-blur=
"ctrl.
refresh
()"
></input>
<input
type=
"text"
class=
"gf-form-input"
ng-model=
"ctrl.target.target"
spellcheck=
"false"
ng-blur=
"ctrl.
targetTextChanged
()"
></input>
</div>
<div
ng-hide=
"ctrl.target.textEditor"
>
...
...
public/app/plugins/datasource/graphite/query_ctrl.ts
View file @
71545320
...
...
@@ -55,7 +55,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
}
try
{
this
.
parseTargeRecursive
(
astNode
,
null
,
0
);
this
.
parseTarge
t
Recursive
(
astNode
,
null
,
0
);
}
catch
(
err
)
{
console
.
log
(
'error parsing target:'
,
err
.
message
);
this
.
error
=
err
.
message
;
...
...
@@ -72,7 +72,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
func
.
params
[
index
]
=
value
;
}
parseTargeRecursive
(
astNode
,
func
,
index
)
{
parseTarge
t
Recursive
(
astNode
,
func
,
index
)
{
if
(
astNode
===
null
)
{
return
null
;
}
...
...
@@ -81,7 +81,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
case
'function'
:
var
innerFunc
=
gfunc
.
createFuncInstance
(
astNode
.
name
,
{
withDefaultParams
:
false
});
_
.
each
(
astNode
.
params
,
(
param
,
index
)
=>
{
this
.
parseTargeRecursive
(
param
,
innerFunc
,
index
);
this
.
parseTarge
t
Recursive
(
param
,
innerFunc
,
index
);
});
innerFunc
.
updateText
();
...
...
@@ -209,30 +209,56 @@ export class GraphiteQueryCtrl extends QueryCtrl {
}
targetTextChanged
()
{
this
.
parse
Target
();
this
.
panelCtrl
.
refresh
();
this
.
updateModel
Target
();
this
.
refresh
();
}
updateModelTarget
()
{
// render query
var
metricPath
=
this
.
getSegmentPathUpTo
(
this
.
segments
.
length
);
this
.
target
.
target
=
_
.
reduce
(
this
.
functions
,
this
.
wrapFunction
,
metricPath
);
if
(
!
this
.
target
.
textEditor
)
{
var
metricPath
=
this
.
getSegmentPathUpTo
(
this
.
segments
.
length
);
this
.
target
.
target
=
_
.
reduce
(
this
.
functions
,
this
.
wrapFunction
,
metricPath
);
}
// loop through queries and update targetFull as needed
for
(
const
target
of
this
.
panelCtrl
.
panel
.
targets
)
{
this
.
resolveTarget
(
target
);
}
}
resolveTarget
(
target
)
{
// render nested query
var
targetsByRefId
=
_
.
keyBy
(
this
.
panelCtrl
.
panel
.
targets
,
'refId'
);
// no references to self
delete
targetsByRefId
[
target
.
refId
];
var
nestedSeriesRefRegex
=
/
\#([
A-Z
])
/g
;
var
targetWithNestedQueries
=
this
.
target
.
target
.
replace
(
nestedSeriesRefRegex
,
(
match
,
g1
)
=>
{
var
target
=
targetsByRefId
[
g1
];
if
(
!
target
)
{
return
match
;
var
targetWithNestedQueries
=
target
.
target
;
while
(
targetWithNestedQueries
.
match
(
nestedSeriesRefRegex
))
{
var
updated
=
targetWithNestedQueries
.
replace
(
nestedSeriesRefRegex
,
(
match
,
g1
)
=>
{
var
t
=
targetsByRefId
[
g1
];
if
(
!
t
)
{
return
match
;
}
// no circular references
delete
targetsByRefId
[
g1
];
return
t
.
target
;
});
if
(
updated
===
targetWithNestedQueries
)
{
break
;
}
return
target
.
targetFull
||
target
.
target
;
}
);
targetWithNestedQueries
=
updated
;
}
delete
t
his
.
t
arget
.
targetFull
;
if
(
t
his
.
t
arget
.
target
!==
targetWithNestedQueries
)
{
t
his
.
t
arget
.
targetFull
=
targetWithNestedQueries
;
delete
target
.
targetFull
;
if
(
target
.
target
!==
targetWithNestedQueries
)
{
target
.
targetFull
=
targetWithNestedQueries
;
}
}
...
...
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