Skip to content

Commit 56b7869

Browse files
authored
Merge pull request #6 from duneanalytics/CUR2-1191
Add bigquery support
2 parents e63d341 + e2b5399 commit 56b7869

10 files changed

Lines changed: 390 additions & 172 deletions

File tree

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM public.ecr.aws/docker/library/golang:1.23 AS builder
1+
FROM public.ecr.aws/docker/library/golang:1.24.7 AS builder
22

33
ENV USER=app
44
ENV UID=10001
@@ -12,10 +12,10 @@ RUN adduser \
1212
--uid "${UID}" \
1313
"${USER}"
1414

15-
ADD . /go/src/github.com/a-monteiro/sql_exporter
16-
WORKDIR /go/src/github.com/a-monteiro/sql_exporter
15+
ADD . /go/src/github.com/duneanalytics/sql_exporter
16+
WORKDIR /go/src/github.com/duneanalytics/sql_exporter
1717

18-
#RUN make drivers-custom
18+
RUN make drivers-custom
1919
RUN make build
2020
RUN chmod +x ./sql_exporter
2121

@@ -25,7 +25,7 @@ FROM scratch
2525
COPY --from=builder /etc/passwd /etc/passwd
2626
COPY --from=builder /etc/group /etc/group
2727
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
28-
COPY --from=builder /go/src/github.com/a-monteiro/sql_exporter/sql_exporter /bin/sql_exporter
28+
COPY --from=builder /go/src/github.com/duneanalytics/sql_exporter/sql_exporter /bin/sql_exporter
2929

3030
EXPOSE 9100
3131
USER app:app

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ monitoring system. Out of the box, it provides support for the following databas
1111
- Microsoft SQL Server
1212
- Oracle Database
1313
- Clickhouse
14+
- BigQuery
1415
- Snowflake
1516
- Vertica
1617

@@ -197,6 +198,18 @@ For example, `p@$$w0rd#abc` then becomes `p%40%24%24w0rd%23abc`.
197198

198199
For additional details please refer to [xo/dburl](https://github.com/xo/dburl) documentation.
199200

201+
#### BigQuery
202+
203+
Use a BigQuery DSN like `bigquery://<project>/<dataset>` (or `bigquery://<project>/<location>/<dataset>`). The driver
204+
uses `GOOGLE_APPLICATION_CREDENTIALS` to locate the service account JSON file. In Kubernetes, follow the existing
205+
pattern used for Snowflake/Trino: set `SQLEXPORTER_TARGET_DSN` from a Secret and mount the service account JSON from a
206+
Secret, then set `GOOGLE_APPLICATION_CREDENTIALS` to the mounted file path.
207+
208+
To target a specific reservation per query, add a `reservation` query parameter to the DSN, for example:
209+
`bigquery://<project>/<dataset>?reservation=projects/<project>/locations/<location>/reservations/<reservation>`.
210+
The driver prefixes each query with `SET @@reservation='...'`, which uses BigQuery multi-statement scripting. See
211+
[BigQuery reservation assignments](https://docs.cloud.google.com/bigquery/docs/reservations-assignments#reservation).
212+
200213

201214
## Miscellaneous
202215

documentation/sql_exporter.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ target:
3535
name: mssql_database
3636
# Data source name always has a URI schema that matches the driver name. In some cases (e.g. MySQL)
3737
# the schema gets dropped or replaced to match the driver expected DSN format.
38+
# BigQuery example:
39+
# data_source_name: 'bigquery://<project>/<dataset>?reservation=projects/<project>/locations/<location>/reservations/<reservation>'
40+
# BigQuery auth uses GOOGLE_APPLICATION_CREDENTIALS pointing at a service account JSON file.
41+
# You can also reference environment variables, e.g. '$SQLEXPORTER_TARGET_DSN'.
3842
data_source_name: 'sqlserver://prom_user:prom_password@dbserver1.example.com:1433/dbname'
3943

4044
# Collectors (referenced by name) to execute on the target.

drivers.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drivers_gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var driverList = map[string][]string{
2929
},
3030
"custom": {
3131
//"github.com/mithrandie/csvq-driver",
32+
"gorm.io/driver/bigquery/driver",
3233
"github.com/trinodb/trino-go-client/trino",
3334
"github.com/databricks/databricks-sql-go",
3435
"github.com/snowflakedb/gosnowflake",

errors/errors.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package errors
22

33
import (
4+
"errors"
45
"fmt"
56
)
67

@@ -24,7 +25,7 @@ type withContext struct {
2425

2526
// New creates a new WithContext.
2627
func New(context string, err string) WithContext {
27-
return &withContext{context, fmt.Errorf(err)}
28+
return &withContext{context, errors.New(err)}
2829
}
2930

3031
// Errorf formats according to a format specifier and returns a new WithContext.

examples/bigquery.collector.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
collector_name: bigquery_ethereum_blocks
2+
3+
metrics:
4+
- metric_name: bigquery_ethereum_blocks_total
5+
type: gauge
6+
help: 'Total number of rows in ethereum_blocks.'
7+
values: [count]
8+
query: |
9+
SELECT COUNT(*) AS count
10+
FROM `PROD_DATASHARES_VIEWS_EU.ethereum_blocks`

examples/bigquery.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Example BigQuery target configuration (EU + US in one process).
2+
#
3+
# For local testing:
4+
# export GOOGLE_APPLICATION_CREDENTIALS=/path/to/bigquery-monitoring-SA-key.json
5+
# export SQLEXPORTER_TARGET_DSN_EU='bigquery://datashare-463211/EU/PROD_DATASHARES_VIEWS_EU?reservation=projects/datashare-463211/locations/EU/reservations/prod-datashare-monitoring-eu'
6+
# export SQLEXPORTER_TARGET_DSN_US='bigquery://datashare-463211/US/PROD_DATASHARES_VIEWS_US?reservation=projects/datashare-463211/locations/US/reservations/prod-datashare-monitoring-us'
7+
#
8+
# For Kubernetes:
9+
# - Set SQLEXPORTER_TARGET_DSN_EU/US from Secrets, as in existing Snowflake config.
10+
# - Mount the SA JSON from a Secret and set GOOGLE_APPLICATION_CREDENTIALS
11+
# to the mounted file path.
12+
13+
global:
14+
scrape_timeout: 30s
15+
16+
jobs:
17+
- job_name: bigquery_datashare_eu
18+
collectors: [bigquery_ethereum_blocks_eu]
19+
static_configs:
20+
- targets:
21+
datashare_eu: '$SQLEXPORTER_TARGET_DSN_EU'
22+
23+
- job_name: bigquery_datashare_us
24+
collectors: [bigquery_ethereum_blocks_us]
25+
static_configs:
26+
- targets:
27+
datashare_us: '$SQLEXPORTER_TARGET_DSN_US'
28+
29+
collectors:
30+
- collector_name: bigquery_ethereum_blocks_eu
31+
metrics:
32+
- metric_name: bigquery_ethereum_blocks_total
33+
type: gauge
34+
help: 'Total number of rows in ethereum_blocks.'
35+
values: [count]
36+
query: |
37+
SELECT COUNT(*) AS count
38+
FROM `PROD_DATASHARES_VIEWS_EU.ethereum_blocks`
39+
40+
- collector_name: bigquery_ethereum_blocks_us
41+
metrics:
42+
- metric_name: bigquery_ethereum_blocks_total
43+
type: gauge
44+
help: 'Total number of rows in ethereum_blocks.'
45+
values: [count]
46+
query: |
47+
SELECT COUNT(*) AS count
48+
FROM `PROD_DATASHARES_VIEWS_US.ethereum_blocks`

go.mod

Lines changed: 79 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,102 @@
11
module github.com/burningalchemist/sql_exporter
22

3-
go 1.23.0
3+
go 1.24.7
44

55
require (
6-
github.com/aws/aws-sdk-go-v2 v1.38.1
7-
github.com/aws/aws-sdk-go-v2/config v1.29.17
6+
github.com/aws/aws-sdk-go-v2 v1.39.0
7+
github.com/aws/aws-sdk-go-v2/config v1.31.8
88
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.35.7
9-
github.com/databricks/databricks-sql-go v1.0.1-0.20230105210901-69b282787450
9+
github.com/databricks/databricks-sql-go v1.9.0
1010
github.com/kardianos/minwinsvc v1.0.2
1111
github.com/prometheus/client_golang v1.22.0
1212
github.com/prometheus/client_model v0.6.2
1313
github.com/prometheus/common v0.65.0
1414
github.com/prometheus/exporter-toolkit v0.14.0
1515
github.com/sethvargo/go-envconfig v1.3.0
16-
github.com/snowflakedb/gosnowflake v1.17.0
17-
github.com/trinodb/trino-go-client v0.326.0
16+
github.com/snowflakedb/gosnowflake v1.19.0
17+
github.com/trinodb/trino-go-client v0.333.0
1818
github.com/xo/dburl v0.23.8
1919
google.golang.org/protobuf v1.36.6
2020
gopkg.in/yaml.v3 v3.0.1
21+
gorm.io/driver/bigquery v1.2.0
2122
)
2223

2324
require (
24-
github.com/apache/thrift v0.22.0 // indirect
25-
github.com/dnephin/pflag v1.0.7 // indirect
26-
github.com/docker/docker v28.2.2+incompatible // indirect
27-
github.com/fatih/color v1.15.0 // indirect
28-
github.com/fsnotify/fsnotify v1.5.4 // indirect
29-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
30-
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
31-
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
32-
github.com/hashicorp/go-uuid v1.0.3 // indirect
33-
github.com/jcmturner/gofork v1.7.6 // indirect
34-
github.com/mattn/go-colorable v0.1.13 // indirect
35-
github.com/mattn/go-isatty v0.0.20 // indirect
36-
github.com/opencontainers/image-spec v1.1.1 // indirect
37-
github.com/rs/zerolog v1.28.0 // indirect
38-
gotest.tools/gotestsum v1.8.2 // indirect
39-
)
40-
41-
require (
25+
cloud.google.com/go v0.121.0 // indirect
26+
cloud.google.com/go/auth v0.16.0 // indirect
27+
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
28+
cloud.google.com/go/bigquery v1.66.2 // indirect
29+
cloud.google.com/go/compute/metadata v0.6.0 // indirect
30+
cloud.google.com/go/iam v1.5.0 // indirect
4231
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
4332
github.com/99designs/keyring v1.2.2 // indirect
44-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 // indirect
45-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2 // indirect
33+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0 // indirect
34+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.10.1 // indirect
35+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
4636
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0 // indirect
4737
github.com/BurntSushi/toml v1.4.0 // indirect
4838
github.com/andybalholm/brotli v1.2.0 // indirect
4939
github.com/apache/arrow-go/v18 v18.4.0 // indirect
50-
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect
51-
github.com/aws/aws-sdk-go-v2/credentials v1.17.70 // indirect
52-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.32 // indirect
40+
github.com/apache/arrow/go/v12 v12.0.1 // indirect
41+
github.com/apache/arrow/go/v15 v15.0.2 // indirect
42+
github.com/apache/thrift v0.22.0 // indirect
43+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.1 // indirect
44+
github.com/aws/aws-sdk-go-v2/credentials v1.18.12 // indirect
45+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.7 // indirect
5346
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.15 // indirect
54-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.36 // indirect
55-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.36 // indirect
47+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.7 // indirect
48+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.7 // indirect
5649
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
57-
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.34 // indirect
58-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.4 // indirect
59-
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.7.0 // indirect
60-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.17 // indirect
61-
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.15 // indirect
62-
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.0 // indirect
63-
github.com/aws/aws-sdk-go-v2/service/sso v1.25.5 // indirect
64-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.3 // indirect
65-
github.com/aws/aws-sdk-go-v2/service/sts v1.34.0 // indirect
66-
github.com/aws/smithy-go v1.22.5 // indirect
50+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.7 // indirect
51+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1 // indirect
52+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.8.7 // indirect
53+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.7 // indirect
54+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.7 // indirect
55+
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.1 // indirect
56+
github.com/aws/aws-sdk-go-v2/service/sso v1.29.3 // indirect
57+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.34.4 // indirect
58+
github.com/aws/aws-sdk-go-v2/service/sts v1.38.4 // indirect
59+
github.com/aws/smithy-go v1.23.0 // indirect
6760
github.com/beorn7/perks v1.0.1 // indirect
6861
github.com/cespare/xxhash/v2 v2.3.0 // indirect
62+
github.com/coreos/go-oidc/v3 v3.5.0 // indirect
6963
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
7064
github.com/danieljoos/wincred v1.2.2 // indirect
71-
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
65+
github.com/dnephin/pflag v1.0.7 // indirect
66+
github.com/dvsekhvalnov/jose2go v1.7.0 // indirect
67+
github.com/fatih/color v1.16.0 // indirect
68+
github.com/felixge/httpsnoop v1.0.4 // indirect
69+
github.com/fsnotify/fsnotify v1.5.4 // indirect
7270
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
71+
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
72+
github.com/go-logr/logr v1.4.3 // indirect
73+
github.com/go-logr/stdr v1.2.2 // indirect
7374
github.com/goccy/go-json v0.10.5 // indirect
7475
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
75-
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
76+
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
7677
github.com/golang/snappy v1.0.0 // indirect
7778
github.com/google/flatbuffers v25.2.10+incompatible // indirect
79+
github.com/google/s2a-go v0.1.9 // indirect
80+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
7881
github.com/google/uuid v1.6.0 // indirect
82+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
83+
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
7984
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
85+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
86+
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
87+
github.com/hashicorp/go-uuid v1.0.3 // indirect
8088
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
8189
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
90+
github.com/jcmturner/gofork v1.7.6 // indirect
8291
github.com/jcmturner/goidentity/v6 v6.0.1 // indirect
8392
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
8493
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
8594
github.com/jpillora/backoff v1.0.0 // indirect
8695
github.com/klauspost/asmfmt v1.3.2 // indirect
87-
github.com/klauspost/compress v1.18.0 // indirect
96+
github.com/klauspost/compress v1.18.1 // indirect
8897
github.com/klauspost/cpuid/v2 v2.2.11 // indirect
98+
github.com/mattn/go-colorable v0.1.13 // indirect
99+
github.com/mattn/go-isatty v0.0.20 // indirect
89100
github.com/mdlayher/socket v0.4.1 // indirect
90101
github.com/mdlayher/vsock v1.2.1 // indirect
91102
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
@@ -95,26 +106,40 @@ require (
95106
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
96107
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
97108
github.com/pierrec/lz4/v4 v4.1.22 // indirect
98-
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
109+
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
99110
github.com/pkg/errors v0.9.1 // indirect
100111
github.com/prometheus/procfs v0.15.1 // indirect
101-
github.com/rogpeppe/go-internal v1.13.1 // indirect
112+
github.com/rs/zerolog v1.28.0 // indirect
102113
github.com/sirupsen/logrus v1.9.3 // indirect
103114
github.com/zeebo/xxh3 v1.0.2 // indirect
115+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
116+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
117+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
104118
go.opentelemetry.io/otel v1.37.0 // indirect
119+
go.opentelemetry.io/otel/metric v1.37.0 // indirect
105120
go.opentelemetry.io/otel/trace v1.37.0 // indirect
106-
golang.org/x/crypto v0.41.0 // indirect
121+
golang.org/x/crypto v0.45.0 // indirect
107122
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
108-
golang.org/x/mod v0.27.0 // indirect
109-
golang.org/x/net v0.43.0 // indirect
123+
golang.org/x/mod v0.29.0 // indirect
124+
golang.org/x/net v0.47.0 // indirect
110125
golang.org/x/oauth2 v0.30.0 // indirect
111-
golang.org/x/sync v0.16.0 // indirect
112-
golang.org/x/sys v0.35.0 // indirect
113-
golang.org/x/term v0.34.0 // indirect
114-
golang.org/x/text v0.28.0 // indirect
115-
golang.org/x/tools v0.36.0 // indirect
126+
golang.org/x/sync v0.18.0 // indirect
127+
golang.org/x/sys v0.38.0 // indirect
128+
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 // indirect
129+
golang.org/x/term v0.37.0 // indirect
130+
golang.org/x/text v0.31.0 // indirect
131+
golang.org/x/time v0.11.0 // indirect
132+
golang.org/x/tools v0.38.0 // indirect
116133
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
134+
google.golang.org/api v0.230.0 // indirect
135+
google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb // indirect
136+
google.golang.org/genproto/googleapis/api v0.0.0-20250414145226-207652e42e2e // indirect
137+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197 // indirect
138+
google.golang.org/grpc v1.73.0 // indirect
117139
gopkg.in/yaml.v2 v2.4.0 // indirect
140+
gotest.tools/gotestsum v1.8.2 // indirect
118141
)
119142

120143
replace github.com/xo/dburl v0.23.8 => github.com/a-monteiro/dburl v0.23.8-fork
144+
145+
replace gorm.io/driver/bigquery => github.com/duneanalytics/bigquery v1.2.0-dune.1

0 commit comments

Comments
 (0)