-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from kaleido-io/status-endpoints
GET /status/* APIs for Liveness and Readiness Probes
- Loading branch information
Showing
10 changed files
with
133 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ coverage.txt | |
.DS_Store | ||
__debug* | ||
.leveldb | ||
.vscode/*.log | ||
.vscode/*.log | ||
*.iml | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright © 2022 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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. | ||
|
||
package ethereum | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/fftypes" | ||
"github.com/hyperledger/firefly-transaction-manager/pkg/ffcapi" | ||
) | ||
|
||
func (c *ethConnector) IsLive(_ context.Context) (*ffcapi.LiveResponse, ffcapi.ErrorReason, error) { | ||
return &ffcapi.LiveResponse{ | ||
Up: true, | ||
}, "", nil | ||
} | ||
|
||
func (c *ethConnector) IsReady(ctx context.Context) (*ffcapi.ReadyResponse, ffcapi.ErrorReason, error) { | ||
var chainID string | ||
err := c.backend.CallRPC(ctx, &chainID, "net_version") | ||
if err != nil { | ||
return &ffcapi.ReadyResponse{ | ||
Ready: false, | ||
}, mapError(netVersionRPCMethods, err), err | ||
} | ||
|
||
details := &fftypes.JSONObject{ | ||
"chainID": chainID, | ||
} | ||
|
||
return &ffcapi.ReadyResponse{ | ||
Ready: true, | ||
DownstreamDetails: fftypes.JSONAnyPtr(details.String()), | ||
}, "", nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright © 2022 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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. | ||
|
||
package ethereum | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hyperledger/firefly-transaction-manager/pkg/ffcapi" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"testing" | ||
) | ||
|
||
func TestIsLive(t *testing.T) { | ||
ctx, c, _, done := newTestConnector(t) | ||
defer done() | ||
|
||
status, _, err := c.IsLive(ctx) | ||
assert.NoError(t, err) | ||
assert.True(t, status.Up) | ||
} | ||
|
||
func TestIsReady(t *testing.T) { | ||
ctx, c, mRPC, done := newTestConnector(t) | ||
defer done() | ||
|
||
mRPC.On("CallRPC", mock.Anything, mock.Anything, "net_version"). | ||
Run(func(args mock.Arguments) { | ||
*(args[1].(*string)) = "80001" | ||
}). | ||
Return(nil) | ||
|
||
status, _, err := c.IsReady(ctx) | ||
assert.NoError(t, err) | ||
assert.True(t, status.Ready) | ||
assert.NotNil(t, status.DownstreamDetails) | ||
|
||
details := status.DownstreamDetails.JSONObject() | ||
assert.Equal(t, details.GetString("chainID"), "80001") | ||
} | ||
|
||
func TestIsReadyError(t *testing.T) { | ||
ctx, c, mRPC, done := newTestConnector(t) | ||
defer done() | ||
|
||
mRPC.On("CallRPC", mock.Anything, mock.Anything, "net_version"). | ||
Return(fmt.Errorf("the method net_version does not exist/is not available")) | ||
|
||
status, reason, err := c.IsReady(ctx) | ||
assert.Error(t, err) | ||
assert.Equal(t, reason, ffcapi.ErrorReasonNotFound) | ||
assert.False(t, status.Ready) | ||
assert.Nil(t, status.DownstreamDetails) | ||
} |