Skip to content

Commit

Permalink
Swap to using integers for extended bounds in the data histogram aggr…
Browse files Browse the repository at this point in the history
…egation instead of strings so that alerts using _timesinceepoch continue to work
  • Loading branch information
kyle-sammons committed Oct 24, 2024
1 parent 130b15d commit 46a8902
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ services:
GF_PATHS_PLUGINS: "/var/lib/grafana/plugins"
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: "slack-astra-app,slack-astra-app-backend-datasource"
GF_SERVER_ENABLE_GZIP: "true"
GF_UNIFIED_ALERTING_ENABLED: "false"
GF_ALERTING_ENABLED: "true"
GF_DATABASE_WAL: "true"
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ require (
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
)

require github.com/grafana/opensearch-datasource v1.2.0
require (
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/grafana/opensearch-datasource v1.2.0
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect
)

replace golang.org/x/sys => golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c
2 changes: 2 additions & 0 deletions pkg/astra/astra.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type AstraExecutor struct{}

var (
intervalCalculator tsdb.IntervalCalculator
_ backend.QueryDataHandler = (*AstraDatasource)(nil)
_ backend.CheckHealthHandler = (*AstraDatasource)(nil)
)

type TsdbQueryEndpoint interface {
Expand Down
3 changes: 1 addition & 2 deletions pkg/astra/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ func (c *baseClientImpl) encodeBatchRequests(requests []*multiRequest) ([]byte,
body := string(reqBody)
body = strings.ReplaceAll(body, "$__interval_ms", strconv.FormatInt(r.interval.Milliseconds(), 10))
body = strings.ReplaceAll(body, "$__interval", r.interval.Text)

payload.WriteString(body + "\n")
}

Expand Down Expand Up @@ -464,7 +463,7 @@ func (c *baseClientImpl) executePPLQueryRequest(method, uriPath string, body []b
return nil, err
}

clientLog.Debug("Executing request", "url", req.URL.String(), "method", method)
clientLog.Debug("Executing PPL request", "url", req.URL.String(), "method", method)

var reqInfo *PPLRequestInfo
if c.debugEnabled {
Expand Down
6 changes: 3 additions & 3 deletions pkg/astra/client/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type SearchResponse struct {
Error map[string]interface{} `json:"error"`
Aggregations map[string]interface{} `json:"aggregations"`
Hits *SearchResponseHits `json:"hits"`
Shards map[string]interface{} `json:"_shards"`
Shards map[string]interface{} `json:"_shards"`
}

// MultiSearchRequest represents a multi search request
Expand Down Expand Up @@ -271,8 +271,8 @@ type TermsAggregation struct {

// ExtendedBounds represents extended bounds
type ExtendedBounds struct {
Min string `json:"min"`
Max string `json:"max"`
Min int64 `json:"min"`
Max int64 `json:"max"`
}

// GeoHashGridAggregation represents a geo hash grid aggregation
Expand Down
4 changes: 2 additions & 2 deletions pkg/astra/lucene_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (h *luceneHandler) processQuery(q *Query) error {
for _, bucketAgg := range q.BucketAggs {
switch bucketAgg.Type {
case dateHistType:
aggBuilder = addDateHistogramAgg(aggBuilder, bucketAgg, from, to)
aggBuilder = addDateHistogramAgg(aggBuilder, bucketAgg, int64(fromMs), int64(toMs))
case histogramType:
aggBuilder = addHistogramAgg(aggBuilder, bucketAgg)
case filtersType:
Expand Down Expand Up @@ -168,7 +168,7 @@ func (h *luceneHandler) executeQueries() (*backend.QueryDataResponse, error) {
return rp.getTimeSeries()
}

func addDateHistogramAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, timeFrom, timeTo string) es.AggBuilder {
func addDateHistogramAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg, timeFrom, timeTo int64) es.AggBuilder {
aggBuilder.DateHistogram(bucketAgg.ID, bucketAgg.Field, func(a *es.DateHistogramAgg, b es.AggBuilder) {
a.Interval = bucketAgg.Settings.Get("interval").MustString("auto")
a.MinDocCount = bucketAgg.Settings.Get("min_doc_count").MustInt(0)
Expand Down

0 comments on commit 46a8902

Please sign in to comment.