Skip to content

Commit

Permalink
SNOW-625282: Make logrus dependency optional or drop it all together
Browse files Browse the repository at this point in the history
  • Loading branch information
rickr-sigma committed Jan 6, 2025
1 parent 8257f91 commit 0bc7382
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 327 deletions.
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
}
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")
logger.Info("Info message")
logger.Trace("Trace message")

Expand Down
Loading

0 comments on commit 0bc7382

Please sign in to comment.