-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Network: Support simple liveness check via http on gossip server port. (
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 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
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,41 @@ | ||
// Copyright (C) 2019-2024 Algorand, Inc. | ||
// This file is part of go-algorand | ||
// | ||
// go-algorand is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// go-algorand is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package rpcs | ||
|
||
import ( | ||
"github.com/algorand/go-algorand/network" | ||
"net/http" | ||
) | ||
|
||
// HealthServiceStatusPath is the path to register HealthService as a handler for when using gorilla/mux | ||
const HealthServiceStatusPath = "/status" | ||
|
||
// HealthService is a service that provides health information endpoints for the node | ||
type HealthService struct{} | ||
|
||
// MakeHealthService creates a new HealthService and registers it with the provided network if enabled | ||
func MakeHealthService(net network.GossipNode) HealthService { | ||
service := HealthService{} | ||
|
||
net.RegisterHTTPHandler(HealthServiceStatusPath, service) | ||
|
||
return service | ||
} | ||
|
||
func (h HealthService) ServeHTTP(writer http.ResponseWriter, _ *http.Request) { | ||
writer.WriteHeader(http.StatusOK) | ||
} |
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,52 @@ | ||
// Copyright (C) 2019-2024 Algorand, Inc. | ||
// This file is part of go-algorand | ||
// | ||
// go-algorand is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// go-algorand is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package rpcs | ||
|
||
import ( | ||
"github.com/algorand/go-algorand/network" | ||
"github.com/algorand/go-algorand/test/partitiontest" | ||
"github.com/stretchr/testify/require" | ||
"io" | ||
"net/http" | ||
"path" | ||
"testing" | ||
) | ||
|
||
func TestHealthService_ServeHTTP(t *testing.T) { | ||
partitiontest.PartitionTest(t) | ||
|
||
nodeA := &basicRPCNode{} | ||
nodeA.start() | ||
defer nodeA.stop() | ||
|
||
_ = MakeHealthService(nodeA) | ||
|
||
parsedURL, err := network.ParseHostOrURL(nodeA.rootURL()) | ||
require.NoError(t, err) | ||
|
||
client := http.Client{} | ||
|
||
parsedURL.Path = path.Join(parsedURL.Path, HealthServiceStatusPath) | ||
|
||
response, err := client.Get(parsedURL.String()) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, http.StatusOK, response.StatusCode) | ||
bodyData, err := io.ReadAll(response.Body) | ||
require.NoError(t, err) | ||
require.Empty(t, bodyData) | ||
} |