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
c62b0858
Unverified
Commit
c62b0858
authored
Jan 16, 2018
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move graphite /functions parsing into gfunc.ts
parent
50ffe56b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
89 deletions
+96
-89
public/app/plugins/datasource/graphite/datasource.ts
+1
-89
public/app/plugins/datasource/graphite/gfunc.ts
+95
-0
No files found.
public/app/plugins/datasource/graphite/datasource.ts
View file @
c62b0858
...
...
@@ -436,97 +436,9 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
.
then
(
results
=>
{
if
(
results
.
status
!==
200
||
typeof
results
.
data
!==
'object'
)
{
this
.
funcDefs
=
gfunc
.
getFuncDefs
(
this
.
graphiteVersion
);
return
Promise
.
resolve
(
this
.
funcDefs
);
}
this
.
funcDefs
=
{};
_
.
forEach
(
results
.
data
||
{},
(
funcDef
,
funcName
)
=>
{
// skip graphite graph functions
if
(
funcDef
.
group
===
'Graph'
)
{
return
;
}
var
description
=
funcDef
.
description
;
if
(
description
)
{
// tidy up some pydoc syntax that rst2html can't handle
description
=
description
.
replace
(
/:py:func:`
(
.+
)(
<
[^
>
]
*>
)?
`/g
,
'``$1``'
)
.
replace
(
/.. seealso:: /g
,
'See also: '
)
.
replace
(
/.. code-block *:: *none/g
,
'.. code-block::'
);
}
var
func
=
{
name
:
funcDef
.
name
,
description
:
description
,
category
:
funcDef
.
group
,
params
:
[],
defaultParams
:
[],
fake
:
false
,
};
// get rid of the first "seriesList" param
if
(
/^seriesLists
?
$/
.
test
(
_
.
get
(
funcDef
,
'params[0].type'
,
''
)))
{
// handle functions that accept multiple seriesLists
// we leave the param in place but mark it optional, so users can add more series if they wish
if
(
funcDef
.
params
[
0
].
multiple
)
{
funcDef
.
params
[
0
].
required
=
false
;
// otherwise chop off the first param, it'll be handled separately
}
else
{
funcDef
.
params
.
shift
(
);
this
.
funcDefs
=
gfunc
.
parseFuncDefs
(
results
.
data
);
}
// tag function as fake
}
else
{
func
.
fake
=
true
;
}
_
.
forEach
(
funcDef
.
params
,
rawParam
=>
{
var
param
=
{
name
:
rawParam
.
name
,
type
:
'string'
,
optional
:
!
rawParam
.
required
,
multiple
:
!!
rawParam
.
multiple
,
options
:
undefined
,
};
if
(
rawParam
.
default
!==
undefined
)
{
func
.
defaultParams
.
push
(
_
.
toString
(
rawParam
.
default
));
}
else
if
(
rawParam
.
suggestions
)
{
func
.
defaultParams
.
push
(
_
.
toString
(
rawParam
.
suggestions
[
0
]));
}
else
{
func
.
defaultParams
.
push
(
''
);
}
if
(
rawParam
.
type
===
'boolean'
)
{
param
.
type
=
'boolean'
;
param
.
options
=
[
'true'
,
'false'
];
}
else
if
(
rawParam
.
type
===
'integer'
)
{
param
.
type
=
'int'
;
}
else
if
(
rawParam
.
type
===
'float'
)
{
param
.
type
=
'float'
;
}
else
if
(
rawParam
.
type
===
'node'
)
{
param
.
type
=
'node'
;
param
.
options
=
[
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'10'
,
'11'
,
'12'
];
}
else
if
(
rawParam
.
type
===
'nodeOrTag'
)
{
param
.
type
=
'node_or_tag'
;
param
.
options
=
[
'name'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'10'
,
'11'
,
'12'
];
}
else
if
(
rawParam
.
type
===
'intOrInterval'
)
{
param
.
type
=
'int_or_interval'
;
}
else
if
(
rawParam
.
type
===
'seriesList'
)
{
param
.
type
=
'value_or_series'
;
}
if
(
rawParam
.
options
)
{
param
.
options
=
_
.
map
(
rawParam
.
options
,
_
.
toString
);
}
else
if
(
rawParam
.
suggestions
)
{
param
.
options
=
_
.
map
(
rawParam
.
suggestions
,
_
.
toString
);
}
func
.
params
.
push
(
param
);
});
this
.
funcDefs
[
funcName
]
=
func
;
});
return
this
.
funcDefs
;
})
.
catch
(
err
=>
{
...
...
public/app/plugins/datasource/graphite/gfunc.ts
View file @
c62b0858
...
...
@@ -1077,8 +1077,103 @@ function getFuncDefs(graphiteVersion, idx?) {
return
funcs
;
}
// parse response from graphite /functions endpoint into internal format
function
parseFuncDefs
(
rawDefs
)
{
var
funcDefs
=
{};
_
.
forEach
(
rawDefs
||
{},
(
funcDef
,
funcName
)
=>
{
// skip graphite graph functions
if
(
funcDef
.
group
===
'Graph'
)
{
return
;
}
var
description
=
funcDef
.
description
;
if
(
description
)
{
// tidy up some pydoc syntax that rst2html can't handle
description
=
description
.
replace
(
/:py:func:`
(
.+
)(
<
[^
>
]
*>
)?
`/g
,
'``$1``'
)
.
replace
(
/.. seealso:: /g
,
'See also: '
)
.
replace
(
/.. code-block *:: *none/g
,
'.. code-block::'
);
}
var
func
=
{
name
:
funcDef
.
name
,
description
:
description
,
category
:
funcDef
.
group
,
params
:
[],
defaultParams
:
[],
fake
:
false
,
};
// get rid of the first "seriesList" param
if
(
/^seriesLists
?
$/
.
test
(
_
.
get
(
funcDef
,
'params[0].type'
,
''
)))
{
// handle functions that accept multiple seriesLists
// we leave the param in place but mark it optional, so users can add more series if they wish
if
(
funcDef
.
params
[
0
].
multiple
)
{
funcDef
.
params
[
0
].
required
=
false
;
// otherwise chop off the first param, it'll be handled separately
}
else
{
funcDef
.
params
.
shift
();
}
// tag function as fake
}
else
{
func
.
fake
=
true
;
}
_
.
forEach
(
funcDef
.
params
,
rawParam
=>
{
var
param
=
{
name
:
rawParam
.
name
,
type
:
'string'
,
optional
:
!
rawParam
.
required
,
multiple
:
!!
rawParam
.
multiple
,
options
:
undefined
,
};
if
(
rawParam
.
default
!==
undefined
)
{
func
.
defaultParams
.
push
(
_
.
toString
(
rawParam
.
default
));
}
else
if
(
rawParam
.
suggestions
)
{
func
.
defaultParams
.
push
(
_
.
toString
(
rawParam
.
suggestions
[
0
]));
}
else
{
func
.
defaultParams
.
push
(
''
);
}
if
(
rawParam
.
type
===
'boolean'
)
{
param
.
type
=
'boolean'
;
param
.
options
=
[
'true'
,
'false'
];
}
else
if
(
rawParam
.
type
===
'integer'
)
{
param
.
type
=
'int'
;
}
else
if
(
rawParam
.
type
===
'float'
)
{
param
.
type
=
'float'
;
}
else
if
(
rawParam
.
type
===
'node'
)
{
param
.
type
=
'node'
;
param
.
options
=
[
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'10'
,
'11'
,
'12'
];
}
else
if
(
rawParam
.
type
===
'nodeOrTag'
)
{
param
.
type
=
'node_or_tag'
;
param
.
options
=
[
'name'
,
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'10'
,
'11'
,
'12'
];
}
else
if
(
rawParam
.
type
===
'intOrInterval'
)
{
param
.
type
=
'int_or_interval'
;
}
else
if
(
rawParam
.
type
===
'seriesList'
)
{
param
.
type
=
'value_or_series'
;
}
if
(
rawParam
.
options
)
{
param
.
options
=
_
.
map
(
rawParam
.
options
,
_
.
toString
);
}
else
if
(
rawParam
.
suggestions
)
{
param
.
options
=
_
.
map
(
rawParam
.
suggestions
,
_
.
toString
);
}
func
.
params
.
push
(
param
);
});
funcDefs
[
funcName
]
=
func
;
});
return
funcDefs
;
}
export
default
{
createFuncInstance
:
createFuncInstance
,
getFuncDef
:
getFuncDef
,
getFuncDefs
:
getFuncDefs
,
parseFuncDefs
:
parseFuncDefs
,
};
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