Skip to content

Commit 952d8a3

Browse files
committed
complete documentation
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
1 parent abf7abb commit 952d8a3

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

rest/api.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ type API struct {
7979
enableMetrics bool
8080
}
8181

82+
// NewLangServerAPI create a new instance of the Stateless API to use the LangServer through HTTP.
83+
//
84+
// If metadata is fetched from a remote Prometheus, the metadataService
85+
// implementation from the promql-langserver/prometheus package can be used,
86+
// otherwise you need to provide your own implementation of the interface.
87+
//
88+
// The provided Logger should be synchronized.
89+
//
90+
// In case "enableMetrics" is set to true, endpoint /metrics is then available and a middleware that instrument the different endpoints provided is instantiated.
91+
// Don't use it in case you have already in place such middleware.
8292
func NewLangServerAPI(ctx context.Context, metadataService promClient.MetadataService, logger log.Logger, enableMetrics bool) (*API, error) {
8393
lgs, err := langserver.CreateHeadlessServer(ctx, metadataService, logger)
8494
if err != nil {

rest/doc.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ Supported endpoints:
2323
/hover
2424
/signatureHelp
2525
26-
URL Query Parameters:
26+
All endpoint are only available through the HTTP method POST. For each request, you have to provide the following JSON:
2727
28-
expr : A PromQL expression.
29-
limit : (optional, only for /diagnostics and /completion endpoints) The maximum number of diagnostic messages returned.
30-
line : (only for /signatureHelp, /hover and /completion endpoints) The line (0 based) for which the metadata is queried.
31-
char : (only for /signatureHelp, /hover and /completion endpoints) The column (0 based) for which the metadata is queried. Characters are counted as UTF16 Codepoints.
28+
{
29+
"expr": "a promQL expression" # Mandatory for all available endpoint
30+
"limit": 45 # Optional. It will be used only for the endpoint /diagnostics and /completion. It's the maximum number of result returned.
31+
"positionLine": 0 # Mandatory for the endpoints /signatureHelp, /hover and /completion. The line (0 based) for which the metadata is queried.
32+
"positionChar": 2 # Mandatory for the endpoints /signatureHelp, /hover and /completion. The column (0 based) for which the metadata is queried. Characters are counted as UTF16 Codepoints.
33+
}
3234
3335
3436
Examples:
3537
36-
$ curl 'localhost:8080/diagnostics?expr=some_metric()&limit=100'|jq
38+
$ curl -XPOST 'localhost:8080/diagnostics' -H "Content-Type: application/json" --data '{"expr": "some_metric()", "limit":100}'|jq
3739
[
3840
{
3941
"range": {
@@ -53,7 +55,7 @@ Examples:
5355
]
5456
5557
56-
$ curl 'localhost:8080/completion?expr=sum(go)&line=0&char=6&limit=2'|jq
58+
$ curl -XPOST 'localhost:8080/completion' -H "Content-Type: application/json" --data '{"expr": "sum(go)", "limit":2, "positionLine":0, "positionChar":6}'|jq
5759
[
5860
{
5961
"label": "go_gc_duration_seconds",

0 commit comments

Comments
 (0)