-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (64 loc) · 1.87 KB
/
main.go
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
package main
import (
"fmt"
c "github.com/Lukpier/flinkmonitoring/config"
"github.com/Lukpier/flinkmonitoring/monitoring"
"github.com/akamensky/argparse"
"github.com/spf13/viper"
"log"
"os"
"time"
)
func loadConfig(configPath string) c.Config {
// Set the file name of the configurations file
viper.SetConfigFile(configPath)
// Enable VIPER to read Environment Variables
viper.AutomaticEnv()
viper.SetConfigType("yml")
var configuration c.Config
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("Error reading config file, %s", err)
}
err := viper.Unmarshal(&configuration)
if err != nil {
log.Fatalf("Unable to decode into struct, %v", err)
}
return configuration
}
func main() {
parser := argparse.NewParser("flinkmonitoring", "Listens for exceptions of all / specified flink jobs and send them to the specified receiver address")
configPath := parser.String("c", "config", &argparse.Options{Required: true, Help: "path to config file"})
jobId := parser.String("j", "jobid", &argparse.Options{Required: false, Default: "", Help: "optional job id"})
err := parser.Parse(os.Args)
if err != nil {
// In case of error print error and print usage
// This can also be done by passing -h or --help flags
log.Fatal(parser.Usage(err))
}
config := loadConfig(*configPath)
lookuper := monitoring.NewExceptionLookuper(config)
done := make(chan bool)
ticker := time.NewTicker(time.Second * time.Duration(config.Poll))
fmt.Println("Starting lookup for exception at ", config.Flink.Endpoint)
go func() {
for {
select {
case <-done:
ticker.Stop()
return
case <-ticker.C:
var err error
if *jobId != "" {
err = lookuper.LookupJobAndSend(*jobId)
} else {
err = lookuper.LookupAllAndSend()
}
if err != nil {
log.Fatal(err)
}
}
}
}()
time.Sleep(time.Second * time.Duration(config.For))
done <- true
}