Skip to content

Commit

Permalink
fullfill solana-labs#7
Browse files Browse the repository at this point in the history
  • Loading branch information
pieceofr committed Oct 3, 2022
1 parent 8a1ab21 commit c75c8b1
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 132 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@
## Server Setup
### API Service
API service for getting the results of ping service.
Use `APIServer: Enabled: true` to turn on in in config-{cluster}.yaml. The default is true for mainnet but false for other clusters.
Use `APIServer: Enabled: true` to turn on in in config-{cluster}.yaml.

### PingService
This is similar to "solana ping" tool in solana tool but can do concurrent rpc query.
It send transactions to rpc endpoint and wait for transactions is confirmed.
Use `PingServiceEnabled: true` to turn on in config-{cluster}.yaml. The default is On.

Use `PingServiceEnabled: true` to turn on in config-{cluster}.yaml.
### RetensionService
Use `Retension: Enabled: true` in config.yaml to turn on. Default is Off.
Clean database data periodically.

### SlackReportService
Use `SlackReport: Enabled:true` in config-{cluster}.yaml to turn on. Default is On.
send summary of ping result to a slack channel periodically.
### ReportService
Use `Report: Enabled:true` in config-{cluster}.yaml to turn on.
ping-api service supports sedning report & alert to both slack and discord.
Use `Report: Slack: Report: Enabled:true` to turn on Slack Report.
This sends summary of ping result to a slack channel periodically.
Use `Report: Slack: Alert: Enabled:true` to turn on Slack Alert.
This will send alert when a event is triggered. See **Alert Spam Filter** for more info.
Use `Report: Discord: Report: Enabled:true` to turn on Discord Report.
Use `Report: Discord: Alert: Enabled:true` to turn on Discord Alert.

### SlackAlertService
Use `SlackReport: SlackAlert: Enabled: true` in config-{cluster}.yaml to turn on. Default is On.
If confirmation loss is greater than a thredhold, send an alert to a channel

+ Example:Run only API Query Server
In config.yaml ServerSetup:
Expand All @@ -38,10 +40,19 @@ Retension:
Enabled: false
(config-{cluster}.yaml)
PingEnabled: true
SlackReport:
Report:
Enabled: true
SlackAlert:
Enabled: true
Slack:
Report:
Enabled: true
Alert:
Enabled: true
Discord:
Enabled: true
Report:
Enabled: false
Alert:
Enabled: true
```
## Installation
- download executable file
Expand Down
19 changes: 6 additions & 13 deletions alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ type AlertTrigger struct {

func NewAlertTrigger(conf ClusterConfig) AlertTrigger {
s := AlertTrigger{}
s.FilePath = conf.SlackReport.SlackAlert.LevelFilePath
s.FilePath = conf.Report.LevelFilePath
s.CurrentLoss = 0
s.LastLoss = 0
s.ThresholdLevels = []float64{float64(conf.SlackReport.SlackAlert.LossThreshold), float64(50), float64(75), float64(100)}
s.FilePath = conf.SlackReport.SlackAlert.LevelFilePath
s.ThresholdLevels = []float64{float64(conf.Report.LossThreshold), float64(50), float64(75), float64(100)}
s.ThresholdIndex = s.ReadIndexFromFile()
return s
}
Expand Down Expand Up @@ -73,10 +72,13 @@ func (s *AlertTrigger) ReadIndexFromFile() int {

// Doing rule here
func (s *AlertTrigger) ShouldAlertSend() bool {
if s.ThresholdLevels[0] == 0 {
return true
}
if s.CurrentLoss < s.ThresholdLevels[0] {
s.ThresholdIndex = 0
s.WritIndexToFile(0)
log.Println("Loss < 20 :", s.CurrentLoss, "Index:", s.ThresholdIndex)
log.Println("Loss = ", s.CurrentLoss, " < ", s.ThresholdLevels[0], "Index:", s.ThresholdIndex)
return false
}
// adjust threshold up, include index = 0
Expand All @@ -98,12 +100,3 @@ func (s *AlertTrigger) ShouldAlertSend() bool {
log.Println("ThresholdLevel NOT change. Loss:", s.CurrentLoss, "Index:", s.ThresholdIndex)
return false
}

func AlertSend(conf ClusterConfig, globalStat *GlobalStatistic, globalErrorStatistic map[string]int, threadhold float64) {
payload := SlackPayload{}
payload.AlertPayload(conf, globalStat, globalErrorStatistic, threadhold)
err := SlackSend(conf.SlackReport.SlackAlert.WebHook, &payload)
if err != nil {
log.Println("SlackSend Error:", err)
}
}
33 changes: 24 additions & 9 deletions config-devnet.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ AlternativeEnpoint:
SlackAlert: # failover alert
Enabled: true
Webhook:
DiscordAlert:
Enabled: true
Webhook:
PingConfig:
Receiver: 9qT3WeLV5o3t3GVgCk9A3mpTRjSb9qBvnfrAsVKLhmU5 # change your receive account here
NumWorkers: 3 #change number of concurent run here
Expand All @@ -30,12 +33,24 @@ PingConfig:
MinPerPingTime: 10
RequestUnits: 200000 # change RequestUnits
ComputeUnitPrice: 1000 # change ComputeUnitPrice
SlackReport:
Enabled: false
WebHook:
ReportInterval: 600
SlackAlert:
Enabled: true
WebHook:
LossThreshold: 20
LevelFilePath: /yourpath/level-mainnet.env
Report:
Interval: 600
LossThreshold: 20
LevelFilePath: /yourpath/level-devnet.env
Slack:
Report:
Enabled: true
Webhook:
Alert:
Enabled: true
Webhook:
Discord:
BotName: ping-service
BotAvatarURL:
Report:
Enabled: true
Webhook:
Alert:
Enabled: true
Webhook:

32 changes: 23 additions & 9 deletions config-mainnet-beta.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ AlternativeEnpoint:
SlackAlert: # failover alert
Enabled: true
Webhook:
DiscordAlert:
Enabled: true
Webhook:
PingConfig:
Receiver: 9qT3WeLV5o3t3GVgCk9A3mpTRjSb9qBvnfrAsVKLhmU5 # change your receive account here
NumWorkers: 3 #change number of concurent run here
Expand All @@ -30,12 +33,23 @@ PingConfig:
MinPerPingTime: 10
RequestUnits: 200000 # change RequestUnits
ComputeUnitPrice: 1000 # change ComputeUnitPrice
SlackReport:
Enabled: false
WebHook:
ReportInterval: 600
SlackAlert:
Enabled: true
WebHook:
LossThreshold: 20
LevelFilePath: /yourpath/level-mainnet.env
Report:
Interval: 600
LossThreshold: 20
LevelFilePath: /yourpath/level-mainnet.env
Slack:
Report:
Enabled: true
Webhook:
Alert:
Enabled: true
Webhook:
Discord:
BotName: ping-service
BotAvatarURL:
Report:
Enabled: false
Webhook:
Alert:
Enabled: true
Webhook:
32 changes: 23 additions & 9 deletions config-testnet.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ AlternativeEnpoint:
SlackAlert: # failover alert
Enabled: true
Webhook:
DiscordAlert:
Enabled: true
Webhook:
PingConfig:
Receiver: 9qT3WeLV5o3t3GVgCk9A3mpTRjSb9qBvnfrAsVKLhmU5 # change your receive account here
NumWorkers: 3 #change number of concurent run here
Expand All @@ -30,12 +33,23 @@ PingConfig:
MinPerPingTime: 10
RequestUnits: 200000 # change RequestUnits
ComputeUnitPrice: 1000 # change ComputeUnitPrice
SlackReport:
Enabled: false
WebHook:
ReportInterval: 600
SlackAlert:
Enabled: true
WebHook:
LossThreshold: 20
LevelFilePath: /yourpath/level-mainnet.env
Report:
Interval: 600
LossThreshold: 20
LevelFilePath: /yourpath/level-testnet.env
Slack:
Report:
Enabled: false
Webhook:
Alert:
Enabled: true
Webhook:
Discord:
BotName: ping-service
BotAvatarURL:
Report:
Enabled: false
Webhook:
Alert:
Enabled: true
Webhook:
36 changes: 25 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,27 @@ type PingConfig struct {
RequestUnits uint32
ComputeUnitPrice uint64
}

type WebHookConfig struct {
Enabled bool
Webhook string
}
type SlackReport struct {
Enabled bool
WebHook string
ReportInterval int
SlackAlert
Report WebHookConfig
Alert WebHookConfig
}
type SlackAlert struct {
type DiscordReport struct {
BotName string
BotAvatarURL string
Report WebHookConfig
Alert WebHookConfig
}
type Report struct {
Enabled bool
WebHook string
LossThreshold int
Interval int
LossThreshold float64
LevelFilePath string
Slack SlackReport
Discord DiscordReport
}
type APIServer struct {
Enabled bool
Expand Down Expand Up @@ -86,17 +95,22 @@ type RPCEndpoint struct {
Piority int
MaxRetry int
}
type EndpointAlert struct {
Enabled bool
Webhook string
}
type AlternativeEnpoint struct {
HostList []RPCEndpoint
SlackAlert
HostList []RPCEndpoint
SlackAlert EndpointAlert
DiscordAlert EndpointAlert
}

type ClusterPing struct {
APIServer
PingServiceEnabled bool
AlternativeEnpoint
PingConfig
SlackReport
Report
}

type ClusterConfig struct {
Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var config Config

//Cluster enum
// Cluster enum
type Cluster string

var database *gorm.DB
Expand All @@ -25,7 +25,7 @@ const useGCloudDB = true

type ClustersToRun string

//Cluster enum
// Cluster enum
const (
MainnetBeta Cluster = "MainnetBeta"
Testnet = "Testnet"
Expand Down Expand Up @@ -60,19 +60,20 @@ func init() {
log.Println("Mainnet.ClusterPing.PingServiceEnabled", config.Mainnet.ClusterPing.PingServiceEnabled)
log.Println("Mainnet.ClusterPing.AlternativeEnpoint.HostList", config.Mainnet.ClusterPing.AlternativeEnpoint.HostList)
log.Println("Mainnet.ClusterPing.PingConfig", config.Mainnet.ClusterPing.PingConfig)
log.Println("Mainnet.ClusterPing.SlackReport", config.Mainnet.ClusterPing.SlackReport)
log.Println("Mainnet.ClusterPing.Report", config.Mainnet.ClusterPing.Report)
log.Println("--- Testnet Ping --- ")
log.Println("Mainnet.ClusterPing.APIServer", config.Testnet.ClusterPing.APIServer)
log.Println("Mainnet.ClusterPing.PingServiceEnabled", config.Mainnet.ClusterPing.PingServiceEnabled)
log.Println("Testnet.ClusterPing.AlternativeEnpoint.HostList", config.Testnet.ClusterPing.AlternativeEnpoint.HostList)
log.Println("Testnet.ClusterPing.PingConfig", config.Testnet.ClusterPing.PingConfig)
log.Println("Testnet.ClusterPing.SlackReport", config.Testnet.ClusterPing.SlackReport)
log.Println("Testnet.ClusterPing.Report", config.Testnet.ClusterPing.Report)
log.Println("--- Devnet Ping --- ")
log.Println("Devnet.ClusterPing.APIServer", config.Devnet.ClusterPing.APIServer)
log.Println("Devnet.ClusterPing.Enabled", config.Devnet.ClusterPing.PingServiceEnabled)
log.Println("Devnet.ClusterPing.AlternativeEnpoint.HostList", config.Devnet.ClusterPing.AlternativeEnpoint.HostList)
log.Println("Devnet.ClusterPing.PingConfig", config.Devnet.ClusterPing.PingConfig)
log.Println("Devnet.ClusterPing.SlackReport", config.Devnet.ClusterPing.SlackReport)
log.Println("Devnet.ClusterPing.Report", config.Devnet.ClusterPing.Report)

log.Println(" *** Config End *** ")

ResponseErrIdentifierInit()
Expand Down
Loading

0 comments on commit c75c8b1

Please sign in to comment.