-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.go
More file actions
101 lines (88 loc) · 3.34 KB
/
main.go
File metadata and controls
101 lines (88 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"autonity-oracle/config"
contract "autonity-oracle/contract_binder/contract"
"autonity-oracle/monitor"
"autonity-oracle/server"
"autonity-oracle/types"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/metrics/exp"
"github.com/ethereum/go-ethereum/metrics/influxdb"
)
func main() { //nolint
conf := config.MakeConfig()
log.Printf("\n\n\n \tRunning autonity oracle server %s\n\twith account: %s\n\twith plugin directory: %s\n "+
"\twith profile data directory: %s\n "+"\tby connecting to L1 node: %s\n \ton oracle contract address: %s \n\n\n",
config.VersionString(config.Version), conf.Key.Address.String(), conf.PluginDIR, conf.ProfileDir,
conf.AutonityWSUrl, types.OracleContractAddress)
// start prometheus metrics exposer if it is enabled.
if conf.MetricConfigs.EnablePrometheusExp {
metrics.Enabled = true
log.Println("Prometheus metrics exposer enabled")
address := fmt.Sprintf("%s:%d", conf.MetricConfigs.HTTP, conf.MetricConfigs.Port)
log.Printf("Enabling stand-alone metrics HTTP endpoint: %s", address)
exp.Setup(address)
}
// start influxDB metrics reporter if it is enabled.
tagsMap := config.SplitTagsFlag(conf.MetricConfigs.InfluxDBTags)
if conf.MetricConfigs.EnableInfluxDB {
metrics.Enabled = true
log.Printf("InfluxDB metrics enabled")
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry,
config.MetricsInterval,
conf.MetricConfigs.InfluxDBEndpoint,
conf.MetricConfigs.InfluxDBDatabase,
conf.MetricConfigs.InfluxDBUsername,
conf.MetricConfigs.InfluxDBPassword,
config.MetricsNameSpace, tagsMap)
// Start system runtime metrics collection
go metrics.CollectProcessMetrics(config.MetricsInterval)
} else if conf.MetricConfigs.EnableInfluxDBV2 {
metrics.Enabled = true
log.Printf("InfluxDBV2 metrics enabled")
go influxdb.InfluxDBV2WithTags(metrics.DefaultRegistry,
config.MetricsInterval,
conf.MetricConfigs.InfluxDBEndpoint,
conf.MetricConfigs.InfluxDBToken,
conf.MetricConfigs.InfluxDBBucket,
conf.MetricConfigs.InfluxDBOrganization,
config.MetricsNameSpace, tagsMap)
// Start system runtime metrics collection
go metrics.CollectProcessMetrics(config.MetricsInterval)
}
// create metrics before the context of the usage.
monitor.InitOracleMetrics()
// dail to L1 network, and start oracle server.
dialer := &types.L1Dialer{}
client, err := dialer.Dial(conf.AutonityWSUrl)
if err != nil {
log.Printf("cannot connect to Autonity network via web socket: %s", err.Error())
os.Exit(1)
}
oc, err := contract.NewOracle(types.OracleContractAddress, client)
if err != nil {
log.Printf("cannot bind to oracle contract in Autonity network via web socket: %s", err.Error())
os.Exit(1)
}
oracle := server.NewServer(conf, dialer, client, oc)
go oracle.Start()
defer oracle.Stop()
monitorConfig := monitor.DefaultMonitorConfig
ms := monitor.New(&monitorConfig, conf.ProfileDir)
ms.Start()
// Wait for interrupt signal to gracefully shut down the server with
// a timeout of 5 seconds.
quit := make(chan os.Signal, 1)
// kill (no param) default send syscall.SIGTERM
// kill -2 is syscall.SIGINT
// kill -9 is syscall.SIGKILL but can't be caught, so don't need to add it
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
ms.Stop()
log.Println("shutting down oracle server...")
}