-
Notifications
You must be signed in to change notification settings - Fork 23
Operations endpoints: version info #931
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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{ | ||
|
|
@@ -122,6 +126,7 @@ func NewOperationsSystem(ops Operations, metricsConfig Metrics) *System { | |
|
|
||
| system.initializeMetricsProvider() | ||
| system.initializeHealthCheckHandler() | ||
| system.initializeVersionInfoHandler() | ||
|
|
||
| return system | ||
| } | ||
|
|
@@ -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) | ||
| } | ||
|
|
||
|
|
@@ -165,3 +167,17 @@ func (s *System) initializeHealthCheckHandler() { | |
| // description: Service unavailable. | ||
| s.RegisterHandler("/healthz", s.healthHandler, false) | ||
| } | ||
|
|
||
| func (s *System) initializeVersionInfoHandler() { | ||
| versionInfo := &VersionInfoHandler{ | ||
| 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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) | ||
| } | ||
There was a problem hiding this comment.
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