Skip to content

Commit f625b2b

Browse files
authored
Merge pull request #51 from dewey/feature/add-snowflake
Add Snowflake support
2 parents b22dbd0 + e05c369 commit f625b2b

File tree

1,781 files changed

+528043
-23600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,781 files changed

+528043
-23600
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Status
1010

1111
Actively used with PostgreSQL in production. We'd like to eventually support all databases for which stable Go database [drivers](https://github.com/golang/go/wiki/SQLDrivers) are available. Contributions welcome.
1212

13+
Currently supported:
14+
15+
- Postgres
16+
- ClickHouse
17+
- AWS Athena
18+
- MS-SQL
19+
- MySQL
20+
- Snowflake
21+
22+
1323
What does it look like?
1424
=======================
1525

config.yml.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,16 @@ jobs:
125125
WHERE partition IN
126126
(SELECT max(partition)
127127
FROM my_athena_db.some_table);
128+
- name: "snowflake"
129+
interval: '1m'
130+
connections:
131+
- 'snowflake://username:password@hostname/schema/table'
132+
queries:
133+
- name: "snowflake_dwh_some_table"
134+
help: "Number of rows..."
135+
# Make sure values matches the return value of the query. If alias isn't quoted in the query Snowflake will use uppercase which has to match with the column
136+
# name in values.
137+
values:
138+
- "count"
139+
query: |
140+
select count(1) as "count" from our_data_warehouse limit 1;

go.mod

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@ module github.com/justwatchcom/sql_exporter
33
go 1.12
44

55
require (
6-
github.com/ClickHouse/clickhouse-go v1.3.13
7-
github.com/aws/aws-sdk-go v1.27.1 // indirect
6+
github.com/ClickHouse/clickhouse-go v1.5.1
7+
github.com/apache/arrow/go/arrow v0.0.0-20211104083220-e6b98c9f1427 // indirect
8+
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.6.0 // indirect
89
github.com/cenkalti/backoff v2.2.1+incompatible
910
github.com/denisenkom/go-mssqldb v0.0.0-20191128021309-1d7a30a10f73
10-
github.com/go-kit/kit v0.9.0
11-
github.com/go-sql-driver/mysql v1.4.1
12-
github.com/go-stack/stack v1.8.0 // indirect
13-
github.com/jmoiron/sqlx v1.2.0
14-
github.com/lib/pq v1.3.0
15-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
16-
github.com/modern-go/reflect2 v1.0.1 // indirect
17-
github.com/prometheus/client_golang v1.3.0
18-
github.com/prometheus/common v0.7.0
11+
github.com/gabriel-vasile/mimetype v1.4.0 // indirect
12+
github.com/go-kit/kit v0.12.0
13+
github.com/go-sql-driver/mysql v1.5.0
14+
github.com/jmoiron/sqlx v1.3.4
15+
github.com/lib/pq v1.10.3
16+
github.com/pierrec/lz4/v4 v4.1.10 // indirect
17+
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
18+
github.com/prometheus/client_golang v1.11.0
19+
github.com/prometheus/common v0.30.0
1920
github.com/satori/go.uuid v1.2.0 // indirect
2021
github.com/segmentio/go-athena v0.0.0-20181208004937-dfa5f1818930
21-
google.golang.org/appengine v1.6.5 // indirect
22-
gopkg.in/yaml.v2 v2.2.7
22+
github.com/snowflakedb/gosnowflake v1.6.3
23+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
24+
golang.org/x/net v0.0.0-20211101193420-4a448f8816b3 // indirect
25+
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
26+
gopkg.in/yaml.v2 v2.4.0
2327
)

go.sum

Lines changed: 820 additions & 40 deletions
Large diffs are not rendered by default.

job.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"fmt"
55
"net/url"
66
"regexp"
7+
"strconv"
78
"strings"
89
"time"
910

11+
"github.com/snowflakedb/gosnowflake"
12+
1013
_ "github.com/ClickHouse/clickhouse-go" // register the ClickHouse driver
1114
"github.com/cenkalti/backoff"
1215
_ "github.com/denisenkom/go-mssqldb" // register the MS-SQL driver
@@ -16,7 +19,8 @@ import (
1619
"github.com/jmoiron/sqlx"
1720
_ "github.com/lib/pq" // register the PostgreSQL driver
1821
"github.com/prometheus/client_golang/prometheus"
19-
_ "github.com/segmentio/go-athena" // register the AWS Athena driver
22+
_ "github.com/segmentio/go-athena" // register the AWS Athena driver
23+
_ "github.com/snowflakedb/gosnowflake" // register the Snowflake driver
2024
)
2125

2226
var (
@@ -127,12 +131,44 @@ func (j *Job) Run() {
127131
// call go-athena's Open() to ensure conn.db is set,
128132
// otherwise API calls will complain about an empty database field:
129133
// "InvalidParameter: 1 validation error(s) found. - minimum field size of 1, StartQueryExecutionInput.QueryExecutionContext.Database."
130-
newConn.conn, err = sqlx.Open("athena", u.RawQuery)
134+
newConn.conn, err = sqlx.Open("athena", u.String())
131135
if err != nil {
132136
level.Error(j.log).Log("msg", "Failed to open Athena connection", "connection", conn, "err", err)
133137
continue
134138
}
135139
}
140+
if newConn.driver == "snowflake" {
141+
cfg := &gosnowflake.Config{
142+
Account: u.Host,
143+
User: u.User.Username(),
144+
}
145+
146+
pw, set := u.User.Password()
147+
if set {
148+
cfg.Password = pw
149+
}
150+
151+
if u.Port() != "" {
152+
portStr, err := strconv.Atoi(u.Port())
153+
if err != nil {
154+
level.Error(j.log).Log("msg", "Failed to parse Snowflake port", "connection", conn, "err", err)
155+
continue
156+
}
157+
cfg.Port = portStr
158+
}
159+
160+
dsn, err := gosnowflake.DSN(cfg)
161+
if err != nil {
162+
level.Error(j.log).Log("msg", "Failed to create Snowflake DSN", "connection", conn, "err", err)
163+
continue
164+
}
165+
166+
newConn.conn, err = sqlx.Open("snowflake", dsn)
167+
if err != nil {
168+
level.Error(j.log).Log("msg", "Failed to open Snowflake connection", "connection", conn, "err", err)
169+
continue
170+
}
171+
}
136172
j.conns = append(j.conns, newConn)
137173
}
138174
}

vendor/github.com/Azure/azure-pipeline-go/LICENSE

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

0 commit comments

Comments
 (0)