Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ type TencentConfig struct {
RateLimit float64 `yaml:"rate_limit"`
MetricQueryBatchSize int `yaml:"metric_query_batch_size"`
Filename string `yaml:"filename"`
CacheInterval int64 `yaml:"cache_interval"` // 单位 s
CacheInterval int64 `yaml:"cache_interval"` // 单位 s
IsInternational bool `yaml:"is_international"` // true 表示是国际站
}

func NewConfig() *TencentConfig {
Expand Down
18 changes: 16 additions & 2 deletions pkg/metric/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ type TcmMetricRepositoryImpl struct {
credential common.CredentialIface
monitorClient *monitor.Client
monitorClientInGuangzhou *monitor.Client
monitorClientInSinapore *monitor.Client
limiter *rate.Limiter // 限速
ctx context.Context
IsInternational bool

queryMetricBatchSize int

Expand Down Expand Up @@ -133,7 +135,9 @@ func (repo *TcmMetricRepositoryImpl) GetSamples(s *TcmSeries, st int64, et int64
}

response := &v20180724.GetMonitorDataResponse{}
if util.IsStrInList(config.QcloudNamespace, s.Metric.Meta.ProductName) {
if repo.IsInternational && s.Metric.Meta.ProductName == "QAAP" {
response, err = repo.monitorClientInSinapore.GetMonitorData(request)
} else if util.IsStrInList(config.QcloudNamespace, s.Metric.Meta.ProductName) {
response, err = repo.monitorClientInGuangzhou.GetMonitorData(request)
} else {
response, err = repo.monitorClient.GetMonitorData(request)
Expand Down Expand Up @@ -185,7 +189,9 @@ func (repo *TcmMetricRepositoryImpl) listSampleByBatch(
request := repo.buildGetMonitorDataRequest(m, seriesList, st, et)

response := &v20180724.GetMonitorDataResponse{}
if util.IsStrInList(config.QcloudNamespace, m.Meta.ProductName) {
if repo.IsInternational && m.Meta.ProductName == "QAAP" {
response, err = repo.monitorClientInSinapore.GetMonitorData(request)
} else if util.IsStrInList(config.QcloudNamespace, m.Meta.ProductName) {
response, err = repo.monitorClientInGuangzhou.GetMonitorData(request)
} else {
response, err = repo.monitorClient.GetMonitorData(request)
Expand Down Expand Up @@ -282,13 +288,21 @@ func NewTcmMetricRepository(cred common.CredentialIface, conf *config.TencentCon
if err != nil {
return
}
var monitorClientInSingapore *monitor.Client
if conf.IsInternational {
if monitorClientInSingapore, err = client.NewMonitorClient(cred, conf, "ap-singapore"); err != nil {
return
}
}

repo = &TcmMetricRepositoryImpl{
credential: cred,
monitorClient: monitorClient,
monitorClientInGuangzhou: monitorClientInGuangzhou,
monitorClientInSinapore: monitorClientInSingapore,
limiter: rate.NewLimiter(rate.Limit(conf.RateLimit), 1),
ctx: context.Background(),
IsInternational: conf.IsInternational,
queryMetricBatchSize: conf.MetricQueryBatchSize,
logger: logger,
}
Expand Down