2017-08-16 17:53:03 +05:30
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
import (
|
2020-01-03 03:21:57 +05:30
|
|
|
"net/url"
|
2017-08-16 17:53:03 +05:30
|
|
|
"os"
|
2020-01-03 03:21:57 +05:30
|
|
|
"time"
|
2017-08-16 17:53:03 +05:30
|
|
|
|
2017-08-27 20:40:03 +05:30
|
|
|
"github.com/getsentry/raven-go"
|
2017-08-16 17:53:03 +05:30
|
|
|
"github.com/mono83/slf/rays"
|
2018-01-05 02:40:38 +05:30
|
|
|
"github.com/mono83/slf/recievers/sentry"
|
2017-08-16 17:53:03 +05:30
|
|
|
"github.com/mono83/slf/recievers/statsd"
|
2017-09-04 01:24:46 +05:30
|
|
|
"github.com/mono83/slf/recievers/writer"
|
2017-08-16 17:53:03 +05:30
|
|
|
"github.com/mono83/slf/wd"
|
2020-01-03 03:21:57 +05:30
|
|
|
"github.com/spf13/viper"
|
2017-09-03 00:07:16 +05:30
|
|
|
|
2020-02-08 17:01:47 +05:30
|
|
|
"github.com/elyby/chrly/dispatcher"
|
|
|
|
"github.com/elyby/chrly/http"
|
2020-01-03 03:21:57 +05:30
|
|
|
"github.com/elyby/chrly/mojangtextures"
|
|
|
|
"github.com/elyby/chrly/version"
|
|
|
|
)
|
2017-09-03 00:07:16 +05:30
|
|
|
|
2017-08-27 20:40:03 +05:30
|
|
|
func CreateLogger(statsdAddr string, sentryAddr string) (wd.Watchdog, error) {
|
2017-09-04 01:24:46 +05:30
|
|
|
wd.AddReceiver(writer.New(writer.Options{
|
2020-01-03 03:21:57 +05:30
|
|
|
Marker: false,
|
2017-09-04 01:24:46 +05:30
|
|
|
TimeFormat: "15:04:05.000",
|
|
|
|
}))
|
2020-01-03 03:21:57 +05:30
|
|
|
|
2017-08-16 17:53:03 +05:30
|
|
|
if statsdAddr != "" {
|
|
|
|
hostname, _ := os.Hostname()
|
|
|
|
statsdReceiver, err := statsd.NewReceiver(statsd.Config{
|
2020-01-03 03:21:57 +05:30
|
|
|
Address: statsdAddr,
|
|
|
|
Prefix: "ely.skinsystem." + hostname + ".app.",
|
2017-08-16 17:53:03 +05:30
|
|
|
FlushEvery: 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
wd.AddReceiver(statsdReceiver)
|
|
|
|
}
|
|
|
|
|
2017-08-27 20:40:03 +05:30
|
|
|
if sentryAddr != "" {
|
|
|
|
ravenClient, err := raven.New(sentryAddr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ravenClient.SetEnvironment("production")
|
|
|
|
ravenClient.SetDefaultLoggerName("sentry-watchdog-receiver")
|
2020-01-03 03:21:57 +05:30
|
|
|
programVersion := version.Version()
|
2017-09-03 00:07:16 +05:30
|
|
|
if programVersion != "" {
|
|
|
|
raven.SetRelease(programVersion)
|
|
|
|
}
|
2017-08-27 20:40:03 +05:30
|
|
|
|
|
|
|
sentryReceiver, err := sentry.NewReceiverWithCustomRaven(ravenClient, &sentry.Config{
|
|
|
|
MinLevel: "warn",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
wd.AddReceiver(sentryReceiver)
|
|
|
|
}
|
|
|
|
|
2017-08-16 17:53:03 +05:30
|
|
|
return wd.New("", "").WithParams(rays.Host), nil
|
|
|
|
}
|
2020-01-03 03:21:57 +05:30
|
|
|
|
|
|
|
func init() {
|
|
|
|
viper.SetDefault("queue.loop_delay", 2*time.Second+500*time.Millisecond)
|
|
|
|
viper.SetDefault("queue.batch_size", 10)
|
|
|
|
}
|
|
|
|
|
2020-02-08 15:58:10 +05:30
|
|
|
func CreateMojangUUIDsProvider(emitter http.Emitter) (mojangtextures.UUIDsProvider, error) {
|
2020-01-03 03:21:57 +05:30
|
|
|
var uuidsProvider mojangtextures.UUIDsProvider
|
|
|
|
preferredUuidsProvider := viper.GetString("mojang_textures.uuids_provider.driver")
|
|
|
|
if preferredUuidsProvider == "remote" {
|
|
|
|
remoteUrl, err := url.Parse(viper.GetString("mojang_textures.uuids_provider.url"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
uuidsProvider = &mojangtextures.RemoteApiUuidsProvider{
|
2020-02-08 15:58:10 +05:30
|
|
|
Emitter: emitter,
|
|
|
|
Url: *remoteUrl,
|
2020-01-03 03:21:57 +05:30
|
|
|
}
|
|
|
|
} else {
|
|
|
|
uuidsProvider = &mojangtextures.BatchUuidsProvider{
|
2020-02-08 15:58:10 +05:30
|
|
|
Emitter: emitter,
|
2020-01-03 03:21:57 +05:30
|
|
|
IterationDelay: viper.GetDuration("queue.loop_delay"),
|
|
|
|
IterationSize: viper.GetInt("queue.batch_size"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uuidsProvider, nil
|
|
|
|
}
|
2020-02-08 17:01:47 +05:30
|
|
|
|
|
|
|
func CreateEventDispatcher() dispatcher.EventDispatcher {
|
|
|
|
return dispatcher.New()
|
|
|
|
}
|