Commit 1c8c7469 by Alexander Zobnin

code-editor: prometheus metrics autocomplete

parent aa670244
...@@ -125,6 +125,23 @@ function link(scope, elem, attrs) { ...@@ -125,6 +125,23 @@ function link(scope, elem, attrs) {
} }
}); });
let extCompleter = {
getCompletions: getExtCompletions
};
function getExtCompletions(editor, session, pos, prefix, callback) {
scope.getMetrics(prefix).then(results => {
let wordList = results;
callback(null, wordList.map(word => {
return {
caption: word,
value: word,
meta: "metric"
};
}));
});
}
function setLangMode(lang) { function setLangMode(lang) {
let aceModeName = `ace/mode/${lang}`; let aceModeName = `ace/mode/${lang}`;
fixModuleUrl("mode", lang); fixModuleUrl("mode", lang);
...@@ -136,6 +153,7 @@ function link(scope, elem, attrs) { ...@@ -136,6 +153,7 @@ function link(scope, elem, attrs) {
enableLiveAutocompletion: true, enableLiveAutocompletion: true,
enableSnippets: true enableSnippets: true
}); });
codeEditor.completers.push(extCompleter);
}); });
} }
...@@ -157,7 +175,8 @@ export function codeEditorDirective() { ...@@ -157,7 +175,8 @@ export function codeEditorDirective() {
template: editorTemplate, template: editorTemplate,
scope: { scope: {
content: "=", content: "=",
onChange: "&" onChange: "&",
getMetrics: "="
}, },
link: link link: link
}; };
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
<div class="gf-form-inline"> <div class="gf-form-inline">
<div class="gf-form gf-form--grow"> <div class="gf-form gf-form--grow">
<code-editor content="ctrl.target.expr" on-change="ctrl.refreshMetricData()" data-mode="prometheus"></code-editor> <code-editor content="ctrl.target.expr" on-change="ctrl.refreshMetricData()"
get-metrics="ctrl.getMetricsAutocomplete" data-mode="prometheus">
</code-editor>
</div> </div>
</div> </div>
......
...@@ -15,6 +15,7 @@ class PrometheusQueryCtrl extends QueryCtrl { ...@@ -15,6 +15,7 @@ class PrometheusQueryCtrl extends QueryCtrl {
formats: any; formats: any;
oldTarget: any; oldTarget: any;
suggestMetrics: any; suggestMetrics: any;
getMetricsAutocomplete: any;
linkToPrometheus: any; linkToPrometheus: any;
/** @ngInject */ /** @ngInject */
...@@ -51,6 +52,10 @@ class PrometheusQueryCtrl extends QueryCtrl { ...@@ -51,6 +52,10 @@ class PrometheusQueryCtrl extends QueryCtrl {
this.datasource.performSuggestQuery(query).then(callback); this.datasource.performSuggestQuery(query).then(callback);
}; };
this.getMetricsAutocomplete = (query) => {
return this.datasource.performSuggestQuery(query);
};
this.updateLink(); this.updateLink();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment