Skip to content

Commit

Permalink
Merge pull request #38 from pk910/client-status-details
Browse files Browse the repository at this point in the history
Client status details
  • Loading branch information
pk910 authored Oct 23, 2023
2 parents 3960b66 + c9b310a commit ed97f12
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 35 deletions.
16 changes: 9 additions & 7 deletions handlers/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ func buildClientsPageData() (*models.ClientsPageData, time.Duration) {
cacheTime := time.Duration(utils.Config.Chain.Config.SecondsPerSlot) * time.Second

for _, client := range services.GlobalBeaconService.GetClients() {
lastHeadSlot, lastHeadRoot := client.GetLastHead()
lastHeadSlot, lastHeadRoot, clientRefresh := client.GetLastHead()
if lastHeadSlot < 0 {
lastHeadSlot = 0
}
resClient := &models.ClientsPageDataClient{
Index: int(client.GetIndex()) + 1,
Name: client.GetName(),
Version: client.GetVersion(),
HeadSlot: uint64(lastHeadSlot),
HeadRoot: lastHeadRoot,
Status: client.GetStatus(),
Index: int(client.GetIndex()) + 1,
Name: client.GetName(),
Version: client.GetVersion(),
HeadSlot: uint64(lastHeadSlot),
HeadRoot: lastHeadRoot,
Status: client.GetStatus(),
LastRefresh: clientRefresh,
LastError: client.GetLastClientError(),
}
pageData.Clients = append(pageData.Clients, resClient)
}
Expand Down
12 changes: 7 additions & 5 deletions handlers/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ func buildForksPageData() (*models.ForksPageData, time.Duration) {
pageData.Forks = append(pageData.Forks, forkData)

for _, client := range fork.AllClients {
clientHeadSlot, _ := client.GetLastHead()
clientHeadSlot, _, clientRefresh := client.GetLastHead()
forkClient := &models.ForksPageDataClient{
Index: int(client.GetIndex()) + 1,
Name: client.GetName(),
Version: client.GetVersion(),
Status: client.GetStatus(),
Index: int(client.GetIndex()) + 1,
Name: client.GetName(),
Version: client.GetVersion(),
Status: client.GetStatus(),
LastRefresh: clientRefresh,
LastError: client.GetLastClientError(),
}
if clientHeadSlot >= 0 {
forkClient.HeadSlot = uint64(clientHeadSlot)
Expand Down
17 changes: 15 additions & 2 deletions indexer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type IndexerClient struct {
versionStr string
indexerCache *indexerCache
cacheMutex sync.RWMutex
lastClientError error
lastHeadRefresh time.Time
lastStreamEvent time.Time
isSynchronizing bool
isOptimistic bool
Expand Down Expand Up @@ -72,10 +74,10 @@ func (client *IndexerClient) GetRpcClient() *rpc.BeaconClient {
return client.rpcClient
}

func (client *IndexerClient) GetLastHead() (int64, []byte) {
func (client *IndexerClient) GetLastHead() (int64, []byte, time.Time) {
client.cacheMutex.RLock()
defer client.cacheMutex.RUnlock()
return client.lastHeadSlot, client.lastHeadRoot
return client.lastHeadSlot, client.lastHeadRoot, client.lastHeadRefresh
}

func (client *IndexerClient) GetStatus() string {
Expand All @@ -90,6 +92,15 @@ func (client *IndexerClient) GetStatus() string {
}
}

func (client *IndexerClient) GetLastClientError() string {
client.cacheMutex.RLock()
defer client.cacheMutex.RUnlock()
if client.lastClientError == nil {
return ""
}
return client.lastClientError.Error()
}

func (client *IndexerClient) runIndexerClientLoop() {
defer utils.HandleSubroutinePanic("runIndexerClientLoop")

Expand Down Expand Up @@ -123,6 +134,7 @@ func (client *IndexerClient) runIndexerClientLoop() {
return
}

client.lastClientError = err
client.retryCounter++
waitTime := 10
skipLog := false
Expand Down Expand Up @@ -507,6 +519,7 @@ func (client *IndexerClient) ensureParentBlocks(currentBlock *CacheBlock) error

func (client *IndexerClient) setHeadBlock(root []byte, slot uint64) error {
client.cacheMutex.Lock()
client.lastHeadRefresh = time.Now()
if bytes.Equal(client.lastHeadRoot, root) {
client.cacheMutex.Unlock()
return nil
Expand Down
4 changes: 2 additions & 2 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (indexer *Indexer) GetHeadForks(readyOnly bool) []*HeadFork {
if readyOnly && (!client.isConnected || client.isSynchronizing || client.isOptimistic) {
continue
}
cHeadSlot, cHeadRoot := client.GetLastHead()
cHeadSlot, cHeadRoot, _ := client.GetLastHead()
var matchingFork *HeadFork
for _, fork := range headForks {
if bytes.Equal(fork.Root, cHeadRoot) || indexer.indexerCache.isCanonicalBlock(cHeadRoot, fork.Root) {
Expand Down Expand Up @@ -222,7 +222,7 @@ func (indexer *Indexer) GetHeadForks(readyOnly bool) []*HeadFork {
})
for _, client := range fork.AllClients {
var headDistance uint64 = 0
_, cHeadRoot := client.GetLastHead()
_, cHeadRoot, _ := client.GetLastHead()
if !bytes.Equal(fork.Root, cHeadRoot) {
_, headDistance = indexer.indexerCache.getCanonicalDistance(cHeadRoot, fork.Root)
}
Expand Down
8 changes: 4 additions & 4 deletions templates/clients/clients.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-server mx-2"></i>Clients</h1>
</td>
<td>
{{ if eq $client.Status "ready" }}
<span class="badge rounded-pill text-bg-success">Connected</span>
<span class="badge rounded-pill text-bg-success">Ready</span>
{{ else if eq $client.Status "synchronizing" }}
<span class="badge rounded-pill text-bg-warning">Synchronizing</span>
<span class="badge rounded-pill text-bg-warning" data-bs-toggle="tooltip" data-bs-placement="top" title="Updated: {{ formatRecentTimeShort $client.LastRefresh }}">Synchronizing</span>
{{ else if eq $client.Status "optimistic" }}
<span class="badge rounded-pill text-bg-info">Optimistic</span>
<span class="badge rounded-pill text-bg-info" data-bs-toggle="tooltip" data-bs-placement="top" title="Updated: {{ formatRecentTimeShort $client.LastRefresh }}">Optimistic</span>
{{ else if eq $client.Status "disconnected" }}
<span class="badge rounded-pill text-bg-secondary">Disconnected</span>
<span class="badge rounded-pill text-bg-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Updated: {{ formatRecentTimeShort $client.LastRefresh }}, Error: {{ $client.LastError }}">Disconnected</span>
{{ else }}
<span class="badge rounded-pill text-bg-dark">{{ $client.Status }}</span>
{{ end }}
Expand Down
6 changes: 3 additions & 3 deletions templates/forks/forks.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-code-fork mx-2"></i>Forks</h1>
{{ if eq .Status "ready" }}
<span class="badge rounded-pill text-bg-success">Connected</span>
{{ else if eq .Status "synchronizing" }}
<span class="badge rounded-pill text-bg-warning">Synchronizing</span>
<span class="badge rounded-pill text-bg-warning" data-bs-toggle="tooltip" data-bs-placement="top" title="Updated: {{ formatRecentTimeShort $client.LastRefresh }}">Synchronizing</span>
{{ else if eq .Status "optimistic" }}
<span class="badge rounded-pill text-bg-info">Optimistic</span>
<span class="badge rounded-pill text-bg-info" data-bs-toggle="tooltip" data-bs-placement="top" title="Updated: {{ formatRecentTimeShort $client.LastRefresh }}">Optimistic</span>
{{ else if eq .Status "disconnected" }}
<span class="badge rounded-pill text-bg-secondary">Disconnected</span>
<span class="badge rounded-pill text-bg-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Updated: {{ formatRecentTimeShort $client.LastRefresh }}, Error: {{ $client.LastError }}">Disconnected</span>
{{ else }}
<span class="badge rounded-pill text-bg-dark">{{ .Status }}</span>
{{ end }}
Expand Down
16 changes: 10 additions & 6 deletions types/models/clients.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package models

import "time"

// ClientsPageData is a struct to hold info for the clients page
type ClientsPageData struct {
Clients []*ClientsPageDataClient `json:"clients"`
ClientCount uint64 `json:"client_count"`
}

type ClientsPageDataClient struct {
Index int `json:"index"`
Name string `json:"name"`
Version string `json:"version"`
HeadSlot uint64 `json:"head_slot"`
HeadRoot []byte `json:"head_root"`
Status string `json:"status"`
Index int `json:"index"`
Name string `json:"name"`
Version string `json:"version"`
HeadSlot uint64 `json:"head_slot"`
HeadRoot []byte `json:"head_root"`
Status string `json:"status"`
LastRefresh time.Time `json:"refresh"`
LastError string `json:"error"`
}
16 changes: 10 additions & 6 deletions types/models/forks.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package models

import "time"

// ForksPageData is a struct to hold info for the forks page
type ForksPageData struct {
Forks []*ForksPageDataFork `json:"forks"`
Expand All @@ -14,10 +16,12 @@ type ForksPageDataFork struct {
}

type ForksPageDataClient struct {
Index int `json:"index"`
Name string `json:"name"`
Version string `json:"version"`
Status string `json:"status"`
HeadSlot uint64 `json:"head_slot"`
Distance uint64 `json:"distance"`
Index int `json:"index"`
Name string `json:"name"`
Version string `json:"version"`
Status string `json:"status"`
HeadSlot uint64 `json:"head_slot"`
Distance uint64 `json:"distance"`
LastRefresh time.Time `json:"refresh"`
LastError string `json:"error"`
}

0 comments on commit ed97f12

Please sign in to comment.