Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_binary(
name = "cmd",
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
data = [
"rank-service.toml",
"test.toml",
],
importpath = "go-common/app/service/main/rank/cmd",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/rank/conf:go_default_library",
"//app/service/main/rank/server/gorpc:go_default_library",
"//app/service/main/rank/server/http:go_default_library",
"//app/service/main/rank/service:go_default_library",
"//library/conf/env:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/naming:go_default_library",
"//library/naming/discovery:go_default_library",
"//library/net/ip:go_default_library",
"//library/net/trace:go_default_library",
],
)

View File

@@ -0,0 +1,81 @@
package main
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"time"
"go-common/app/service/main/rank/conf"
rpc "go-common/app/service/main/rank/server/gorpc"
"go-common/app/service/main/rank/server/http"
"go-common/app/service/main/rank/service"
"go-common/library/conf/env"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
"go-common/library/naming"
"go-common/library/naming/discovery"
xip "go-common/library/net/ip"
"go-common/library/net/trace"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Log)
defer log.Close()
log.Info("start")
trace.Init(conf.Conf.Tracer)
defer trace.Close()
ecode.Init(conf.Conf.Ecode)
// int service
svr := service.New(conf.Conf)
rpcSvr := rpc.New(conf.Conf, svr)
http.Init(conf.Conf, svr)
// start discovery register
var (
err error
cancel context.CancelFunc
)
if env.IP == "" {
ip := xip.InternalIP()
dis := discovery.New(nil)
ins := &naming.Instance{
Zone: env.Zone,
Env: env.DeployEnv,
AppID: env.AppID,
Addrs: []string{
"http://" + ip + ":" + env.HTTPPort,
"gorpc://" + ip + ":" + env.GORPCPort,
},
}
cancel, err = dis.Register(context.Background(), ins)
if err != nil {
panic(err)
}
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
if cancel != nil {
cancel()
}
rpcSvr.Close()
time.Sleep(time.Second * 2)
svr.Close()
log.Info("rank-service exit")
return
case syscall.SIGHUP:
default:
return
}
}
}

View File

@@ -0,0 +1,99 @@
# uat config.
[bm]
addr = "0.0.0.0:7861"
timeout = "1s"
[rpcServer]
proto = "tcp"
addr = "0.0.0.0:7869"
[rank]
switchAll = false
ticker = "10s"
rowsLimit = 1000
batchSleep = "10ms"
batchStep = "24h"
filePath = "/data/backup/rank-service/"
fileName = "rmap_%d.pb"
[log]
dir="/data/log/rank-service"
[mysql]
[mysql.bilibiliArchive]
addr = "172.22.34.101:3306"
dsn = "bili_search:BzwF6Ez64RT6Yy2alSKDFGCPgGX5tMlj@tcp(172.22.34.101:3306)/bilibili_archive?timeout=500ms&readTimeout=500ms&writeTimeout=500ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "5s"
[mysql.archiveStat]
addr = "172.22.34.101:3306"
dsn = "bili_search:BzwF6Ez64RT6Yy2alSKDFGCPgGX5tMlj@tcp(172.22.34.101:3306)/archive_stat?timeout=500ms&readTimeout=500ms&writeTimeout=500ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "5s"
[mysql.bilibiliTV]
addr = "172.22.34.101:3309"
dsn = "bili_search:OsQ2cmCoWpafd91gEAPIiNV87Fjq6nZu@tcp(172.22.34.101:3309)/bilibili_tv?timeout=500ms&readTimeout=500ms&writeTimeout=500ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "5s"
[databus]
[databus.Archive]
key = "2511663d546f1413"
secret = "cde3b480836cc76df3d635470f991caa"
group = "Archive-MainSearch-S"
topic = "Archive-T"
action = "sub"
name = "rank-service/archive-sub"
proto = "tcp"
addr = "172.18.33.50:6205"
idle = 1
active = 1
dialTimeout = "1s"
readTimeout = "60s"
writeTimeout = "1s"
idleTimeout = "10s"
[databus.StatView]
key = "2511663d546f1413"
secret = "cde3b480836cc76df3d635470f991caa"
group = "StatView-MainSearch-S"
topic = "StatView-T"
action = "sub"
name = "rank-service/statView-sub"
proto = "tcp"
addr = "172.18.33.50:6205"
idle = 1
active = 1
dialTimeout = "1s"
readTimeout = "60s"
writeTimeout = "1s"
idleTimeout = "10s"
[databus.UgcTvBinlog]
key = "2511663d546f1413"
secret = "cde3b480836cc76df3d635470f991caa"
group = "UgcTvBinlog-MainSearch-S"
topic = "UgcTvBinlog-T"
action = "sub"
name = "rank-service/ugcTvBinlog-sub"
proto = "tcp"
addr = "172.18.33.50:6205"
idle = 1
active = 1
dialTimeout = "1s"
readTimeout = "60s"
writeTimeout = "1s"
idleTimeout = "10s"

View File

@@ -0,0 +1,96 @@
# dev config.
[bm]
addr = "0.0.0.0:7861"
timeout = "1s"
[rank]
switchAll = false
switchIncr = false
ticker = "10s"
rowsLimit = 1000
batchSleep = "10ms"
batchStep = "24h"
filePath = "/data/backup/rank-service/"
fileName = "rmap_%d.pb"
[log]
dir="/data/log/rank-service"
[mysql]
[mysql.bilibiliArchive]
addr = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_archive?timeout=500ms&readTimeout=500ms&writeTimeout=500ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "500ms"
execTimeout = "500ms"
tranTimeout = "500ms"
[mysql.archiveStat]
addr = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/archive_stat?timeout=500ms&readTimeout=500ms&writeTimeout=500ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "500ms"
execTimeout = "500ms"
tranTimeout = "500ms"
[mysql.bilibiliTV]
addr = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_tv?timeout=500ms&readTimeout=500ms&writeTimeout=500ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "500ms"
execTimeout = "500ms"
tranTimeout = "500ms"
[databus]
[databus.StatView]
key = "170e302355453683"
secret = "3d0e8db7bed0503949e545a469789279"
group = "Favorite-MainSearch-S"
topic = "StatView-T"
action = "sub"
name = "rank-service/statView-sub"
proto = "tcp"
addr = "172.16.33.158:6205"
idle = 1
active = 1
dialTimeout = "1s"
readTimeout = "60s"
writeTimeout = "1s"
idleTimeout = "10s"
[databus.UgcTvBinlog]
key = "170e302355453683"
secret = "3d0e8db7bed0503949e545a469789279"
group = "Favorite-MainSearch-S"
topic = "UgcTvBinlog-T"
action = "sub"
name = "rank-service/UgcTvBinlog-sub"
proto = "tcp"
addr = "172.16.33.158:6205"
idle = 1
active = 1
dialTimeout = "1s"
readTimeout = "60s"
writeTimeout = "1s"
idleTimeout = "10s"
[databus.Archive]
key = "170e302355453683"
secret = "3d0e8db7bed0503949e545a469789279"
group = "Rank-MainSearch-S"
topic = "Archive-T"
action = "sub"
name = "rank-service/archive-sub"
proto = "tcp"
addr = "172.16.33.158:6205"
idle = 1
active = 1
dialTimeout = "1s"
readTimeout = "60s"
writeTimeout = "1s"
idleTimeout = "10s"