burningalchemist / sql_exporter

Database-agnostic SQL Exporter for Prometheus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for ASE database (sybase)

clacalderonc opened this issue · comments

Hi @burningalchemist

I'm working on a montoring implementation of a SAP ASE database(sybase) and since this project is database agnostic, i gave it a try, since the driver is not imported on the dependencies list (drivers.go/drivers_gen.go) i built the binary using the available go ase driver according your documentation:

I added the dependency to drivers_gen.go, ln 17:

var driverList = map[string][]string{
	"minimal": {
		"github.com/go-sql-driver/mysql",
		"github.com/lib/pq",
		"github.com/microsoft/go-mssqldb/azuread",
	},
	"extra": {
		"github.com/ClickHouse/clickhouse-go",
		"github.com/jackc/pgx/v4/stdlib",
		"github.com/snowflakedb/gosnowflake",
		"github.com/vertica/vertica-sql-go",
		"github.com/SAP/go-ase", // <--------- GO ASE DRIVER
	},
	"custom": {
		"github.com/mithrandie/csvq-driver",
	},
}

the run

make drivers-all
make build

The only issue that i couldnt figure out is how is the driver name inferred based in the datasource, my connection string looks like:

# Global settings and defaults.
global:
  # some parameters
  ... 
# The target to monitor and the list of collectors to execute on it.
target:
  data_source_name: "ase://dbusername:dbpassword@mydbhostname.mydomain:4901/"

I added some prints on sql.go and findout that the driver name inferred was wrong, so i did a little workarround to overwrite the driver name:

sql: unknown driver "tds" (forgotten import?) ts=2023-09-25T15:34:12.884Z caller=klog.go:124 level=error func=Errorf msg="No metrics gathered: [from Gatherer #1] sql: unknown driver \"tds\" (forgotten import?)"

	driver := url.Driver
	fmt.Println("\nDSN ", dsn)
	fmt.Println("\nDRIVER: ", driver)


	if url.GoDriver != "" {
		driver = url.GoDriver
	}

	// Workarround to overwrite driver name
	if strings.Contains(dsn, "ase") {
		driver = "ase"
	}

	fmt.Println("driver new ", driver)

	// Open the DB handle in a separate goroutine so we can terminate early if the context closes.
	go func() {
		conn, err = sql.Open(driver, url.DSN)
		fmt.Println("\nCONN_ERROR ", err)
		close(ch)
	}()

tell me if there is a better way to handle the driver name calculation for this case, i dont have exp with golang by the way, but i can create a merge request if this works for you.

Regards!

Hi @clacalderonc, please have a look at this discussion - #232

You can apply changes from the ase-temp branch to work around the existing dependency limitations (it was created for demonstration, so the rebase against the HEAD might be required) if needed.

The proper solution, however, is to contribute the driver schema change directly to xo/dburl (link) (currently it works as an alias for the old tds driver), then update the dburl dependency on the sql_exporter side and just use it here, no other changes are needed. So the goal is that we don't have any special database-related handling on the sql_exporter side.

I plan to contribute this change to the upstream, however I'm currently focused on some other features, so it might take some time. In the meantime, you can follow the discussion leads to build it on your end with some adjustments.

With this in mind, there's currently nothing to do on the sql_exporter side. I'll make another announcement once it's supported in the upstream.