Skip to content

Commit

Permalink
Merge branch 'main' into issue-397
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbroadhurst authored Nov 7, 2024
2 parents ef6a417 + 4ce4dae commit 26cd5aa
Show file tree
Hide file tree
Showing 42 changed files with 194 additions and 158 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/paladin-PR-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ jobs:
- name: Build with Gradle
run: ./gradlew -PcomposeLogs=true -PverboseTests=true --no-daemon --parallel --max-workers=5 build


- name: Upload logs
uses: actions/upload-artifact@v4
if: always()
with:
name: testbed-logs
path: |
**/testbed.*.log
image-build:
runs-on: ubuntu-latest
env:
Expand Down
5 changes: 5 additions & 0 deletions core/go/componenttest/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ blockchain:
ws:
url: ws://localhost:8546
initialConnectAttempts: 25
log:
level: debug
output: file
file:
filename: build/testbed.component-test.log
wallets:
- name: wallet1
keySelector: .*
Expand Down
9 changes: 8 additions & 1 deletion core/go/componenttest/utils_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,14 @@ func newInstanceForComponentTesting(t *testing.T, domainRegistryAddress *tktypes
//i.conf.DB.SQLite.DSN = "./sql." + i.name + ".db"
//uncomment to use postgres - TODO once all tests are using postgres, we can parameterize this and run in both modes
//i.conf.DB.Type = "postgres"
i.conf.Log.Level = confutil.P("debug")
i.conf.Log = pldconf.LogConfig{
Level: confutil.P("debug"),
Output: confutil.P("file"),
File: pldconf.LogFileConfig{
Filename: confutil.P("build/testbed.component-test.log"),
},
}
log.InitConfig(&i.conf.Log)

if i.conf.DB.Type == "postgres" {
dns, cleanUp := initPostgres(t, context.Background())
Expand Down
3 changes: 0 additions & 3 deletions core/go/pkg/blockindexer/block_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/kaleido-io/paladin/toolkit/pkg/query"
"github.com/kaleido-io/paladin/toolkit/pkg/rpcclient"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -117,8 +116,6 @@ func newTestBlockIndexer(t *testing.T) (context.Context, *blockIndexer, *rpcclie
}

func newTestBlockIndexerConf(t *testing.T, config *pldconf.BlockIndexerConfig) (context.Context, *blockIndexer, *rpcclientmocks.WSClient, func()) {
logrus.SetLevel(logrus.DebugLevel)

ctx, cancelCtx := context.WithCancel(context.Background())

p, pDone, err := persistence.NewUnitTestPersistence(ctx, "blockindexer")
Expand Down
3 changes: 0 additions & 3 deletions core/go/pkg/blockindexer/block_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (

"github.com/kaleido-io/paladin/toolkit/pkg/rpcclient"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -54,8 +53,6 @@ func newTestBlockListener(t *testing.T) (context.Context, *blockListener, *rpccl

func newTestBlockListenerConf(t *testing.T, ctx context.Context, config *pldconf.BlockIndexerConfig) (*blockListener, *rpcclientmocks.WSClient) {

logrus.SetLevel(logrus.DebugLevel)

mRPC := rpcclientmocks.NewWSClient(t)

subsChan := make(chan *rpcclient.RPCSubscriptionNotification)
Expand Down
2 changes: 1 addition & 1 deletion core/go/pkg/persistence/testdb_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func NewUnitTestPersistence(ctx context.Context, suite string) (p Persistence, c
DSN: dbDSN(utDBName),
MigrationsDir: migrationsDirRelative,
AutoMigrate: &autoMigrate,
DebugQueries: true,
DebugQueries: false,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion core/go/pkg/persistence/testdb_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewUnitTestPersistence(ctx context.Context, suite string) (Persistence, fun
DSN: ":memory:",
AutoMigrate: confutil.P(true),
MigrationsDir: "../../db/migrations/sqlite",
DebugQueries: true,
DebugQueries: false,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion core/go/pkg/testbed/testbed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ db:
dsn: ":memory:"
autoMigrate: true
migrationsDir: any
debugQueries: true
debugQueries: false
wallets:
- name: wallet1
keySelector: .*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class YamlConfig {

private static final Logger LOGGER = LogManager.getLogger(YamlConfig.class);
Expand Down Expand Up @@ -73,6 +72,7 @@ void setupLogging() {
default -> Level.INFO;
};
Configurator.setAllLevels("io.kaleido.paladin", level);

}

void setupLoaderDebug() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.api.client.json.Json;

@JsonIgnoreProperties(ignoreUnknown = true)
record YamlLogConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright © 2024 Kaleido, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

package io.kaleido.paladin.configlight;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
record YamlLogFileConfig(
@JsonProperty
String filename
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class Testbed implements Closeable {

public record Setup(
String dbMigrationsDir,
String logFile,
long startTimeoutMS
) {
}
Expand Down Expand Up @@ -214,10 +215,14 @@ private String baseConfig() {
debug: true
log:
level: debug
output: file
file:
filename: %s
""".formatted(
new File(testbedSetup.dbMigrationsDir).getAbsolutePath(),
JsonHex.randomBytes32(),
availableRPCPort
availableRPCPort,
new File(testbedSetup.logFile).getAbsolutePath()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void runTestbed() throws Exception {
System.out.println(System.getProperty("java.library.path"));

Testbed testBed = new Testbed(
new Testbed.Setup("../go/db/migrations/sqlite", 5000),
new Testbed.Setup("../go/db/migrations/sqlite", "build/test.java-noop-domain.txt", 5000),
new Testbed.ConfigDomain(
"domain1",
JsonHex.Address.addressFrom("0x1234567890abcdef1234567890abcdef12345678"),
Expand Down
5 changes: 5 additions & 0 deletions domains/integration-test/testbed.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ blockchain:
url: ws://localhost:8546
initialConnectAttempts: 25
shutdownTimeout: 0s
log:
level: debug
output: file
file:
filename: build/testbed.domain-integration-test.log
wallets:
- name: wallet1
keySelector: .*
Expand Down
5 changes: 4 additions & 1 deletion domains/noto/testbed.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ blockchain:
url: ws://localhost:8546
initialConnectAttempts: 25
log:
level: info
level: debug
output: file
file:
filename: build/testbed.domain-noto.log
wallets:
- name: wallet1
keySelector: .*
Expand Down
1 change: 0 additions & 1 deletion domains/pente/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ assemble.dependsOn jar

test {
testLogging {
showStandardStreams = true
testLogging {
events("passed", "skipped", "failed")
showStackTraces = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@

public class BondTest {

private final Testbed.Setup testbedSetup = new Testbed.Setup("../../core/go/db/migrations/sqlite", 5000);
private final Testbed.Setup testbedSetup = new Testbed.Setup(
"../../core/go/db/migrations/sqlite",
"build/testbed.java-bond.log",
5000);

JsonHex.Address deployPenteFactory() throws Exception {
try (Testbed deployBed = new Testbed(testbedSetup)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public class DomainIntegrationTests {

private static final Logger LOGGER = LogManager.getLogger(DomainIntegrationTests.class);

private final Testbed.Setup testbedSetup = new Testbed.Setup("../../core/go/db/migrations/sqlite", 5000);
private final Testbed.Setup testbedSetup = new Testbed.Setup(
"../../core/go/db/migrations/sqlite",
"build/testbed.java-domain-integration.log",
5000);

JsonHex.Address deployPenteFactory() throws Exception {
try (Testbed deployBed = new Testbed(testbedSetup)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@

public class PenteDomainTests {

private final Testbed.Setup testbedSetup = new Testbed.Setup("../../core/go/db/migrations/sqlite", 5000);
private final Testbed.Setup testbedSetup = new Testbed.Setup(
"../../core/go/db/migrations/sqlite",
"build/testbed.java-pente.log",
5000);

JsonHex.Address deployFactory() throws Exception {
try (Testbed deployBed = new Testbed(testbedSetup)) {
Expand Down
5 changes: 4 additions & 1 deletion domains/zeto/integration-test/testbed.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ db:
dsn: ':memory:'
autoMigrate: true
migrationsDir: '../../../core/go/db/migrations/sqlite'
debugQueries: true
debugQueries: false
# type: postgres
# postgres:
# dsn: 'postgres://postgres:my-secret@localhost:5432/postgres?sslmode=disable'
Expand All @@ -31,6 +31,9 @@ blockchain:
initialConnectAttempts: 25
log:
level: debug
output: file
file:
filename: build/testbed.zeto.log
wallets:
- name: wallet1
keySelector: .*
Expand Down
21 changes: 9 additions & 12 deletions toolkit/go/pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ import (
)

var (
rootLogger = logrus.NewEntry(
// we use our own root logger rather than logrus.StandardLogger, so any code that does logrus.SetLevel does not disrupt our logging
logrus.New(),
)
rootLogger = logrus.NewEntry(logrus.StandardLogger())

// L accesses the current logger from the context
L = loggerFromContext
Expand Down Expand Up @@ -65,11 +62,11 @@ func InitConfig(conf *pldconf.LogConfig) {
MaxAge: int(math.Ceil(float64(maxAgeDuration) / float64(time.Hour) / 24)), /* round up in days */
Compress: confutil.Bool(conf.File.Compress, *pldconf.LogDefaults.File.Compress),
}
rootLogger.Logger.SetOutput(lumberjack)
logrus.SetOutput(lumberjack)
case "stderr":
rootLogger.Logger.SetOutput(os.Stderr)
logrus.SetOutput(os.Stderr)
case "stdout":
rootLogger.Logger.SetOutput(os.Stdout)
logrus.SetOutput(os.Stdout)
fallthrough
default:
}
Expand All @@ -89,11 +86,11 @@ func InitConfig(conf *pldconf.LogConfig) {
}

func IsDebugEnabled() bool {
return rootLogger.Logger.IsLevelEnabled(logrus.DebugLevel)
return logrus.IsLevelEnabled(logrus.DebugLevel)
}

func IsTraceEnabled() bool {
return rootLogger.Logger.IsLevelEnabled(logrus.TraceLevel)
return logrus.IsLevelEnabled(logrus.TraceLevel)
}

func ensureInit() {
Expand Down Expand Up @@ -142,7 +139,7 @@ func SetLevel(level string) {
default:
l = logrus.InfoLevel
}
rootLogger.Logger.SetLevel(l)
logrus.SetLevel(l)
}

type Formatting struct {
Expand Down Expand Up @@ -189,7 +186,7 @@ func setFormatting(format *Formatting) {
DisableSorting: false,
FullTimestamp: true,
}
rootLogger.Logger.SetReportCaller(true)
logrus.SetReportCaller(true)
case "simple":
fallthrough
default:
Expand All @@ -205,5 +202,5 @@ func setFormatting(format *Formatting) {
if format.UTC {
formatter = &utcFormat{f: formatter}
}
rootLogger.Logger.SetFormatter(formatter)
logrus.SetFormatter(formatter)
}
12 changes: 6 additions & 6 deletions toolkit/go/pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,34 @@ func TestLogContextLimited(t *testing.T) {

func TestSettingErrorLevel(t *testing.T) {
SetLevel("eRrOr")
assert.Equal(t, logrus.ErrorLevel, rootLogger.Logger.GetLevel())
assert.Equal(t, logrus.ErrorLevel, logrus.GetLevel())
}

func TestSettingWarnLevel(t *testing.T) {
SetLevel("WARNING")
assert.Equal(t, logrus.WarnLevel, rootLogger.Logger.GetLevel())
assert.Equal(t, logrus.WarnLevel, logrus.GetLevel())
}

func TestSettingDebugLevel(t *testing.T) {
SetLevel("DEBUG")
assert.True(t, IsDebugEnabled())
assert.Equal(t, logrus.DebugLevel, rootLogger.Logger.GetLevel())
assert.Equal(t, logrus.DebugLevel, logrus.GetLevel())
}

func TestSettingTraceLevel(t *testing.T) {
SetLevel("trace")
assert.True(t, IsTraceEnabled())
assert.Equal(t, logrus.TraceLevel, rootLogger.Logger.GetLevel())
assert.Equal(t, logrus.TraceLevel, logrus.GetLevel())
}

func TestSettingInfoLevel(t *testing.T) {
SetLevel("info")
assert.Equal(t, logrus.InfoLevel, rootLogger.Logger.GetLevel())
assert.Equal(t, logrus.InfoLevel, logrus.GetLevel())
}

func TestSettingDefaultLevel(t *testing.T) {
SetLevel("something else")
assert.Equal(t, logrus.InfoLevel, rootLogger.Logger.GetLevel())
assert.Equal(t, logrus.InfoLevel, logrus.GetLevel())
}

func TestSetFormatting(t *testing.T) {
Expand Down
Loading

0 comments on commit 26cd5aa

Please sign in to comment.