Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-625282: Make logrus dependency optional or drop it all together #1286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func authenticate(
params.Add("roleName", sc.cfg.Role)
}

logger.WithContext(ctx).WithContext(sc.ctx).Infof("PARAMS for Auth: %v, %v, %v, %v, %v, %v",
logger.WithContext(ctx, sc.ctx).Infof("PARAMS for Auth: %v, %v, %v, %v, %v, %v",
params, sc.rest.Protocol, sc.rest.Host, sc.rest.Port, sc.rest.LoginTimeout, sc.cfg.Authenticator.String())

respd, err := sc.rest.FuncPostAuth(ctx, sc.rest, sc.rest.getClientFor(sc.cfg.Authenticator), params, headers, bodyCreator, sc.rest.LoginTimeout)
Expand Down
4 changes: 2 additions & 2 deletions chunk_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ func (scd *snowflakeChunkDownloader) checkErrorRetry() (err error) {
},
)
scd.ChunksErrorCounter++
logger.WithContext(scd.ctx).Warningf("chunk idx: %v, err: %v. retrying (%v/%v)...",
logger.WithContext(scd.ctx).Warn("chunk idx: %v, err: %v. retrying (%v/%v)...",
errc.Index, errc.Error, scd.ChunksErrorCounter, maxChunkDownloaderErrorCounter)
} else {
scd.ChunksFinalErrors = append(scd.ChunksFinalErrors, errc)
logger.WithContext(scd.ctx).Warningf("chunk idx: %v, err: %v. no further retry", errc.Index, errc.Error)
logger.WithContext(scd.ctx).Warn("chunk idx: %v, err: %v. no further retry", errc.Index, errc.Error)
return errc.Error
}
default:
Expand Down
12 changes: 5 additions & 7 deletions ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ func TestCtxVal(t *testing.T) {
}
}

func TestLogEntryCtx(t *testing.T) {
func TestLogCtx(t *testing.T) {
var log = logger
var ctx1 = context.WithValue(context.Background(), SFSessionIDKey, "sessID1")
var ctx2 = context.WithValue(context.Background(), SFSessionUserKey, "admin")

fs1 := context2Fields(ctx1)
fs2 := context2Fields(ctx2)
l1 := log.WithFields(*fs1)
l2 := log.WithFields(*fs2)
l1.Info("Hello 1")
l2.Warning("Hello 2")
l := log.WithContext(ctx1, ctx2)
l.Info("Hello 1")
l.Warn("Hello 2")
// what purpose does this test serve? ... nothing is being validated except that it compiles and runs.
}
29 changes: 29 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/rsa"
"database/sql"
"database/sql/driver"
"encoding/json"
"flag"
"fmt"
"net/http"
Expand Down Expand Up @@ -50,11 +51,16 @@ const (
// Optionally you may specify SNOWFLAKE_TEST_PROTOCOL, SNOWFLAKE_TEST_HOST
// and SNOWFLAKE_TEST_PORT to specify the endpoint.
func init() {
params := parseParameters("parameters.json", "testconnection")

// get environment variables
env := func(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
if value, ok := params[key].(string); ok && value != "" {
return value
}
Comment on lines +54 to +63
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is not necessary for the PR but it does allow parameters to be read from the json file as per the README.

return defaultValue
}
username = env("SNOWFLAKE_TEST_USER", "testuser")
Expand All @@ -81,6 +87,29 @@ func init() {
debugMode, _ = strconv.ParseBool(os.Getenv("SNOWFLAKE_TEST_DEBUG"))
}

// parseParameters parses a parameters file returning the obj named objname as a map.
func parseParameters(nm string, objname string) map[string]any {
m := make(map[string]any)
b, err := os.ReadFile(nm)
if err != nil {
fmt.Printf("ignoring parameters file %s: err=%v\n", nm, err)
return m
}
err = json.Unmarshal(b, &m)
if err != nil {
fmt.Printf("invalid json in parameters file %s: err=%v\n", nm, err)
}
v, ok := m[objname]
if !ok {
return m
}
p, ok := v.(map[string]any)
if ok {
return p
}
return m
}

func createDSN(timezone string) {
dsn = fmt.Sprintf("%s:%s@%s/%s/%s", username, pass, host, dbname, schemaname)

Expand Down
1 change: 0 additions & 1 deletion easy_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func TestLogToConfiguredFile(t *testing.T) {

logger.Error("Error message")
logger.Warn("Warning message")
logger.Warning("Warning message")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning is basically an alias for Warn so removing it since it clutters the interface otherwise.

logger.Info("Info message")
logger.Trace("Trace message")

Expand Down
Loading
Loading