Skip to content

Commit

Permalink
code clean up, build fixed (#40)
Browse files Browse the repository at this point in the history
* "added"

* added

* Run button added

* disabling/enabling run button

* bug fixed

* support for backup server and autocomplete

* code cleanup and setting up go actions pipeline

* added code_cleaup branch for github actions

* updated github actions for frontend

* updated node version in github actions

* changed from npm to yarn in github actions

* changed grafana experimental version to 1.1.0

* removed npm build and added yarn build for frontend github action pipeline

* code cleanup

* updated

* updated

* updated code

* label change for backup server node

* bug fixing

* test junit

* build fixing

* version update

* port editable

* port change

* port change and long asec issue fix

* "Port placeholder removed"

* "updated tests"

* supports ipv4 and [ipv6]

* removed lock file

* backup sever host clear

* updated

* updated build yml

* pkg fixed

* code cleanup

* code cleanup

---------

Co-authored-by: Vishal kumar <[email protected]>
Co-authored-by: Shilpa C <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2023
1 parent baee4d6 commit 040c4ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- code_cleaup
- update


jobs:
Expand Down
21 changes: 10 additions & 11 deletions coverage/junit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="jest tests" tests="23" failures="0" time="4.197">
<testsuite name="Render" errors="0" failures="0" skipped="0" timestamp="2023-03-15T08:01:08" time="2.51" tests="9">
<testcase classname="Render Render should render component with value in BackUp Server Nodes" name="Render Render should render component with value in BackUp Server Nodes" time="0.015">
<testsuites name="jest tests" tests="23" failures="0" time="4.526">
<testsuite name="Render" errors="0" failures="0" skipped="0" timestamp="2023-03-15T10:54:01" time="2.81" tests="9">
<testcase classname="Render Render should render component with value in BackUp Server Nodes" name="Render Render should render component with value in BackUp Server Nodes" time="0.016">
</testcase>
<testcase classname="Render Render should render component with value in Use Backup Server field" name="Render Render should render component with value in Use Backup Server field" time="0.004">
</testcase>
<testcase classname="Render Render should render component with value in Host" name="Render Render should render component with value in Host" time="0.004">
</testcase>
>>>>>>> tpise
<testcase classname="Render Render should render component with value in Database" name="Render Render should render component with value in Database" time="0.003">
<testcase classname="Render Render should render component with value in Database" name="Render Render should render component with value in Database" time="0.004">
</testcase>
<testcase classname="Render Render should render component with value in User" name="Render Render should render component with value in User" time="0.004">
</testcase>
<testcase classname="Render Render should render component with value in Password" name="Render Render should render component with value in Password" time="0.003">
</testcase>
<testcase classname="Render Render should render component with value in SSL" name="Render Render should render component with value in SSL" time="0.004">
<testcase classname="Render Render should render component with value in SSL" name="Render Render should render component with value in SSL" time="0.009">
</testcase>
<testcase classname="Render Render should render component with value in setUp" name="Render Render should render component with value in setUp" time="0.009">
</testcase>
<testcase classname="Render Render should render component with value in Vertica Connection" name="Render Render should render component with value in Vertica Connection" time="0.003">
</testcase>
</testsuite>
<testsuite name="Query Editor Test cases" errors="0" failures="0" skipped="0" timestamp="2023-03-15T08:01:11" time="0.37" tests="10">
<testsuite name="Query Editor Test cases" errors="0" failures="0" skipped="0" timestamp="2023-03-15T10:54:03" time="0.385" tests="10">
<testcase classname="Query Editor Test cases should handle minimal query" name="Query Editor Test cases should handle minimal query" time="0.001">
</testcase>
<testcase classname="Query Editor Test cases should handle minimal query with rawQuery on" name="Query Editor Test cases should handle minimal query with rawQuery on" time="0">
Expand All @@ -43,15 +42,15 @@
<testcase classname="Query Editor Test cases should handle complex query with value in group,select,where with rawQuery On" name="Query Editor Test cases should handle complex query with value in group,select,where with rawQuery On" time="0">
</testcase>
</testsuite>
<testsuite name="undefined" errors="0" failures="0" skipped="0" timestamp="2023-03-15T08:01:11" time="0.339" tests="3">
<testcase classname=" Verifying functionality of unwrap function keeping value null" name=" Verifying functionality of unwrap function keeping value null" time="0.003">
<testsuite name="undefined" errors="0" failures="0" skipped="0" timestamp="2023-03-15T10:54:04" time="0.331" tests="3">
<testcase classname=" Verifying functionality of unwrap function keeping value null" name=" Verifying functionality of unwrap function keeping value null" time="0.002">
</testcase>
<testcase classname=" Verifying functionality of unwrap function keeping value undefined" name=" Verifying functionality of unwrap function keeping value undefined" time="0.001">
</testcase>
<testcase classname=" Verifying functionality of unwrap function passing numeric value" name=" Verifying functionality of unwrap function passing numeric value" time="0">
<testcase classname=" Verifying functionality of unwrap function passing numeric value" name=" Verifying functionality of unwrap function passing numeric value" time="0.001">
</testcase>
</testsuite>
<testsuite name="undefined" errors="0" failures="0" skipped="0" timestamp="2023-03-15T08:01:11" time="0.309" tests="1">
<testsuite name="undefined" errors="0" failures="0" skipped="0" timestamp="2023-03-15T10:54:04" time="0.309" tests="1">
<testcase classname=" Checking working functionality of toSelectableValue function" name=" Checking working functionality of toSelectableValue function" time="0.001">
</testcase>
</testsuite>
Expand Down
34 changes: 4 additions & 30 deletions pkg/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -57,7 +54,6 @@ func newDatasource() datasource.ServeOpts {
ds := &VerticaDatasource{
im: im,
}

return datasource.ServeOpts{
QueryDataHandler: ds,
CheckHealthHandler: ds,
Expand All @@ -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"`
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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{
Expand All @@ -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{
Expand Down

0 comments on commit 040c4ce

Please sign in to comment.