kopia lustrzana https://github.com/bugout-dev/moonstream
Small changes
rodzic
8e7da79fb1
commit
363388857b
|
@ -1,17 +1,17 @@
|
|||
# Node Balancer application
|
||||
|
||||
# Installation
|
||||
## Installation
|
||||
|
||||
- Prepare environment variables
|
||||
- Prepare environment variables, according with `sample.env`.
|
||||
- Build application
|
||||
|
||||
```bash
|
||||
go build -o nodebalancer .
|
||||
```
|
||||
|
||||
# Work with nodebalancer
|
||||
## Work with nodebalancer
|
||||
|
||||
## add-access
|
||||
### add-access
|
||||
|
||||
Add new access for user:
|
||||
|
||||
|
@ -25,7 +25,7 @@ nodebalancer add-access \
|
|||
--blockchain--access true
|
||||
```
|
||||
|
||||
## delete-access
|
||||
### delete-access
|
||||
|
||||
Delete user access:
|
||||
|
||||
|
@ -37,7 +37,7 @@ nodebalancer delete-access \
|
|||
|
||||
If `access-id` not specified, all user accesses will be deleted.
|
||||
|
||||
## users
|
||||
### users
|
||||
|
||||
```bash
|
||||
nodebalancer users | jq .
|
||||
|
@ -67,7 +67,7 @@ This command will return a list of bugout resources of registered users to acces
|
|||
|
||||
`extended_methods` - boolean which allow you to call not whitelisted method to blockchain node, by default for new user this is equal to `false`
|
||||
|
||||
## server
|
||||
### server
|
||||
|
||||
```bash
|
||||
nodebalancer server -host 0.0.0.0 -port 8544 -healthcheck
|
||||
|
@ -76,17 +76,17 @@ nodebalancer server -host 0.0.0.0 -port 8544 -healthcheck
|
|||
Flag `--healthcheck` will execute background process to ping-pong available nodes to keep their status and current block number.
|
||||
Flag `--debug` will extend output of each request to server and healthchecks summary.
|
||||
|
||||
# Work with node
|
||||
## Work with node
|
||||
|
||||
Common request to fetch block number
|
||||
|
||||
```bash
|
||||
curl --request GET 'http://127.0.0.1:8544/nb/ethereum/jsonrpc?access_id=<access_id>&data_source=<blockchain/database>' \
|
||||
curl --request POST 'http://127.0.0.1:8544/nb/ethereum/jsonrpc?access_id=<access_id>&data_source=<blockchain/database>' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
"jsonrpc":"2.0",
|
||||
"method":"eth_getBlockByNumber",
|
||||
"params":["0xb71b64", false],
|
||||
"params":["latest", false],
|
||||
"id":1
|
||||
}'
|
||||
```
|
||||
|
|
|
@ -206,16 +206,18 @@ func (bpool *BlockchainPool) HealthCheck() {
|
|||
if err != nil {
|
||||
n.UpdateNodeState(0, alive)
|
||||
log.Printf("Unable to reach node: %s", n.Endpoint.Host)
|
||||
resp.Body.Close()
|
||||
continue
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
n.UpdateNodeState(0, alive)
|
||||
log.Printf("Unable to parse response from %s node, err %v", n.Endpoint.Host, err)
|
||||
resp.Body.Close()
|
||||
continue
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
var statusResponse NodeStatusResponse
|
||||
err = json.Unmarshal(body, &statusResponse)
|
||||
|
|
|
@ -42,7 +42,7 @@ type ClientPool struct {
|
|||
func CreateClientPools() {
|
||||
clientPool = make(map[string]ClientPool)
|
||||
|
||||
for b := range configBlockchains {
|
||||
for b := range supportedBlockchains {
|
||||
clientPool[b] = ClientPool{}
|
||||
if cp, ok := clientPool[b]; ok {
|
||||
cp.Client = make(map[string]*Client)
|
||||
|
@ -54,7 +54,7 @@ func CreateClientPools() {
|
|||
// Return client pool corresponding to provided blockchain
|
||||
func GetClientPool(blockchain string) *ClientPool {
|
||||
var cpool *ClientPool
|
||||
for b := range configBlockchains {
|
||||
for b := range supportedBlockchains {
|
||||
if b == blockchain {
|
||||
c := clientPool[blockchain]
|
||||
cpool = &c
|
||||
|
|
|
@ -17,6 +17,8 @@ import (
|
|||
var (
|
||||
nodeConfigs []NodeConfig
|
||||
|
||||
supportedBlockchains map[string]bool
|
||||
|
||||
// Bugout and application configuration
|
||||
BUGOUT_AUTH_URL = os.Getenv("BUGOUT_AUTH_URL")
|
||||
BUGOUT_AUTH_CALL_TIMEOUT = time.Second * 5
|
||||
|
@ -26,7 +28,7 @@ var (
|
|||
|
||||
NB_CONNECTION_RETRIES = 2
|
||||
NB_CONNECTION_RETRIES_INTERVAL = time.Millisecond * 10
|
||||
NB_HEALTH_CHECK_INTERVAL = time.Second * 5
|
||||
NB_HEALTH_CHECK_INTERVAL = time.Millisecond * 5000
|
||||
NB_HEALTH_CHECK_CALL_TIMEOUT = time.Second * 2
|
||||
|
||||
NB_CACHE_CLEANING_INTERVAL = time.Second * 10
|
||||
|
@ -108,7 +110,7 @@ func GetConfigPath(providedPath string) (*ConfigPlacement, error) {
|
|||
return nil, fmt.Errorf("Unable to find user home directory, %v", err)
|
||||
}
|
||||
configDirPath = fmt.Sprintf("%s/.nodebalancer", homeDir)
|
||||
configPath = fmt.Sprintf("%s/config.txt", configDirPath)
|
||||
configPath = fmt.Sprintf("%s/config.json", configDirPath)
|
||||
} else {
|
||||
configPath = strings.TrimSuffix(providedPath, "/")
|
||||
configDirPath = filepath.Dir(configPath)
|
||||
|
|
|
@ -42,7 +42,7 @@ func lbHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
var blockchain string
|
||||
for b := range configBlockchains {
|
||||
for b := range supportedBlockchains {
|
||||
if strings.HasPrefix(r.URL.Path, fmt.Sprintf("/nb/%s/", b)) {
|
||||
blockchain = b
|
||||
break
|
||||
|
|
|
@ -22,8 +22,6 @@ import (
|
|||
var (
|
||||
internalCrawlersAccess ClientResourceData
|
||||
|
||||
configBlockchains map[string]bool
|
||||
|
||||
// Crash reporter
|
||||
reporter *humbug.HumbugReporter
|
||||
)
|
||||
|
@ -36,7 +34,7 @@ func initHealthCheck(debug bool) {
|
|||
case <-t.C:
|
||||
blockchainPool.HealthCheck()
|
||||
logStr := "Client pool healthcheck."
|
||||
for b := range configBlockchains {
|
||||
for b := range supportedBlockchains {
|
||||
cp := clientPool[b]
|
||||
clients := cp.CleanInactiveClientNodes()
|
||||
logStr += fmt.Sprintf(" Active %s clients: %d.", b, clients)
|
||||
|
@ -170,7 +168,7 @@ func Server() {
|
|||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
configBlockchains = make(map[string]bool)
|
||||
supportedBlockchains = make(map[string]bool)
|
||||
|
||||
// Parse nodes and set list of proxies
|
||||
for i, nodeConfig := range nodeConfigs {
|
||||
|
@ -181,7 +179,7 @@ func Server() {
|
|||
}
|
||||
|
||||
// Append to supported blockchain set
|
||||
configBlockchains[nodeConfig.Blockchain] = true
|
||||
supportedBlockchains[nodeConfig.Blockchain] = true
|
||||
|
||||
proxyToEndpoint := httputil.NewSingleHostReverseProxy(endpoint)
|
||||
// If required detailed timeout configuration, define node.GethReverseProxy.Transport = &http.Transport{}
|
||||
|
|
Ładowanie…
Reference in New Issue