Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"agentconfig.go",
"config.go",
],
importpath = "go-common/app/service/main/dapper/conf",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/conf:go_default_library",
"//library/log:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/BurntSushi/toml:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,68 @@
package conf
import (
"fmt"
"github.com/BurntSushi/toml"
"go-common/library/conf"
"go-common/library/log"
)
const (
_agentConfigKey = "dapper-agent.toml"
)
// LoadAgentConfig LoadAgentConfig
func LoadAgentConfig() (*AgentConfig, error) {
if confPath != "" {
cfg := new(AgentConfig)
_, err := toml.DecodeFile(confPath, cfg)
return cfg, err
}
return remoteAgentConfig()
}
// AgentConfig config for dapper agent
type AgentConfig struct {
Servers []string `toml:"servers"`
Log *log.Config `toml:"log"`
Queue *QueueConfig `toml:"queue"`
UDPCollect UDPCollectConfig `toml:"udp_collect"`
}
// QueueConfig internal queue config
type QueueConfig struct {
// queue local stroage path
MemBuckets int `toml:"mem_buckets"`
BucketBytes int `toml:"bucket_bytes"`
CacheDir string `toml:"cache_dir"`
}
// UDPCollectConfig collect config
type UDPCollectConfig struct {
Workers int `toml:"workers"`
Addr string `toml:"addr"`
}
func remoteAgentConfig() (*AgentConfig, error) {
client, err := conf.New()
if err != nil {
return nil, fmt.Errorf("new config center client error: %s", err)
}
data, ok := client.Value2(_agentConfigKey)
if !ok {
return nil, fmt.Errorf("load config center error key %s not found", _agentConfigKey)
}
cfg := new(AgentConfig)
_, err = toml.Decode(data, cfg)
if err != nil {
return nil, fmt.Errorf("could not decode config file %s, error: %s", _agentConfigKey, err)
}
go func() {
for range client.Event() {
// ignore config change event
}
}()
return cfg, nil
}

View File

@@ -0,0 +1,129 @@
package conf
import (
"errors"
"flag"
"github.com/BurntSushi/toml"
"go-common/library/conf"
"go-common/library/log"
xtime "go-common/library/time"
)
func init() {
flag.StringVar(&confPath, "conf", "", "config file")
}
var (
confPath string
// Conf conf
Conf = &Config{}
client *conf.Client
)
// Config config.
type Config struct {
Log *log.Config `toml:"log"`
HBase *HBaseConfig `toml:"hbase"`
InfluxDB *InfluxDBConfig `toml:"influx_db"`
Collect *Collect `toml:"collect"`
BatchWriter *BatchWriter `toml:"batch_writer"`
Dapper *DapperConfig `toml:"dapper"`
KafkaCollect *KafkaCollect `toml:"kafka_collect"`
}
// DapperConfig .
type DapperConfig struct {
RetentionDay int `toml:"retention_day"`
APIListen string `toml:"api_listen"`
}
// HBaseConfig hbase config
type HBaseConfig struct {
Namespace string `toml:"namespace"`
Addrs string `toml:"addrs"`
RPCQueueSize int `toml:"rpc_queue_size"`
FlushInterval xtime.Duration `toml:"flush_interval"`
EffectiveUser string `toml:"effective_user"`
RegionLookupTimeout xtime.Duration `toml:"region_lookup_timeout"`
RegionReadTimeout xtime.Duration `toml:"region_read_timeout"`
}
// InfluxDBConfig InfluxDBConfig
type InfluxDBConfig struct {
Addr string `toml:"addr"`
Username string `toml:"username"`
Password string `toml:"password"`
Database string `toml:"database"`
}
// Collect config.
type Collect struct {
Network string
Addr string
}
// KafkaCollect .
type KafkaCollect struct {
Topic string `toml:"topic"`
Addrs []string `toml:"addrs"`
}
// BatchWriter config
type BatchWriter struct {
SummaryWorkers int `toml:"summary_workers"`
SummaryBulkSize int `toml:"summary_bulk_size"`
SummaryChanSize int `toml:"summary_chan_size"`
RawWorkers int `toml:"raw_workers"`
RawBufSize int `toml:"raw_buf_size"`
RawChanSize int `toml:"raw_chan_size"`
FlushInterval xtime.Duration `toml:"flush_interval"`
}
// Init config
func Init() (err error) {
if confPath != "" {
return local()
}
return remote()
}
func local() (err error) {
_, err = toml.DecodeFile(confPath, &Conf)
return
}
func remote() (err error) {
if client, err = conf.New(); err != nil {
return
}
if err = load(); err != nil {
return
}
go func() {
for range client.Event() {
log.Info("config reload")
if err := load(); err != nil {
log.Error("config reload error (%v)", err)
}
}
}()
return
}
func load() (err error) {
var (
s string
ok bool
tmpConf *Config
)
if s, ok = client.Value2("dapper-service.toml"); !ok {
return errors.New("load config center error")
}
if _, err = toml.Decode(s, &tmpConf); err != nil {
return errors.New("could not decode config")
}
*Conf = *tmpConf
return
}