From 25e8927279a04903c820889fc433e11e06009dc9 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Tue, 6 May 2025 14:54:04 +0800 Subject: [PATCH 1/6] Minor test updates --- .github/workflows/streaming-jakarta.yaml | 2 +- .github/workflows/streaming.yaml | 2 +- coherence/processors/processors.go | 3 +-- test/e2e/perf/suite_test.go | 3 ++- test/e2e/queues/queues_test.go | 7 +------ test/e2e/streaming/streaming_test.go | 4 +--- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.github/workflows/streaming-jakarta.yaml b/.github/workflows/streaming-jakarta.yaml index 1a42720..05ec77d 100644 --- a/.github/workflows/streaming-jakarta.yaml +++ b/.github/workflows/streaming-jakarta.yaml @@ -65,7 +65,7 @@ jobs: with: go-version: '${{ matrix.go-version }}' - - name: Verify Examples + - name: Verify shell: bash run: | go get google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0 diff --git a/.github/workflows/streaming.yaml b/.github/workflows/streaming.yaml index 370ac41..a9a36ae 100644 --- a/.github/workflows/streaming.yaml +++ b/.github/workflows/streaming.yaml @@ -66,7 +66,7 @@ jobs: with: go-version: '${{ matrix.go-version }}' - - name: Verify Examples + - name: Verify shell: bash run: | go get google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0 diff --git a/coherence/processors/processors.go b/coherence/processors/processors.go index bbae06c..43aab71 100644 --- a/coherence/processors/processors.go +++ b/coherence/processors/processors.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -15,7 +15,6 @@ import ( const ( processorPrefix = "processor." extractorPrefix = "extractor." - queuePrefix = "internal.net.queue.processor." compositeProcessorType = processorPrefix + "CompositeProcessor" conditionalProcessorType = processorPrefix + "ConditionalProcessor" diff --git a/test/e2e/perf/suite_test.go b/test/e2e/perf/suite_test.go index 27944cd..eb07c4e 100644 --- a/test/e2e/perf/suite_test.go +++ b/test/e2e/perf/suite_test.go @@ -155,7 +155,8 @@ func InitializeCoherence(ctx context.Context, address string) (Config, error) { ) // create a new Session to the default gRPC port of 1408 using plain text - config.Session, err = coherence.NewSession(ctx, coherence.WithPlainText(), coherence.WithAddress(address)) + config.Session, err = coherence.NewSession(ctx, coherence.WithPlainText(), coherence.WithAddress(address), + coherence.WithRequestTimeout(300*time.Minute)) if err != nil { return config, err } diff --git a/test/e2e/queues/queues_test.go b/test/e2e/queues/queues_test.go index 185a417..93cf978 100644 --- a/test/e2e/queues/queues_test.go +++ b/test/e2e/queues/queues_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Oracle and/or its affiliates. + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -455,11 +455,6 @@ func runTestQueueCompatability(g *gomega.WithT, queueName string, firstQueueType g.Expect(queue.Destroy(ctx)).ShouldNot(gomega.HaveOccurred()) utils.Sleep(5) - - //g.Expect(errorOccurred).To(gomega.Equal(shouldError)) - //if !shouldError { - // g.Expect(queue.Destroy(ctx)).ShouldNot(gomega.HaveOccurred()) - //} } func testQueue(ctx context.Context, g *gomega.WithT, queue coherence.NamedQueue[string]) { diff --git a/test/e2e/streaming/streaming_test.go b/test/e2e/streaming/streaming_test.go index 58bff54..f7c7a02 100644 --- a/test/e2e/streaming/streaming_test.go +++ b/test/e2e/streaming/streaming_test.go @@ -48,8 +48,6 @@ var ( func TestStreamingConcurrency(t *testing.T) { g := gomega.NewWithT(t) - _ = os.Setenv("COHERENCE_CLIENT_REQUEST_TIMEOUT", "300000") - osCacheCount := os.Getenv("COHERENCE_CACHE_COUNT") if os.Getenv(osCacheCount) != "" { v, err := strconv.Atoi(osCacheCount) @@ -58,7 +56,7 @@ func TestStreamingConcurrency(t *testing.T) { } } - session, err := utils.GetSession() + session, err := utils.GetSession(coherence.WithRequestTimeout(5 * time.Minute)) g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() From 1c217cf2a6c3ba7c9700240739c5a09ddfb0d59e Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Mon, 12 May 2025 13:50:07 +0800 Subject: [PATCH 2/6] Improve the way the Go client logs messages --- Makefile | 2 +- README.md | 2 +- coherence/common.go | 11 +++-- coherence/doc.go | 21 ++++++++ coherence/named_map_client.go | 9 ++-- coherence/resolver.go | 7 ++- coherence/session.go | 70 ++++++++++++++++++++------- coherence/session_test.go | 5 +- coherence/v1client.go | 40 +++++++++++---- test/e2e/queues/queues_test.go | 3 -- test/e2e/resolver/run_test.go | 4 +- test/e2e/resolver_cluster/run_test.go | 4 +- test/e2e/standalone/event_test.go | 8 +-- test/e2e/standalone/filter_test.go | 5 +- test/e2e/standalone/named_map_test.go | 4 +- test/e2e/standalone/session_test.go | 4 +- test/v1/base/base_test.go | 5 +- 17 files changed, 134 insertions(+), 70 deletions(-) diff --git a/Makefile b/Makefile index 33a0df4..13295a9 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ # ---------------------------------------------------------------------------------------------------------------------- # This is the version of the coherence-go-client -VERSION ?=2.1.0 +VERSION ?=2.1.1 CURRDIR := $(shell pwd) USER_ID := $(shell echo "`id -u`:`id -g`") diff --git a/README.md b/README.md index ea0d30d..a97dca1 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ For local development, we recommend using the Coherence CE Docker image; it cont everything necessary for the client to operate correctly. ```bash -docker run -d -p 1408:1408 -p 30000:30000 ghcr.io/oracle/coherence-ce:24.09.3 +docker run -d -p 1408:1408 -p 30000:30000 ghcr.io/oracle/coherence-ce:25.03.1 ``` ## Installation diff --git a/coherence/common.go b/coherence/common.go index 45c0f38..5b8a278 100644 --- a/coherence/common.go +++ b/coherence/common.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -35,13 +35,13 @@ const ( envDisconnectTimeout = "COHERENCE_SESSION_DISCONNECT_TIMEOUT" envReadyTimeout = "COHERENCE_READY_TIMEOUT" - // envSessionDebug enables session debug messages to be displayed. + // envSessionDebug enables session debug messages to be displayed. Deprecated, use COHERENCE_LOG_LEVEL=DEBUG instead. envSessionDebug = "COHERENCE_SESSION_DEBUG" - // envMessageDebug enables message debug messages to be displayed. + // envMessageDebug enables message debug messages to be displayed. Deprecated, use COHERENCE_LOG_LEVEL=ALL instead. envMessageDebug = "COHERENCE_MESSAGE_DEBUG" - // envResolverDebug enables resolver debug messages to be displayed. + // envResolverDebug enables resolver debug messages to be displayed. Deprecated, use COHERENCE_LOG_LEVEL=DEBUG instead. envResolverDebug = "COHERENCE_RESOLVER_DEBUG" // envResolverDebug sets the number of retries when the resolver fails. @@ -50,6 +50,9 @@ const ( // envResolverDebug enables randomization of addresses returned by resolver envResolverRandomize = "COHERENCE_RESOLVER_RANDOMIZE" + // the Coherence log level: 0 -> 5 + envLogLevel = "COHERENCE_LOG_LEVEL" + // Integer.MAX_VALUE on Java integerMaxValue = 2147483647 diff --git a/coherence/doc.go b/coherence/doc.go index 751c4c0..d95337f 100644 --- a/coherence/doc.go +++ b/coherence/doc.go @@ -99,6 +99,27 @@ You also have the ability to control maximum amount of time, in milliseconds, a without successfully reconnecting. For this you use the option [coherence.WithDisconnectTimeout] or the environment variable COHERENCE_SESSION_DISCONNECT_TIMEOUT. +# Setting Log Levels + +The Coherence Go client supports setting the following log levels to change verbosity of messages output. +The default level is 'INFO' and this can be changed by setting the environment variable COHERENCE_LOG_LEVEL to one of the following values: + +- ERROR + +- WARNING + +- INFO + +- DEBUG + +- ALL + +All messages at and above the level are displayed. For example setting to WARNING will only show ERROR and WARNING messages. +Where as setting DEBUG, will show ERROR, WARNING, INFO and DEBUG messages. + +Note: Setting to ALL should only be used to diagnose issues as directed by Oracle Support. This level will +output a large volume of messages. + # Obtaining a NamedMap or NamedCache Once a session has been created, the [GetNamedMap](session, name, ...options) or [GetNamedCache](session, name, ...options) diff --git a/coherence/named_map_client.go b/coherence/named_map_client.go index 4b21ab2..d783c9a 100644 --- a/coherence/named_map_client.go +++ b/coherence/named_map_client.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -14,7 +14,6 @@ import ( "github.com/oracle/coherence-go-client/v2/coherence/extractors" "github.com/oracle/coherence-go-client/v2/coherence/filters" "github.com/oracle/coherence-go-client/v2/coherence/processors" - "log" "sync" "time" ) @@ -456,7 +455,7 @@ func (nm *NamedMapClient[K, V]) Release() { if nm.baseClient.nearCacheListener != nil { err := nm.RemoveListener(context.Background(), nm.baseClient.nearCacheListener.listener) if err != nil { - log.Printf("unable to remove listener to near cache: %v", err) + logMessage(WARNING, "unable to remove listener to near cache: %v", err) } } @@ -995,7 +994,7 @@ func newNamedMapReconnectListener[K comparable, V any](nm NamedMapClient[K, V]) // re-register listeners for the NamedMap namedMap := convertNamedMapClient[K, V](&nm) if err := reRegisterListeners[K, V](context.Background(), &namedMap, nm.baseClient); err != nil { - log.Println(err) + logMessage(WARNING, "unable to re-register listeners: %v", err) } }) @@ -1057,7 +1056,7 @@ func newNearNamedMapMapLister[K comparable, V any](nc NamedMapClient[K, V], cach listener.listener.OnAny(func(e MapEvent[K, V]) { err := processNearCacheEvent(nc.baseClient.nearCache, e) if err != nil { - log.Println("Error processing near cache MapEvent", e) + logMessage(WARNING, "Error processing near cache MapEvent: %v", e) } }) diff --git a/coherence/resolver.go b/coherence/resolver.go index 67b4b9b..7531a72 100644 --- a/coherence/resolver.go +++ b/coherence/resolver.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -219,10 +219,13 @@ func parseNsLookupString(addresses string) ([]string, error) { } func checkResolverDebug() { - if getBoolValueFromEnvVarOrDefault(envResolverDebug, false) { + if getBoolValueFromEnvVarOrDefault(envResolverDebug, false) || currentLogLevel >= int(DEBUG) { // enable session debugging resolverDebug = func(s string, v ...any) { logMessage(DEBUG, s, v...) } + if currentLogLevel <= int(DEBUG) { + currentLogLevel = int(DEBUG) + } } } diff --git a/coherence/session.go b/coherence/session.go index e1065e5..8e31ff3 100644 --- a/coherence/session.go +++ b/coherence/session.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/resolver" "google.golang.org/grpc/status" - "log" "os" "reflect" "strconv" @@ -72,9 +71,8 @@ type Session struct { connectMutex sync.RWMutex // mutes for connection attempts firstConnectAttempted bool // indicates if the first connection has been attempted hasConnected bool // indicates if the session has ever connected - debug func(string, ...any) // a function to output debug messages - debugConnection func(string, ...any) // a function to output debug messages for gRPCV1 connections - messageDebugMode string // either "on" or "full" + debug func(string, ...any) // a function to output DEBUG messages + debugConnection func(string, ...any) // a function to output ALL messages for gRPCV1 connections requestID int64 // request id for gRPC v1 filterID int64 // filter id for gRPC v1 v1StreamManagerCache *streamManagerV1 @@ -192,24 +190,26 @@ func NewSession(ctx context.Context, options ...func(session *SessionOptions)) ( // ensure name resolver has been registered resolver.Register(&nsLookupResolverBuilder{}) - if getBoolValueFromEnvVarOrDefault(envSessionDebug, false) { + // set the coherenceLogLevel + setLogLevel() + + if getBoolValueFromEnvVarOrDefault(envSessionDebug, false) || currentLogLevel >= int(DEBUG) { // enable session debugging session.debug = func(format string, v ...any) { logMessage(DEBUG, format, v...) } + if currentLogLevel <= int(DEBUG) { + currentLogLevel = int(DEBUG) + } } messageDebug := getStringValueFromEnvVarOrDefault(envMessageDebug, "") - if messageDebug != "" { + if messageDebug != "" || currentLogLevel == int(ALL) { // enable session debugging session.debugConnection = func(s string, v ...any) { - msg := getLogMessage(DEBUG, s, v...) - if session.messageDebugMode == "on" && len(msg) > 256 { - msg = msg[:256] - } - log.Println(msg) + logMessage(DEBUG, s, v...) } - session.messageDebugMode = messageDebug + currentLogLevel = int(ALL) } // apply any options @@ -257,6 +257,40 @@ func NewSession(ctx context.Context, options ...func(session *SessionOptions)) ( return session, session.ensureConnection() } +// setLogLevel sets the log level from the COHERENCE_LOG_LEVEL environment variable. +func setLogLevel() { + var ( + level int + envLevel = getStringValueFromEnvVarOrDefault(envLogLevel, "3") + ) + + // try to convert from integer first + if lvl, err := strconv.Atoi(envLevel); err == nil { + if lvl >= 1 && lvl <= 5 { + currentLogLevel = lvl + return + } + } + + // fall-through, check for string values + switch envLevel { + case "ERROR": + level = 1 + case "WARNING": + level = 2 + case "INFO": + level = 3 + case "DEBUG": + level = 4 + case "ALL": + level = 5 + default: + level = 3 // INFO + } + + currentLogLevel = level +} + func getTimeoutValue(envVar, defaultValue, description string) (time.Duration, error) { timeoutString := getStringValueFromEnvVarOrDefault(envVar, defaultValue) timeout, err := strconv.ParseInt(timeoutString, 10, 64) @@ -418,7 +452,7 @@ func (s *Session) Close() { return newSessionLifecycleEvent(s, Closed) }) if err != nil { - log.Printf("unable to close session %s %v", s.sessionID, err) + logMessage(WARNING, "unable to close session %s %v", s.sessionID, err) } } else { defer s.mapMutex.Unlock() @@ -753,7 +787,7 @@ func (s *SessionOptions) createTLSOption() (grpc.DialOption, error) { // check if a tls.Config has been set and use this, otherwise continue to check for env and other options if s.TlSConfig != nil { if s.TlSConfig.InsecureSkipVerify { - log.Println(insecureWarning) + logMessage(WARNING, insecureWarning) } return grpc.WithTransportCredentials(credentials.NewTLS(s.TlSConfig)), nil } @@ -774,7 +808,7 @@ func (s *SessionOptions) createTLSOption() (grpc.DialOption, error) { ignoreInvalidCerts := ignoreInvalidCertsEnv == "true" if ignoreInvalidCerts { - log.Println(insecureWarning) + logMessage(WARNING, insecureWarning) } s.IgnoreInvalidCerts = ignoreInvalidCerts @@ -801,7 +835,7 @@ func (s *SessionOptions) createTLSOption() (grpc.DialOption, error) { if s.CaCertPath != "" { cp = x509.NewCertPool() - log.Println("loading CA certificate") + logMessage(DEBUG, "loading CA certificate") if err = validateFilePath(s.CaCertPath); err != nil { return nil, err } @@ -817,7 +851,7 @@ func (s *SessionOptions) createTLSOption() (grpc.DialOption, error) { } if s.ClientCertPath != "" && s.ClientKeyPath != "" { - log.Println("loading client certificate and key, cert=", s.ClientCertPath, "key=", s.ClientKeyPath) + logMessage(DEBUG, "loading client certificate and key paths, cert=%s, key=%s", s.ClientCertPath, s.ClientKeyPath) if err = validateFilePath(s.ClientCertPath); err != nil { return nil, err } diff --git a/coherence/session_test.go b/coherence/session_test.go index 04b620d..62b66c3 100644 --- a/coherence/session_test.go +++ b/coherence/session_test.go @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022, 2024 Oracle and/or its affiliates. +* Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -9,7 +9,6 @@ package coherence import ( "context" "github.com/onsi/gomega" - "os" "strconv" "testing" "time" @@ -22,8 +21,6 @@ func TestSessionValidation(t *testing.T) { ctx = context.Background() ) - os.Setenv("COHERENCE_SESSION_DEBUG", "true") - _, err = NewSession(ctx, WithFormat("not-json")) g.Expect(err).To(gomega.Equal(ErrInvalidFormat)) diff --git a/coherence/v1client.go b/coherence/v1client.go index de65bad..66b15e3 100644 --- a/coherence/v1client.go +++ b/coherence/v1client.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -26,15 +26,17 @@ import ( // V1ProxyProtocol defines the types of proxy protocols such as "CacheService" or "QueueService". type V1ProxyProtocol string -type logLevel string +type logLevel int var ( - INFO logLevel = "INFO:" - WARNING logLevel = "WARN:" - ERROR logLevel = "ERROR:" - DEBUG logLevel = "DEBUG:" - RCV = "RCV" - SND = "SND" + ERROR logLevel = 1 + WARNING logLevel = 2 + INFO logLevel = 3 // Default + DEBUG logLevel = 4 + ALL logLevel = 5 // all messages + + // current log level + currentLogLevel int ) const ( @@ -234,14 +236,34 @@ func (m *streamManagerV1) processResponseMessage(id int64, resp *responseMessage m.processResponse(id, resp) } +// logMessage logs a message only if the level <= currentLogLevel func logMessage(level logLevel, format string, args ...any) { - log.Println(getLogMessage(level, format, args...)) + if int(level) <= currentLogLevel { + log.Println(getLogMessage(level, format, args...)) + } } func getLogMessage(level logLevel, format string, args ...any) string { return fmt.Sprintf("%v ", level) + fmt.Sprintf(format, args...) } +func (l logLevel) String() string { + switch l { + case ERROR: + return "ERROR" + case WARNING: + return "WARNING" + case INFO: + return "INFO" + case DEBUG: + return "DEBUG" + case ALL: + return "DEBUG" + default: + return fmt.Sprintf("logLevel(%d)", int(l)) + } +} + func (m *streamManagerV1) setServerInfo(r *pb1.InitResponse) { m.serverVersion = r.GetVersion() m.serverProtocolVersion = r.GetProtocolVersion() diff --git a/test/e2e/queues/queues_test.go b/test/e2e/queues/queues_test.go index 93cf978..de17250 100644 --- a/test/e2e/queues/queues_test.go +++ b/test/e2e/queues/queues_test.go @@ -639,9 +639,6 @@ func TestQueueDestroy(t *testing.T) { g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() - t.Setenv("COHERENCE_SESSION_DEBUG", "true") - t.Setenv("COHERENCE_MESSAGE_DEBUG", "true") - runTestQueueDestroy(g, session, "destroy-q", coherence.Queue) runTestQueueDestroy(g, session, "destroy-paged-q", coherence.PagedQueue) runTestQueueDestroy(g, session, "destroy-dq", coherence.Dequeue) diff --git a/test/e2e/resolver/run_test.go b/test/e2e/resolver/run_test.go index 062db30..d2ce5f8 100644 --- a/test/e2e/resolver/run_test.go +++ b/test/e2e/resolver/run_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -33,7 +33,7 @@ func TestNsLookupGrpcAddresses(t *testing.T) { func TestConnectingUsingNSResolver(t *testing.T) { g := gomega.NewGomegaWithT(t) ctx := context.Background() - t.Setenv("COHERENCE_RESOLVER_DEBUG", "true") + t.Setenv("COHERENCE_LOG_LEVEL", "DEBUG") session, err := coherence.NewSession(ctx, coherence.WithPlainText(), coherence.WithAddress("coherence:///localhost:7574")) g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) diff --git a/test/e2e/resolver_cluster/run_test.go b/test/e2e/resolver_cluster/run_test.go index 3ec7cb9..5eb130c 100644 --- a/test/e2e/resolver_cluster/run_test.go +++ b/test/e2e/resolver_cluster/run_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -44,7 +44,7 @@ func TestNsLookupGrpcAddressesMultipleClusters(t *testing.T) { func TestConnectingUsingNSResolverMultipleClusters(t *testing.T) { g := gomega.NewGomegaWithT(t) ctx := context.Background() - t.Setenv("COHERENCE_RESOLVER_DEBUG", "true") + t.Setenv("COHERENCE_LOG_LEVEL", "DEBUG") session, err := coherence.NewSession(ctx, coherence.WithPlainText(), coherence.WithAddress("coherence:///localhost:7574/cluster2")) g.Expect(err).To(gomega.Not(gomega.HaveOccurred())) diff --git a/test/e2e/standalone/event_test.go b/test/e2e/standalone/event_test.go index e952de4..41cfd5c 100644 --- a/test/e2e/standalone/event_test.go +++ b/test/e2e/standalone/event_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -140,8 +140,6 @@ func TestExpiringEvents(t *testing.T) { // TestEventDisconnect tests to ensure that if we get a disconnect, then we can rec-connect and // re-register event listeners. func TestEventDisconnect(t *testing.T) { - t.Setenv("COHERENCE_SESSION_DEBUG", "true") - g, session := initTest(t, coherence.WithDisconnectTimeout(time.Duration(130)*time.Second), coherence.WithReadyTimeout(time.Duration(130)*time.Second)) @@ -164,8 +162,6 @@ func TestEventDisconnect(t *testing.T) { // TestEventDisconnectWithReadyTimeoutDelay tests that the ready timeout is honoured, // as we have stopped the gRPC proxy before the test runs. func TestEventDisconnectWithReadyTimeoutDelay(t *testing.T) { - t.Setenv("COHERENCE_SESSION_DEBUG", "true") - fmt.Println("Issue stop of $GRPC:GrpcProxy") _, err := utils.IssuePostRequest("http://127.0.0.1:30000/management/coherence/cluster/services/$GRPC:GrpcProxy/members/1/stop") if err != nil { @@ -190,8 +186,6 @@ func TestEventDisconnectWithReadyTimeoutDelay(t *testing.T) { func TestMapEventInsertsOnly(t *testing.T) { expectedA := "A" - t.Setenv("COHERENCE_SESSION_DEBUG", "true") - t.Setenv("COHERENCE_MESSAGE_DEBUG", "true") expected := ExpectedEvents[string, string]{ inserts: []*ValidateEvent[string, string]{ diff --git a/test/e2e/standalone/filter_test.go b/test/e2e/standalone/filter_test.go index 5ca34ad..3c0dc42 100644 --- a/test/e2e/standalone/filter_test.go +++ b/test/e2e/standalone/filter_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024 Oracle and/or its affiliates. + * Copyright (c) 2023, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -207,9 +207,6 @@ func TestFiltersAgainstMapAndCache(t *testing.T) { func TestPresentFilter(t *testing.T) { g := gomega.NewWithT(t) - t.Setenv("COHERENCE_SESSION_DEBUG", "true") - t.Setenv("COHERENCE_GRPCV1_DEBUG", "true") - session, err := utils.GetSession() g.Expect(err).ShouldNot(gomega.HaveOccurred()) defer session.Close() diff --git a/test/e2e/standalone/named_map_test.go b/test/e2e/standalone/named_map_test.go index 45daa38..b3c6d3a 100644 --- a/test/e2e/standalone/named_map_test.go +++ b/test/e2e/standalone/named_map_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024 Oracle and/or its affiliates. + * Copyright (c) 2022, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -54,7 +54,6 @@ func TestBasicCrudOperationsVariousTypes(t *testing.T) { err error session *coherence.Session ) - t.Setenv("COHERENCE_SESSION_DEBUG", "true") session, err = utils.GetSession() g.Expect(err).ShouldNot(gomega.HaveOccurred()) @@ -215,7 +214,6 @@ func RunTestInvocationTimeout(g *gomega.WithT, namedMap coherence.NamedMap[int, // TestBasicOperationsAgainstMapAndCache runs all tests against NamedMap and NamedCache. func TestBasicOperationsAgainstMapAndCache(t *testing.T) { g := gomega.NewWithT(t) - t.Setenv("COHERENCE_SESSION_DEBUG", "true") session, err := utils.GetSession() g.Expect(err).ShouldNot(gomega.HaveOccurred()) diff --git a/test/e2e/standalone/session_test.go b/test/e2e/standalone/session_test.go index 0b1bd7b..29fe8fa 100644 --- a/test/e2e/standalone/session_test.go +++ b/test/e2e/standalone/session_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024 Oracle and/or its affiliates. + * Copyright (c) 2023, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -19,7 +19,7 @@ import ( func TestSessionLifecycle(t *testing.T) { g := gomega.NewWithT(t) - t.Setenv("COHERENCE_SESSION_DEBUG", "true") + t.Setenv("COHERENCE_LOG_LEVEL", "DEBUG") session, err := utils.GetSession() g.Expect(err).ShouldNot(gomega.HaveOccurred()) diff --git a/test/v1/base/base_test.go b/test/v1/base/base_test.go index 3149e07..a463855 100644 --- a/test/v1/base/base_test.go +++ b/test/v1/base/base_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Oracle and/or its affiliates. + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. * Licensed under the Universal Permissive License v 1.0 as shown at * https://oss.oracle.com/licenses/upl. */ @@ -887,8 +887,7 @@ func assertSize(g *gomega.WithT, session *coherence.Session, cache string, expec } func getTestSession(t *testing.T, g *gomega.WithT) *coherence.Session { - t.Setenv("COHERENCE_SESSION_DEBUG", "true") - t.Setenv("COHERENCE_MESSAGE_DEBUG", "true") + t.Setenv("COHERENCE_LOG_LEVEL", "ALL") t.Setenv("COHERENCE_CLIENT_REQUEST_TIMEOUT", "120000") session, err := utils.GetSession() From c4b03fa0c802d748dbb8571b99cb7cda676eb094 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Mon, 12 May 2025 13:52:58 +0800 Subject: [PATCH 3/6] Minor comment --- coherence/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coherence/common.go b/coherence/common.go index 5b8a278..2e58658 100644 --- a/coherence/common.go +++ b/coherence/common.go @@ -50,7 +50,7 @@ const ( // envResolverDebug enables randomization of addresses returned by resolver envResolverRandomize = "COHERENCE_RESOLVER_RANDOMIZE" - // the Coherence log level: 0 -> 5 + // the Coherence log level: 1 -> 5 (ERROR -> ALL) envLogLevel = "COHERENCE_LOG_LEVEL" // Integer.MAX_VALUE on Java From 1804c69de501164d95db71312b4206c407023886 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Mon, 12 May 2025 14:19:31 +0800 Subject: [PATCH 4/6] Add test for log levels --- coherence/log_level_test.go | 67 +++++++++++++++++++++++++++++++++++++ coherence/session.go | 9 ++--- coherence/v1client.go | 2 +- 3 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 coherence/log_level_test.go diff --git a/coherence/log_level_test.go b/coherence/log_level_test.go new file mode 100644 index 0000000..bf6777e --- /dev/null +++ b/coherence/log_level_test.go @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 Oracle and/or its affiliates. + * Licensed under the Universal Permissive License v 1.0 as shown at + * https://oss.oracle.com/licenses/upl. + */ + +package coherence + +import ( + "bytes" + "github.com/onsi/gomega" + "log" + "testing" +) + +func TestErrorLogLevel(t *testing.T) { + runLogLevelTest(t, ERROR, ERROR, true) + runLogLevelTest(t, WARNING, ERROR, false) + runLogLevelTest(t, INFO, ERROR, false) + runLogLevelTest(t, DEBUG, ERROR, false) + runLogLevelTest(t, ALL, ERROR, false) + + runLogLevelTest(t, ERROR, WARNING, true) + runLogLevelTest(t, WARNING, WARNING, true) + runLogLevelTest(t, INFO, WARNING, false) + runLogLevelTest(t, DEBUG, WARNING, false) + runLogLevelTest(t, ALL, WARNING, false) + + runLogLevelTest(t, ERROR, INFO, true) + runLogLevelTest(t, WARNING, INFO, true) + runLogLevelTest(t, INFO, INFO, true) + runLogLevelTest(t, DEBUG, INFO, false) + runLogLevelTest(t, ALL, INFO, false) + + runLogLevelTest(t, ERROR, DEBUG, true) + runLogLevelTest(t, WARNING, DEBUG, true) + runLogLevelTest(t, INFO, DEBUG, true) + runLogLevelTest(t, DEBUG, DEBUG, true) + runLogLevelTest(t, ALL, DEBUG, false) + + runLogLevelTest(t, ERROR, ALL, true) + runLogLevelTest(t, WARNING, ALL, true) + runLogLevelTest(t, INFO, ALL, true) + runLogLevelTest(t, DEBUG, ALL, true) + runLogLevelTest(t, ALL, ALL, true) +} + +func runLogLevelTest(t *testing.T, messageLevel, testLogLevel logLevel, expectOutput bool) { + g := gomega.NewWithT(t) + const message = "MESSAGE" + + var buf bytes.Buffer + log.SetOutput(&buf) + defer log.SetOutput(nil) + + setLogLevel(testLogLevel.String()) + + logMessage(messageLevel, message) + output := buf.String() + + if expectOutput { + g.Expect(output).To(gomega.ContainSubstring(message)) + } else { + g.Expect(output).To(gomega.Not(gomega.ContainSubstring(message))) + } + +} diff --git a/coherence/session.go b/coherence/session.go index 8e31ff3..e4bcaca 100644 --- a/coherence/session.go +++ b/coherence/session.go @@ -191,7 +191,7 @@ func NewSession(ctx context.Context, options ...func(session *SessionOptions)) ( resolver.Register(&nsLookupResolverBuilder{}) // set the coherenceLogLevel - setLogLevel() + setLogLevel(getStringValueFromEnvVarOrDefault(envLogLevel, "3")) if getBoolValueFromEnvVarOrDefault(envSessionDebug, false) || currentLogLevel >= int(DEBUG) { // enable session debugging @@ -258,11 +258,8 @@ func NewSession(ctx context.Context, options ...func(session *SessionOptions)) ( } // setLogLevel sets the log level from the COHERENCE_LOG_LEVEL environment variable. -func setLogLevel() { - var ( - level int - envLevel = getStringValueFromEnvVarOrDefault(envLogLevel, "3") - ) +func setLogLevel(envLevel string) { + var level int // try to convert from integer first if lvl, err := strconv.Atoi(envLevel); err == nil { diff --git a/coherence/v1client.go b/coherence/v1client.go index 66b15e3..e33a883 100644 --- a/coherence/v1client.go +++ b/coherence/v1client.go @@ -258,7 +258,7 @@ func (l logLevel) String() string { case DEBUG: return "DEBUG" case ALL: - return "DEBUG" + return "ALL" default: return fmt.Sprintf("logLevel(%d)", int(l)) } From f76c55a378d76a00e6d75277a985d281160b7ee4 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Mon, 12 May 2025 14:26:28 +0800 Subject: [PATCH 5/6] Correctly reset log writer --- coherence/log_level_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/coherence/log_level_test.go b/coherence/log_level_test.go index bf6777e..07c1d6c 100644 --- a/coherence/log_level_test.go +++ b/coherence/log_level_test.go @@ -50,9 +50,10 @@ func runLogLevelTest(t *testing.T, messageLevel, testLogLevel logLevel, expectOu const message = "MESSAGE" var buf bytes.Buffer - log.SetOutput(&buf) - defer log.SetOutput(nil) + origOutput := log.Writer() + log.SetOutput(&buf) + defer log.SetOutput(origOutput) setLogLevel(testLogLevel.String()) logMessage(messageLevel, message) @@ -63,5 +64,4 @@ func runLogLevelTest(t *testing.T, messageLevel, testLogLevel logLevel, expectOu } else { g.Expect(output).To(gomega.Not(gomega.ContainSubstring(message))) } - } From d07b04a1e3aff927f25d3bdffb8ddfbac0c9ae81 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Mon, 12 May 2025 15:02:07 +0800 Subject: [PATCH 6/6] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 13295a9..295c88a 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ # ---------------------------------------------------------------------------------------------------------------------- # This is the version of the coherence-go-client -VERSION ?=2.1.1 +VERSION ?=2.2.0 CURRDIR := $(shell pwd) USER_ID := $(shell echo "`id -u`:`id -g`")