grafana / grafana

The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
https://grafana.com
GNU Affero General Public License v3.0
60.72k stars 11.61k forks source link

Build: Replace github.com/mattn/go-sqlite3 with a non-CGO alternative #87327

Open hairyhenderson opened 2 weeks ago

hairyhenderson commented 2 weeks ago

Why is this needed:

Currently we need to build the Grafana backend with CGO_ENABLED=1 because of our use of github.com/mattn/go-sqlite3. A pure Go alternative is available - github.com/glebarez/go-sqlite.

We should consider using this to simplify our build process (remove cross-compilation considerations, etc).

grafanabot commented 2 weeks ago

@hairyhenderson please add one or more appropriate labels. Here are some tips:

hairyhenderson commented 1 week ago

Upon reading closer about github.com/glebarez/go-sqlite I realize my initial impression of modernc.org/sqlite was mistaken - I thought the latter had no database/sql driver, hence the former. However both have drivers. The reason glebarez/go-sqlite exists is explained here: https://github.com/glebarez/go-sqlite/issues/96 - essentially:

glebarez/go-sqlite is just a fork of modernc.org/sqlite with slight changes in the driver part (2), to behave more closely to mattn’s CGo driver (https://github.com/mattn/go-sqlite3). this slight changes allowed it to be fully compatible with GORM [...]

This may or may not be relevant, as we're currently using the mattn driver, and that with xorm, which, while different from GORM, raises questions about whether or not modernc.org/sqlite will work without too much trouble on its own.

https://github.com/cvilsmeier/go-sqlite-bench also lists a number of other candidate modules:

(copy/pasted from the README, and annotated by me):

So, we're left with effectively 3 options:

IMO it's worth experimenting with these three, starting with modernc.org/sqlite.