diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 880a686..811fc6f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: branches: - main - - code_cleaup + - update jobs: diff --git a/coverage/junit.xml b/coverage/junit.xml index 564852b..b118064 100644 --- a/coverage/junit.xml +++ b/coverage/junit.xml @@ -1,27 +1,26 @@ - - - + + + ->>>>>>> tpise - + - + - + @@ -43,15 +42,15 @@ - - + + - + - + diff --git a/pkg/datasource.go b/pkg/datasource.go index 169e046..5cfc5f3 100644 --- a/pkg/datasource.go +++ b/pkg/datasource.go @@ -38,10 +38,7 @@ import ( "encoding/json" "fmt" "net/http" - // "strconv" "time" - - // "strings" "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/datasource" "github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt" @@ -57,7 +54,6 @@ func newDatasource() datasource.ServeOpts { ds := &VerticaDatasource{ im: im, } - return datasource.ServeOpts{ QueryDataHandler: ds, CheckHealthHandler: ds, @@ -70,26 +66,24 @@ type VerticaDatasource struct { im instancemgmt.InstanceManager } -// GetVerticaDb will return the vertica db connection -// stored in the instance setting when the instance is created or update // GetVerticaDb will return the vertica db connection // stored in the instance setting when the instance is created or update func (v *VerticaDatasource) GetVerticaDb(pluginContext backend.PluginContext) (*sql.DB, error) { instance, err := v.im.Get(pluginContext) - - if err != nil { log.DefaultLogger.Error("getVerticaDb: %s", err) return nil, err } if instanceSetting, ok := instance.(*instanceSettings); ok { return instanceSetting.Db, nil + } else { + log.DefaultLogger.Error("getVerticaDb: %s", err) + return nil, err } - return nil, nil //this is added to avoid syntax error but this line will never gets executed - return nil, nil //this is added to avoid syntax error but this line will never gets executed } + type configArgs struct { User string `json:"user"` Database string `json:"database"` @@ -107,16 +101,12 @@ type configArgs struct { // ConnectionURL , generates a vertica connection URL for configArgs. Requires password as input. func (config *configArgs) ConnectionURL(password string) string { var tlsmode string - - if config.TLSMode == "" { tlsmode = "none" } else { tlsmode = config.TLSMode } - return fmt.Sprintf("vertica://%s:%s@%s/%s?use_prepared_statements=%d&connection_load_balance=%d&tlsmode=%s&backup_server_node=%s", config.User, password, config.URL, config.Database, boolTouint8(config.UsePreparedStmts), boolTouint8(config.UseLoadBalancer), tlsmode, config.BackupServerNode) - } type queryModel struct { @@ -196,44 +186,30 @@ type instanceSettings struct { // Create new datasource. func newDataSourceInstance(setting backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) { var config configArgs - - secret := setting.DecryptedSecureJSONData["password"] err := json.Unmarshal(setting.JSONData, &config) if err != nil { return nil, err } - // res := strings.Split(config.URL, ":") - // config.URL= res[0] - // Port,_ := strconv.Atoi(res[1]) connStr := config.ConnectionURL(secret) db, err := sql.Open("vertica", connStr) - - if err != nil { return nil, err } - db.SetMaxOpenConns(config.MaxOpenConnections) db.SetMaxIdleConns(config.MaxIdealConnections) db.SetConnMaxIdleTime(time.Minute * time.Duration(config.MaxConnectionIdealTime)) log.DefaultLogger.Info(fmt.Sprintf("newDataSourceInstance: new instance of datasource created: %+v", setting.Name)) - log.DefaultLogger.Info(fmt.Sprintf("newDataSourceInstance: new instance of datasource created: %+v", setting.Name)) return &instanceSettings{ httpClient: &http.Client{}, Db: db, Name: setting.Name, }, nil - - } - - - // CheckHealth handles health checks sent from Grafana to the plugin. // The main use case for these health checks is the test button on the // datasource configuration page which allows users to verify that @@ -245,7 +221,6 @@ func (v *VerticaDatasource) CheckHealth(ctx context.Context, req *backend.CheckH var status = backend.HealthStatusOk connDB, err := v.GetVerticaDb(req.PluginContext) - if err != nil { log.DefaultLogger.Error("unable to get sql.DB connection: " + err.Error()) return &backend.CheckHealthResult{ @@ -257,7 +232,6 @@ func (v *VerticaDatasource) CheckHealth(ctx context.Context, req *backend.CheckH log.DefaultLogger.Debug(fmt.Sprintf("%s connection stats open connections =%d, InUse = %d, Ideal = %d", req.PluginContext.DataSourceInstanceSettings.Name, connDB.Stats().MaxOpenConnections, connDB.Stats().InUse, connDB.Stats().Idle)) connection, err := connDB.Conn(ctx) - if err != nil { log.DefaultLogger.Info(fmt.Sprintf("CheckHealth :connection: %s", err)) return &backend.CheckHealthResult{