Documentation
¶
Overview ¶
Package rest provides a REST API to access the features of the PromQL language server with a stateless API.
The returned datastructures are taken from the Language Server Protocol Specification (https://microsoft.github.io/language-server-protocol/specifications/specification-current/)
Supported endpoints:
/diagnostics /completion /hover /signatureHelp
URL Query Parameters:
expr : A PromQL expression. limit : (optional, only for /diagnostics and /completion endpoints) The maximum number of diagnostic messages returned. line : (only for /signatureHelp, /hover and /completion endpoints) The line (0 based) for which the metadata is queried. char : (only for /signatureHelp, /hover and /completion endpoints) The column (0 based) for which the metadata is queried. Characters are counted as UTF16 Codepoints.
Examples:
$ curl 'localhost:8080/diagnostics?expr=some_metric()&limit=100'|jq
[
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 11
}
},
"severity": 1,
"source": "promql-lsp",
"message": "unknown function with name \"some_metric\""
}
]
$ curl 'localhost:8080/completion?expr=sum(go)&line=0&char=6&limit=2'|jq
[
{
"label": "go_gc_duration_seconds",
"kind": 12,
"sortText": "__3__go_gc_duration_seconds",
"textEdit": {
"range": {
"start": {
"line": 0,
"character": 4
},
"end": {
"line": 0,
"character": 6
}
},
"newText": "go_gc_duration_seconds"
}
},
{
"label": "go_gc_duration_seconds_count",
"kind": 12,
"sortText": "__3__go_gc_duration_seconds_count",
"textEdit": {
"range": {
"start": {
"line": 0,
"character": 4
},
"end": {
"line": 0,
"character": 6
}
},
"newText": "go_gc_duration_seconds_count"
}
}
]
Try out the API:
Use the PromQL language server with a configuration file like this:
rest_api_port: 8080 prometheus_url: http://localhost:9090
Run it with:
$ promql-langserver --config-file config.yaml REST API: Listening on port 8080 Prometheus: http://localhost:9090
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateHandler ¶
func CreateHandler(ctx context.Context, prometheusClient promClient.Client, logger log.Logger) (http.Handler, error)
CreateHandler creates an http.Handler for the PromQL langserver REST API.
Expects a prometheus Client as a second argument. The provided Logger should be synchronized.
func CreateInstHandler ¶
func CreateInstHandler(ctx context.Context, prometheusClient promClient.Client, r *prometheus.Registry, logger log.Logger) (http.Handler, error)
CreateInstHandler creates an instrumented http.Handler for the PromQL langserver REST API.
Expects a prometheus Client as a second argument and a Registry as third argument. The provided Logger should be synchronized.
Types ¶
This section is empty.