Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 24 additions & 8 deletions common/operations/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func HealthCheckServiceURL(system *System, logger *flogging.FabricLogger) string
return operationServiceURL("healthz", system.Addr(), logger)
}

func VersionInfoServiceURL(system *System, logger *flogging.FabricLogger) string {
return operationServiceURL("version", system.Addr(), logger)
}

// NewOperationsSystem creates a new operations system with the provided configuration.
func NewOperationsSystem(ops Operations, metricsConfig Metrics) *System {
o := Options{
Expand Down Expand Up @@ -122,6 +126,7 @@ func NewOperationsSystem(ops Operations, metricsConfig Metrics) *System {

system.initializeMetricsProvider()
system.initializeHealthCheckHandler()
system.initializeVersionInfoHandler()

return system
}
Expand All @@ -142,14 +147,11 @@ func (s *System) RegisterChecker(component string, checker healthz.HealthChecker
}

func (s *System) initializeMetricsProvider() {
// case "prometheus":
// // s.Provider = provider
// s.versionGauge = versionGauge(s.Provider)
// // swagger:operation GET /metrics operations metrics
// // ---
// // responses:
// // '200':
// // description: Ok.
// swagger:operation GET /metrics operations metrics
// ---
// responses:
// '200':
// description: Ok.
s.RegisterHandler("/metrics", promhttp.Handler(), s.options.TLS.Enabled)
}

Expand All @@ -165,3 +167,17 @@ func (s *System) initializeHealthCheckHandler() {
// description: Service unavailable.
s.RegisterHandler("/healthz", s.healthHandler, false)
}

func (s *System) initializeVersionInfoHandler() {
versionInfo := &VersionInfoHandler{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is coming from fabric-x-orderer/internal/cryptogen/metadata... not the right place IMO

CommitSHA: metadata.CommitSHA,
Version: metadata.Version,
}
// swagger:operation GET /version operations version
// ---
// summary: Returns the orderer or peer version and the commit SHA on which the release was created.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

update: no peer here

// responses:
// '200':
// description: Ok.
s.RegisterHandler("/version", versionInfo, false)
}
1 change: 1 addition & 0 deletions node/assembler/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func NewDefaultAssembler(

assembler.logger.Infof("Prometheus serving on URL: %s", operations.PrometheusMetricsServiceURL(assembler.opsSystem, assembler.logger))
assembler.logger.Infof("Health check serving on URL: %s", operations.HealthCheckServiceURL(assembler.opsSystem, assembler.logger))
assembler.logger.Infof("Version info serving on URL: %s", operations.VersionInfoServiceURL(assembler.opsSystem, assembler.logger))
assembler.metrics.StartMetricsTracker()

return assembler
Expand Down
1 change: 1 addition & 0 deletions node/batcher/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (b *Batcher) Run() {
b.metrics.StartMetricsTracker()
b.logger.Infof("Prometheus serving on URL: %s", b.MonitoringServiceAddress())
b.logger.Infof("Health check serving on URL: %s", operations.HealthCheckServiceURL(b.opsSystem, b.logger))
b.logger.Infof("Version info serving on URL: %s", operations.VersionInfoServiceURL(b.opsSystem, b.logger))
}

func (b *Batcher) GetStatus() string {
Expand Down
5 changes: 4 additions & 1 deletion node/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@ func (c *Consensus) Start() error {
}
RegisterHealthCheckers(c)

c.Metrics.StartMetricsTracker()

c.Logger.Infof("Prometheus serving on URL: %s", operations.PrometheusMetricsServiceURL(c.opsSystem, c.Logger))
c.Logger.Infof("Health check serving on URL: %s", operations.HealthCheckServiceURL(c.opsSystem, c.Logger))
c.Metrics.StartMetricsTracker()
c.Logger.Infof("Version info serving on URL: %s", operations.VersionInfoServiceURL(c.opsSystem, c.Logger))

bft := c.BFT
c.lock.Unlock()

Expand Down
1 change: 1 addition & 0 deletions node/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (r *Router) initFromConfig(rconfig *nodeconfig.RouterNodeConfig, configurat
r.metrics.StartMetricsTracker()
r.logger.Infof("Prometheus serving on URL: %s", r.MonitoringServiceAddress())
r.logger.Infof("Health check serving on URL: %s", operations.HealthCheckServiceURL(r.opsSystem, r.logger))
r.logger.Infof("Version info serving on URL: %s", operations.VersionInfoServiceURL(r.opsSystem, r.logger))
r.logger.Infof("Router with PartyID: %d has been initialized from config with sequence: %d", rconfig.PartyID, r.configSeq)
}

Expand Down
51 changes: 51 additions & 0 deletions test/faulttolerance/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/hyperledger/fabric-x-orderer/common/tools/armageddon"
"github.com/hyperledger/fabric-x-orderer/common/types"
"github.com/hyperledger/fabric-x-orderer/internal/cryptogen/metadata"
"github.com/hyperledger/fabric-x-orderer/testutil"
"github.com/hyperledger/fabric-x-orderer/testutil/client"
"github.com/hyperledger/fabric-x-orderer/testutil/signutil"
Expand Down Expand Up @@ -257,3 +258,53 @@ func TestStartAssemblerGetResponseFromOperationEndpoints(t *testing.T) {
return testutil.GetHealthCheckStatus(t, re, url)
}, 30*time.Second, 100*time.Millisecond)
}

// TestRunArmaNetworkAndGetAssemblerVersionInfo tests that the assembler's version info endpoint is up and returns the correct version information after the assembler is started.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't need to spin 4 different networks to test the /version service.
Start one network and test /healthz, /version in one test on all componets.

func TestRunArmaNetworkAndGetAssemblerVersionInfo(t *testing.T) {
// 1. compile arma
armaBinaryPath, err := gexec.BuildWithEnvironment("github.com/hyperledger/fabric-x-orderer/cmd/arma", []string{"GOPRIVATE=" + os.Getenv("GOPRIVATE")})
defer gexec.CleanupBuildArtifacts()
require.NoError(t, err)
require.NotNil(t, armaBinaryPath)

// Number of parties in the test
numOfParties := 1

t.Logf("Running test with %d parties and %d shards", numOfParties, 1)

// 2. Create a temporary directory for the test.
dir, err := os.MkdirTemp("", t.Name())
require.NoError(t, err)
defer os.RemoveAll(dir)

// 3. Create a config YAML file in the temporary directory.
configPath := filepath.Join(dir, "config.yaml")
netInfo := testutil.CreateNetwork(t, configPath, numOfParties, 1, "none", "none")
defer netInfo.CleanUp()
numOfArmaNodes := len(netInfo)

// 4. Generate the config files in the temporary directory using the armageddon generate command.
armageddon.NewCLI().Run([]string{"generate", "--config", configPath, "--output", dir})

// 5. Run the arma nodes.
// NOTE: if one of the nodes is not started within 10 seconds, there is no point in continuing the test, so fail it
readyChan := make(chan string, numOfArmaNodes)
armaNetwork := testutil.RunArmaNodes(t, dir, armaBinaryPath, readyChan, netInfo)
defer armaNetwork.Stop()

testutil.WaitReady(t, readyChan, numOfArmaNodes, 10)

// 6. Query the assemblers's version info endpoint and assert the version information.
assembler := armaNetwork.GetAssembler(t, types.PartyID(1))
url := testutil.CaptureArmaNodeVersionInfoServiceURL(t, assembler)

re := regexp.MustCompile(`^\{\s*"CommitSHA"\s*:\s*"([^"]*)"\s*,\s*"Version"\s*:\s*"([^"]*)"\s*\}$`)

require.Eventually(t, func() bool {
val := testutil.FetchVersionInfoValue(t, re, url)
if val == nil {
return false
}
return val.CommitSHA == metadata.CommitSHA && val.Version == metadata.Version

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please t.logf the version and build infor

}, 30*time.Second, 100*time.Millisecond)
}
52 changes: 52 additions & 0 deletions test/faulttolerance/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"math"
"os"
"path/filepath"
"regexp"
"testing"
"time"

"github.com/hyperledger/fabric-x-orderer/common/tools/armageddon"
"github.com/hyperledger/fabric-x-orderer/common/types"
"github.com/hyperledger/fabric-x-orderer/internal/cryptogen/metadata"
test_utils "github.com/hyperledger/fabric-x-orderer/test/utils"
"github.com/hyperledger/fabric-x-orderer/testutil"
"github.com/hyperledger/fabric-x-orderer/testutil/client"
Expand Down Expand Up @@ -467,3 +469,53 @@ func TestSecondaryBatcherRestartRecover(t *testing.T) {
Signer: signer,
})
}

// TestRunArmaNetworkAndGetBatcherVersionInfo tests that the batcher's version info endpoint is up and returns the correct version information after the batcher is started.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't need to spin 4 different networks to test the /version service.
Start one network and test /healthz, /version in one test on all componets.

func TestRunArmaNetworkAndGetBatcherVersionInfo(t *testing.T) {
// 1. compile arma
armaBinaryPath, err := gexec.BuildWithEnvironment("github.com/hyperledger/fabric-x-orderer/cmd/arma", []string{"GOPRIVATE=" + os.Getenv("GOPRIVATE")})
defer gexec.CleanupBuildArtifacts()
require.NoError(t, err)
require.NotNil(t, armaBinaryPath)

// Number of parties in the test
numOfParties := 1

t.Logf("Running test with %d parties and %d shards", numOfParties, 1)

// 2. Create a temporary directory for the test.
dir, err := os.MkdirTemp("", t.Name())
require.NoError(t, err)
defer os.RemoveAll(dir)

// 3. Create a config YAML file in the temporary directory.
configPath := filepath.Join(dir, "config.yaml")
netInfo := testutil.CreateNetwork(t, configPath, numOfParties, 1, "none", "none")
defer netInfo.CleanUp()
numOfArmaNodes := len(netInfo)

// 4. Generate the config files in the temporary directory using the armageddon generate command.
armageddon.NewCLI().Run([]string{"generate", "--config", configPath, "--output", dir})

// 5. Run the arma nodes.
// NOTE: if one of the nodes is not started within 10 seconds, there is no point in continuing the test, so fail it
readyChan := make(chan string, numOfArmaNodes)
armaNetwork := testutil.RunArmaNodes(t, dir, armaBinaryPath, readyChan, netInfo)
defer armaNetwork.Stop()

testutil.WaitReady(t, readyChan, numOfArmaNodes, 10)

// 6. Query the batcher's version info endpoint and assert the version information.
batcher := armaNetwork.GetBatcher(t, types.PartyID(1), types.ShardID(1))
url := testutil.CaptureArmaNodeVersionInfoServiceURL(t, batcher)

re := regexp.MustCompile(`^\{\s*"CommitSHA"\s*:\s*"([^"]*)"\s*,\s*"Version"\s*:\s*"([^"]*)"\s*\}$`)

require.Eventually(t, func() bool {
val := testutil.FetchVersionInfoValue(t, re, url)
if val == nil {
return false
}
return val.CommitSHA == metadata.CommitSHA && val.Version == metadata.Version
}, 30*time.Second, 100*time.Millisecond)
}
52 changes: 52 additions & 0 deletions test/faulttolerance/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"sync"
"testing"
"time"

"github.com/hyperledger/fabric-x-orderer/common/tools/armageddon"
"github.com/hyperledger/fabric-x-orderer/common/types"
"github.com/hyperledger/fabric-x-orderer/internal/cryptogen/metadata"
"github.com/hyperledger/fabric-x-orderer/test/utils"
"github.com/hyperledger/fabric-x-orderer/testutil"
"github.com/hyperledger/fabric-x-orderer/testutil/signutil"
Expand Down Expand Up @@ -143,3 +145,53 @@ func TestSubmitStopThenRestartConsenter(t *testing.T) {
Signer: signer,
})
}

// TestRunArmaNetworkAndGetConsenterVersionInfo tests that the consenter's version info endpoint is up and returns the correct version information after the consenter is started.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't need to spin 4 different networks to test the /version service.
Start one network and test /healthz, /version in one test on all componets.

func TestRunArmaNetworkAndGetConsenterVersionInfo(t *testing.T) {
// 1. compile arma
armaBinaryPath, err := gexec.BuildWithEnvironment("github.com/hyperledger/fabric-x-orderer/cmd/arma", []string{"GOPRIVATE=" + os.Getenv("GOPRIVATE")})
defer gexec.CleanupBuildArtifacts()
require.NoError(t, err)
require.NotNil(t, armaBinaryPath)

// Number of parties in the test
numOfParties := 1

t.Logf("Running test with %d parties and %d shards", numOfParties, 1)

// 2. Create a temporary directory for the test.
dir, err := os.MkdirTemp("", t.Name())
require.NoError(t, err)
defer os.RemoveAll(dir)

// 3. Create a config YAML file in the temporary directory.
configPath := filepath.Join(dir, "config.yaml")
netInfo := testutil.CreateNetwork(t, configPath, numOfParties, 1, "none", "none")
defer netInfo.CleanUp()
numOfArmaNodes := len(netInfo)

// 4. Generate the config files in the temporary directory using the armageddon generate command.
armageddon.NewCLI().Run([]string{"generate", "--config", configPath, "--output", dir})

// 5. Run the arma nodes.
// NOTE: if one of the nodes is not started within 10 seconds, there is no point in continuing the test, so fail it
readyChan := make(chan string, numOfArmaNodes)
armaNetwork := testutil.RunArmaNodes(t, dir, armaBinaryPath, readyChan, netInfo)
defer armaNetwork.Stop()

testutil.WaitReady(t, readyChan, numOfArmaNodes, 10)

// 6. Query the consenter's version info endpoint and assert the version information.
consenter := armaNetwork.GetConsenter(t, types.PartyID(1))
url := testutil.CaptureArmaNodeVersionInfoServiceURL(t, consenter)

re := regexp.MustCompile(`^\{\s*"CommitSHA"\s*:\s*"([^"]*)"\s*,\s*"Version"\s*:\s*"([^"]*)"\s*\}$`)

require.Eventually(t, func() bool {
val := testutil.FetchVersionInfoValue(t, re, url)
if val == nil {
return false
}
return val.CommitSHA == metadata.CommitSHA && val.Version == metadata.Version
}, 30*time.Second, 100*time.Millisecond)
}
52 changes: 52 additions & 0 deletions test/faulttolerance/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"math"
"os"
"path/filepath"
"regexp"
"testing"
"time"

"github.com/hyperledger/fabric-x-orderer/common/tools/armageddon"
"github.com/hyperledger/fabric-x-orderer/common/types"
"github.com/hyperledger/fabric-x-orderer/internal/cryptogen/metadata"
test_utils "github.com/hyperledger/fabric-x-orderer/test/utils"
"github.com/hyperledger/fabric-x-orderer/testutil"
"github.com/hyperledger/fabric-x-orderer/testutil/client"
Expand Down Expand Up @@ -281,3 +283,53 @@ func TestRouterRestartRecover(t *testing.T) {
Signer: signer,
})
}

// TestRunArmaNetworkAndGetRouterVersionInfo tests that the router's version info endpoint is up and returns the correct version information after the router is started.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't need to spin 4 different networks to test the /version service.
Start one network and test /healthz, /version in one test on all componets.

func TestRunArmaNetworkAndGetRouterVersionInfo(t *testing.T) {
// 1. compile arma
armaBinaryPath, err := gexec.BuildWithEnvironment("github.com/hyperledger/fabric-x-orderer/cmd/arma", []string{"GOPRIVATE=" + os.Getenv("GOPRIVATE")})
defer gexec.CleanupBuildArtifacts()
require.NoError(t, err)
require.NotNil(t, armaBinaryPath)

// Number of parties in the test
numOfParties := 1

t.Logf("Running test with %d parties and %d shards", numOfParties, 1)

// 2. Create a temporary directory for the test.
dir, err := os.MkdirTemp("", t.Name())
require.NoError(t, err)
defer os.RemoveAll(dir)

// 3. Create a config YAML file in the temporary directory.
configPath := filepath.Join(dir, "config.yaml")
netInfo := testutil.CreateNetwork(t, configPath, numOfParties, 1, "none", "none")
defer netInfo.CleanUp()
numOfArmaNodes := len(netInfo)

// 4. Generate the config files in the temporary directory using the armageddon generate command.
armageddon.NewCLI().Run([]string{"generate", "--config", configPath, "--output", dir})

// 5. Run the arma nodes.
// NOTE: if one of the nodes is not started within 10 seconds, there is no point in continuing the test, so fail it
readyChan := make(chan string, numOfArmaNodes)
armaNetwork := testutil.RunArmaNodes(t, dir, armaBinaryPath, readyChan, netInfo)
defer armaNetwork.Stop()

testutil.WaitReady(t, readyChan, numOfArmaNodes, 10)

// 6. Query the router's version info endpoint and assert the version information.
router := armaNetwork.GetRouter(t, types.PartyID(1))
url := testutil.CaptureArmaNodeVersionInfoServiceURL(t, router)

re := regexp.MustCompile(`^\{\s*"CommitSHA"\s*:\s*"([^"]*)"\s*,\s*"Version"\s*:\s*"([^"]*)"\s*\}$`)

require.Eventually(t, func() bool {
val := testutil.FetchVersionInfoValue(t, re, url)
if val == nil {
return false
}
return val.CommitSHA == metadata.CommitSHA && val.Version == metadata.Version
}, 30*time.Second, 100*time.Millisecond)
}
Loading
Loading