Skip to content

Commit 71090eb

Browse files
authored
Chore: use functions migrated to sqlutil (#107)
1 parent 655348a commit 71090eb

File tree

7 files changed

+163
-563
lines changed

7 files changed

+163
-563
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,4 @@ func datasourceFactory(ctx context.Context, s backend.DataSourceInstanceSettings
2626

2727
### Macros
2828

29-
The `sqlds` package defines a set of default macros:
30-
31-
- `$__timeFilter(time_column)`: Filters by timestamp using the query period. Resolves to: `time >= '0001-01-01T00:00:00Z' AND time <= '0001-01-01T00:00:00Z'`
32-
- `$__timeFrom(time_column)`: Filters by timestamp using the start point of the query period. Resolves to `time >= '0001-01-01T00:00:00Z'`
33-
- `$__timeTo(time_column)`: Filters by timestamp using the end point of the query period. Resolves to `time <= '0001-01-01T00:00:00Z'`
34-
- `$__timeGroup(time_column, period)`: To group times based on a period. Resolves to (minute example): `"datepart(year, time), datepart(month, time)'"`
35-
- `$__table`: Returns the `table` configured in the query.
36-
- `$__column`: Returns the `column` configured in the query.
29+
The `sqlds` package formerly defined a set of default macros, but those have been migrated to `grafana-plugin-sdk-go`: see [the code](https://github.com/grafana/grafana-plugin-sdk-go/blob/main/data/sqlutil/macros.go) for details.

datasource.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
"github.com/grafana/grafana-plugin-sdk-go/data/sqlutil"
910
"net/http"
1011
"strings"
1112
"sync"
@@ -207,7 +208,7 @@ func (ds *SQLDatasource) handleQuery(ctx context.Context, req backend.DataQuery,
207208
// Apply supported macros to the query
208209
q.RawSQL, err = Interpolate(ds.c, q)
209210
if err != nil {
210-
return getErrorFrameFromQuery(q), fmt.Errorf("%s: %w", "Could not apply macros", err)
211+
return sqlutil.ErrorFrameFromQuery(q), fmt.Errorf("%s: %w", "Could not apply macros", err)
211212
}
212213

213214
// Apply the default FillMode, overwritting it if the query specifies it
@@ -219,7 +220,7 @@ func (ds *SQLDatasource) handleQuery(ctx context.Context, req backend.DataQuery,
219220
// Retrieve the database connection
220221
cacheKey, dbConn, err := ds.getDBConnectionFromQuery(ctx, q, datasourceUID)
221222
if err != nil {
222-
return getErrorFrameFromQuery(q), err
223+
return sqlutil.ErrorFrameFromQuery(q), err
223224
}
224225

225226
if ds.driverSettings.Timeout != 0 {

go.mod

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ toolchain go1.21.1
66

77
require (
88
github.com/go-sql-driver/mysql v1.4.0
9-
github.com/google/go-cmp v0.5.9
9+
github.com/google/go-cmp v0.6.0
1010
github.com/grafana/dataplane/sdata v0.0.7
11-
github.com/grafana/grafana-plugin-sdk-go v0.188.3
11+
github.com/grafana/grafana-plugin-sdk-go v0.201.0
1212
github.com/mithrandie/csvq-driver v1.6.8
1313
github.com/stretchr/testify v1.8.4
1414
)
1515

1616
require (
17-
cloud.google.com/go/compute/metadata v0.2.3 // indirect
1817
github.com/BurntSushi/toml v1.3.2 // indirect
1918
github.com/apache/arrow/go/v13 v13.0.0 // indirect
2019
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
2120
github.com/chromedp/cdproto v0.0.0-20220208224320-6efb837e6bc2 // indirect
2221
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
2322
github.com/elazarl/goproxy v0.0.0-20230731152917-f99041a5c027 // indirect
2423
github.com/getkin/kin-openapi v0.120.0 // indirect
25-
github.com/go-logr/logr v1.2.4 // indirect
24+
github.com/go-logr/logr v1.3.0 // indirect
2625
github.com/go-logr/stdr v1.2.2 // indirect
2726
github.com/go-openapi/jsonpointer v0.19.6 // indirect
2827
github.com/go-openapi/swag v0.22.4 // indirect
2928
github.com/goccy/go-json v0.10.0 // indirect
30-
github.com/google/uuid v1.3.0 // indirect
29+
github.com/gogo/protobuf v1.3.2 // indirect
30+
github.com/google/uuid v1.5.0 // indirect
3131
github.com/gorilla/mux v1.8.0 // indirect
3232
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 // indirect
3333
github.com/invopop/yaml v0.2.0 // indirect
@@ -43,20 +43,22 @@ require (
4343
github.com/unknwon/log v0.0.0-20150304194804-e617c87089d3 // indirect
4444
github.com/urfave/cli v1.22.14 // indirect
4545
github.com/zeebo/xxh3 v1.0.2 // indirect
46-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.45.0 // indirect
47-
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.45.0 // indirect
48-
go.opentelemetry.io/contrib/propagators/jaeger v1.20.0 // indirect
49-
go.opentelemetry.io/otel v1.19.0 // indirect
50-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
51-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
52-
go.opentelemetry.io/otel/metric v1.19.0 // indirect
53-
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
54-
go.opentelemetry.io/otel/trace v1.19.0 // indirect
46+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
47+
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.46.1 // indirect
48+
go.opentelemetry.io/contrib/propagators/jaeger v1.21.1 // indirect
49+
go.opentelemetry.io/contrib/samplers/jaegerremote v0.15.1 // indirect
50+
go.opentelemetry.io/otel v1.21.0 // indirect
51+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
52+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect
53+
go.opentelemetry.io/otel/metric v1.21.0 // indirect
54+
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
55+
go.opentelemetry.io/otel/trace v1.21.0 // indirect
5556
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
5657
golang.org/x/mod v0.9.0 // indirect
5758
golang.org/x/tools v0.6.0 // indirect
58-
google.golang.org/genproto/googleapis/api v0.0.0-20230731193218-e0aa005b6bdf // indirect
59-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731193218-e0aa005b6bdf // indirect
59+
google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 // indirect
60+
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 // indirect
61+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
6062
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
6163
)
6264

@@ -70,16 +72,15 @@ require (
7072
github.com/google/flatbuffers v23.1.21+incompatible // indirect
7173
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
7274
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
73-
github.com/hashicorp/go-hclog v1.5.0 // indirect
74-
github.com/hashicorp/go-plugin v1.4.9 // indirect
75+
github.com/hashicorp/go-hclog v1.6.2 // indirect
76+
github.com/hashicorp/go-plugin v1.6.0 // indirect
7577
github.com/hashicorp/yamux v0.1.1 // indirect
7678
github.com/json-iterator/go v1.1.12 // indirect
7779
github.com/klauspost/compress v1.15.15 // indirect
7880
github.com/mattetti/filebuffer v1.0.1 // indirect
7981
github.com/mattn/go-colorable v0.1.13 // indirect
8082
github.com/mattn/go-isatty v0.0.18 // indirect
8183
github.com/mattn/go-runewidth v0.0.9 // indirect
82-
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
8384
github.com/mitchellh/go-homedir v1.0.0 // indirect
8485
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
8586
github.com/mithrandie/csvq v1.17.10 // indirect
@@ -92,19 +93,19 @@ require (
9293
github.com/olekukonko/tablewriter v0.0.5 // indirect
9394
github.com/pierrec/lz4/v4 v4.1.17 // indirect
9495
github.com/pmezard/go-difflib v1.0.0 // indirect
95-
github.com/prometheus/client_golang v1.14.0 // indirect
96-
github.com/prometheus/client_model v0.3.0 // indirect
97-
github.com/prometheus/common v0.42.0 // indirect
98-
github.com/prometheus/procfs v0.8.0 // indirect
99-
golang.org/x/crypto v0.14.0 // indirect
100-
golang.org/x/exp v0.0.0-20230307190834-24139beb5833
101-
golang.org/x/net v0.17.0 // indirect
102-
golang.org/x/sys v0.13.0 // indirect
103-
golang.org/x/term v0.13.0 // indirect
104-
golang.org/x/text v0.13.0 // indirect
96+
github.com/prometheus/client_golang v1.18.0 // indirect
97+
github.com/prometheus/client_model v0.5.0 // indirect
98+
github.com/prometheus/common v0.46.0 // indirect
99+
github.com/prometheus/procfs v0.12.0 // indirect
100+
golang.org/x/crypto v0.18.0 // indirect
101+
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect
102+
golang.org/x/net v0.20.0 // indirect
103+
golang.org/x/sys v0.16.0 // indirect
104+
golang.org/x/term v0.16.0 // indirect
105+
golang.org/x/text v0.14.0 // indirect
105106
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
106-
google.golang.org/appengine v1.6.7 // indirect
107-
google.golang.org/grpc v1.58.2 // indirect
108-
google.golang.org/protobuf v1.31.0 // indirect
107+
google.golang.org/appengine v1.6.8 // indirect
108+
google.golang.org/grpc v1.60.1 // indirect
109+
google.golang.org/protobuf v1.32.0 // indirect
109110
gopkg.in/yaml.v3 v3.0.1 // indirect
110111
)

0 commit comments

Comments
 (0)