Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .github/workflows/go-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Go Checks
on:
push:
branches:
main
pull_request:

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.19'
- name: Tidy
run: go mod tidy
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
skip-pkg-cache: true
- name: Build
run: go build -v ./...
2 changes: 1 addition & 1 deletion cmd/bodies_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type SnapshotItem struct {
}

func (uih *UiHandler) bodiesDownload(ctx context.Context, w http.ResponseWriter, templ *template.Template, requestChannel chan *NodeRequest) {
snapshot := btree.NewG[SnapshotItem](16, func(a, b SnapshotItem) bool {
snapshot := btree.NewG(16, func(a, b SnapshotItem) bool {
return a.Id < b.Id
})
var tick int64
Expand Down
6 changes: 3 additions & 3 deletions cmd/bridge_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type NodeRequest struct {
const MaxRequestRetries = 16 // How many time to retry a request to the support

type BridgeHandler struct {
cancel context.CancelFunc
uih *UiHandler
//cancel context.CancelFunc
uih *UiHandler
}

var supportUrlRegex = regexp.MustCompile("^/support/([0-9]+)$")
Expand Down Expand Up @@ -90,7 +90,7 @@ func (bh *BridgeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
request.lock.Unlock()
log.Printf("Sending request %s\n", url)
writeBuf.Reset()
fmt.Fprintf(&writeBuf, url)
fmt.Fprint(&writeBuf, url)
if _, err := w.Write(writeBuf.Bytes()); err != nil {
log.Printf("Writing metrics request: %v\n", err)
request.lock.Lock()
Expand Down
2 changes: 1 addition & 1 deletion cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func parseLogPart(nodeRequest *NodeRequest, offset uint64) (bool, uint64, uint64
}
firstLineEnd := bytes.IndexByte(nodeRequest.response, '\n')
if firstLineEnd == -1 {
return clear, 0, 0, nil, fmt.Sprintf("could not find first line in log part response")
return clear, 0, 0, nil, "could not find first line in log part response"
}
m := logReadFirstLine.FindSubmatch(nodeRequest.response[:firstLineEnd])
if m == nil {
Expand Down
36 changes: 20 additions & 16 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/x509"
"fmt"
"html/template"
"io/ioutil"
"log"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -52,9 +52,9 @@ func init() {
rootCmd.Flags().StringVar(&listenAddr, "addr", "localhost", "network interface to listen on")
rootCmd.Flags().IntVar(&listenPort, "port", 8080, "port to listen on")
rootCmd.Flags().StringVar(&serverKeyFile, "tls.key", "", "path to server TLS key")
rootCmd.MarkFlagRequired("tls.key")
_ = rootCmd.MarkFlagRequired("tls.key")
rootCmd.Flags().StringVar(&serverCertFile, "tls.cert", "", "paths to server TLS certificates")
rootCmd.MarkFlagRequired("tls.cert")
_ = rootCmd.MarkFlagRequired("tls.cert")
rootCmd.Flags().StringSliceVar(&caCertFiles, "tls.cacerts", []string{}, "comma-separated list of paths to and CAs TLS certificates")
rootCmd.Flags().BoolVar(&insecure, "insecure", false, "whether to use insecure PIN generation for testing purposes (default is false)")
}
Expand Down Expand Up @@ -85,8 +85,8 @@ const successLine = "SUCCESS"

// NodeSession corresponds to one Erigon node connected via "erigon support" bridge to an operator
type NodeSession struct {
lock sync.Mutex
sessionPin uint64
lock sync.Mutex
//sessionPin uint64
Connected bool
RemoteAddr string
SupportVersion uint64 // Version of the erigon support command
Expand All @@ -112,15 +112,15 @@ type UiNodeSession struct {
}

type UiSession struct {
lock sync.Mutex
Session bool
SessionPin uint64
SessionName string
Errors []string // Transient field - only filled for the time of template execution
currentSessionName string
NodeS *NodeSession // Transient field - only filled for the time of template execution
uiNodeTree *btree.BTreeG[UiNodeSession]
UiNodes []UiNodeSession // Transient field - only filled forthe time of template execution
lock sync.Mutex
Session bool
SessionPin uint64
SessionName string
Errors []string // Transient field - only filled for the time of template execution
//currentSessionName string
NodeS *NodeSession // Transient field - only filled for the time of template execution
uiNodeTree *btree.BTreeG[UiNodeSession]
UiNodes []UiNodeSession // Transient field - only filled forthe time of template execution
}

func (uiSession *UiSession) appendError(err string) {
Expand Down Expand Up @@ -148,7 +148,7 @@ func webServer() error {
mux.Handle("/support/", bh)
certPool := x509.NewCertPool()
for _, caCertFile := range caCertFiles {
caCert, err := ioutil.ReadFile(caCertFile)
caCert, err := os.ReadFile(caCertFile)
if err != nil {
return fmt.Errorf("reading server certificate: %v", err)
}
Expand All @@ -171,8 +171,12 @@ func webServer() error {
go func() {
<-sigs
cancel()
s.Shutdown(ctx)
err := s.Shutdown(ctx)
if err != nil {
log.Printf("Failed to shutdown server due to error:%s", err.Error())
}
}()
log.Printf("Starting diagnostics Server listening at %s:%d", listenAddr, listenPort)
if err = s.ListenAndServeTLS(serverCertFile, serverKeyFile); err != nil {
select {
case <-ctx.Done():
Expand Down
4 changes: 2 additions & 2 deletions cmd/ui_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (sh *UiHandler) newUiSession() (string, *UiSession, error) {
if err == nil {
sessionId = base64.URLEncoding.EncodeToString(b[:])
}
uiSession := &UiSession{uiNodeTree: btree.NewG[UiNodeSession](32, func(a, b UiNodeSession) bool {
uiSession := &UiSession{uiNodeTree: btree.NewG(32, func(a, b UiNodeSession) bool {
return strings.Compare(a.SessionName, b.SessionName) < 0
})}
sh.uiSessionsLock.Lock()
Expand Down Expand Up @@ -274,7 +274,7 @@ func (sh *UiHandler) validSessionName(sessionName string, uiSession *UiSession)

func (sh *UiHandler) fetch(url string, requestChannel chan *NodeRequest) (bool, string) {
if requestChannel == nil {
return false, fmt.Sprintf("ERROR: Node is not allocated\n")
return false, "ERROR: Node is not allocated\n"
}
// Request command line arguments
nodeRequest := &NodeRequest{url: url}
Expand Down
2 changes: 1 addition & 1 deletion cmd/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func processVersions(w http.ResponseWriter, templ *template.Template, success bo
if len(lines) > 0 && strings.HasPrefix(lines[0], successLine) {
versions.Success = true
if len(lines) < 2 {
versions.Error = fmt.Sprintf("at least node version needs to be present")
versions.Error = "at least node version needs to be present"
versions.Success = false
} else {
var err error
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package main

import (
"log"

"github.com/ledgerwatch/diagnostics/cmd"
)

func main() {
cmd.Execute()
err := cmd.Execute()
if err != nil {
log.Printf("Failed to execute command due to error: %s", err.Error())
}
}