Skip to content
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

Darren/admin api log toggler #877

Merged
merged 24 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
19db51a
Adding Health endpoint
otherview Sep 4, 2024
22bc2c2
Merge remote-tracking branch 'origin/master' into pedro/health_endpoint
otherview Oct 29, 2024
df30451
pr comments + 503 if not healthy
otherview Oct 29, 2024
ed0097c
refactored admin server and api + health endpoint tests
otherview Oct 30, 2024
552629c
fix health condition
otherview Oct 30, 2024
6fa89c1
Merge remote-tracking branch 'origin/master' into pedro/health_endpoint
otherview Oct 30, 2024
91ceb58
fix admin routing
otherview Oct 30, 2024
0206c1f
added comments + changed from ChainSync to ChainBootstrapStatus
otherview Nov 4, 2024
17c2ce9
Adding healthcheck for solo mode
otherview Nov 4, 2024
2f461c8
Merge remote-tracking branch 'origin/master' into pedro/health_endpoint
otherview Nov 5, 2024
1797c22
adding solo + tests
otherview Nov 5, 2024
dbea45a
Merge remote-tracking branch 'origin/master' into pedro/health_endpoint
otherview Nov 6, 2024
15a18fc
fix log_level handler funcs
otherview Nov 6, 2024
bda5f97
Merge remote-tracking branch 'origin/master' into pedro/health_endpoint
otherview Nov 7, 2024
8bf5003
feat(admin): toggle api logs via admin API
darrenvechain Nov 8, 2024
2392e96
feat(admin): add license headers
darrenvechain Nov 8, 2024
6b22089
refactor health package + add p2p count
otherview Nov 15, 2024
1fdc48b
remove solo methods
otherview Nov 15, 2024
430c458
moving health service to api pkg
otherview Nov 18, 2024
f1b0000
added defaults + api health query
otherview Nov 20, 2024
c0aee23
pr comments
otherview Nov 21, 2024
34a8adc
pr comments
otherview Nov 27, 2024
186edc6
Merge branch 'pedro/health_endpoint' into darren/admin-api-log-toggler
darrenvechain Dec 6, 2024
d8f66d7
Merge remote-tracking branch 'origin/master' into darren/admin-api-lo…
otherview Dec 9, 2024
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
Prev Previous commit
Next Next commit
fix health condition
  • Loading branch information
otherview committed Oct 30, 2024
commit 552629c009e286dfb22abd427e09ee42e70a6cd0
3 changes: 1 addition & 2 deletions health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ func (h *Health) Status() (*Status, error) {
BestBlockIngestionTimestamp: &h.newBestBlock,
}

// todo review time slots
healthy := time.Since(h.newBestBlock) >= 10*time.Second &&
healthy := time.Since(h.newBestBlock) <= 10*time.Second && // less than 10 secs have passed since a new block was received
h.chainSynced

return &Status{
Expand Down
85 changes: 85 additions & 0 deletions health/health_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) 2024 The VeChainThor developers

// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

package health

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vechain/thor/v2/thor"
)

func TestHealth_NewBestBlock(t *testing.T) {
h := &Health{}
blockID := thor.Bytes32{0x01, 0x02, 0x03}

h.NewBestBlock(blockID)

if h.bestBlockID == nil || *h.bestBlockID != blockID {
t.Errorf("expected bestBlockID to be %v, got %v", blockID, h.bestBlockID)
}

if time.Since(h.newBestBlock) > time.Second {
t.Errorf("newBestBlock timestamp is not recent")
}

h.ChainSyncStatus(true)

status, err := h.Status()
require.NoError(t, err)

assert.True(t, status.Healthy)
}

func TestHealth_ChainSyncStatus(t *testing.T) {
h := &Health{}

h.ChainSyncStatus(true)
if !h.chainSynced {
t.Errorf("expected chainSynced to be true, got false")
}

h.ChainSyncStatus(false)
if h.chainSynced {
t.Errorf("expected chainSynced to be false, got true")
}

status, err := h.Status()
require.NoError(t, err)

assert.False(t, status.Healthy)
}

func TestHealth_Status(t *testing.T) {
h := &Health{}
blockID := thor.Bytes32{0x01, 0x02, 0x03}

h.NewBestBlock(blockID)
h.ChainSyncStatus(true)

status, err := h.Status()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if !status.Healthy {
t.Errorf("expected healthy to be true, got false")
}

if status.BlockIngestion.BestBlock == nil || *status.BlockIngestion.BestBlock != blockID {
t.Errorf("expected bestBlock to be %v, got %v", blockID, status.BlockIngestion.BestBlock)
}

if status.BlockIngestion.BestBlockIngestionTimestamp == nil || time.Since(*status.BlockIngestion.BestBlockIngestionTimestamp) > time.Second {
t.Errorf("bestBlockIngestionTimestamp is not recent")
}

if !status.ChainSync {
t.Errorf("expected chainSync to be true, got false")
}
}
Loading