Skip to content

Commit

Permalink
fix health check, fix build, add maxlines limit
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryk-dk committed Feb 8, 2024
1 parent 87e385d commit 12f71e9
Show file tree
Hide file tree
Showing 5 changed files with 1,724 additions and 1,959 deletions.
120 changes: 4 additions & 116 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@grafana/schema": "10.0.3",
"@grafana/ui": "10.0.3",
"@lezer/common": "^1.2.1",
"@lezer/lr": "^1.4.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-lodash": "^7.4.0",
Expand Down
7 changes: 4 additions & 3 deletions pkg/plugin/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

const (
health = "/-/healthy"
health = "/health"
)

// NewDatasource creates a new datasource instance.
Expand Down Expand Up @@ -116,13 +116,14 @@ func (d *Datasource) query(ctx context.Context, _ backend.PluginContext, query b
return newResponseError(err, backend.Status(resp.StatusCode))
}

var r Response
// TODO implement correct response
var r interface{}
if err := json.NewDecoder(resp.Body).Decode(&r); err != nil {
err = fmt.Errorf("failed to decode body response: %w", err)
return newResponseError(err, backend.StatusInternal)
}

log.DefaultLogger.Debug("RESPONSE => %#v", r)
// TODO convert response to the data Frames
// frames, err := r.getDataFrames()
// if err != nil {
// err = fmt.Errorf("failed to prepare data from reponse: %w", err)
Expand Down
14 changes: 12 additions & 2 deletions pkg/plugin/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import (
"fmt"
"net/url"
"path"
"strconv"
)

const instantQueryPath = "/logsql/query"
const (
instantQueryPath = "/select/logsql/query"
defaultMaxLines = 1000
)

// Query represents backend query object
type Query struct {
RefID string `json:"refId"`
Expr string `json:"expr"`
LegendFormat string `json:"legendFormat"`
MaxLines int
MaxLines int `json:"maxLines"`
url *url.URL
}

Expand Down Expand Up @@ -47,7 +51,13 @@ func (q *Query) queryInstantURL(queryParams url.Values) string {
values.Add(k, v)
}
}

if q.MaxLines <= 0 {
q.MaxLines = defaultMaxLines
}

values.Set("query", q.Expr)
values.Set("limit", strconv.Itoa(q.MaxLines))

q.url.RawQuery = values.Encode()
return q.url.String()
Expand Down
Loading

0 comments on commit 12f71e9

Please sign in to comment.