Skip to content

Commit 42c2487

Browse files
authored
Merge pull request #91 from BattleL/dev/support-qaap-international
Dev/support qaap international
2 parents a23f323 + 2c7e196 commit 42c2487

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pkg/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ type TencentConfig struct {
144144
RateLimit float64 `yaml:"rate_limit"`
145145
MetricQueryBatchSize int `yaml:"metric_query_batch_size"`
146146
Filename string `yaml:"filename"`
147-
CacheInterval int64 `yaml:"cache_interval"` // 单位 s
147+
CacheInterval int64 `yaml:"cache_interval"` // 单位 s
148+
IsInternational bool `yaml:"is_international"` // true 表示是国际站
148149
}
149150

150151
func NewConfig() *TencentConfig {

pkg/metric/repository.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ type TcmMetricRepositoryImpl struct {
3939
credential common.CredentialIface
4040
monitorClient *monitor.Client
4141
monitorClientInGuangzhou *monitor.Client
42+
monitorClientInSinapore *monitor.Client
4243
limiter *rate.Limiter // 限速
4344
ctx context.Context
45+
IsInternational bool
4446

4547
queryMetricBatchSize int
4648

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

135137
response := &v20180724.GetMonitorDataResponse{}
136-
if util.IsStrInList(config.QcloudNamespace, s.Metric.Meta.ProductName) {
138+
if repo.IsInternational && s.Metric.Meta.ProductName == "QAAP" {
139+
response, err = repo.monitorClientInSinapore.GetMonitorData(request)
140+
} else if util.IsStrInList(config.QcloudNamespace, s.Metric.Meta.ProductName) {
137141
response, err = repo.monitorClientInGuangzhou.GetMonitorData(request)
138142
} else {
139143
response, err = repo.monitorClient.GetMonitorData(request)
@@ -185,7 +189,9 @@ func (repo *TcmMetricRepositoryImpl) listSampleByBatch(
185189
request := repo.buildGetMonitorDataRequest(m, seriesList, st, et)
186190

187191
response := &v20180724.GetMonitorDataResponse{}
188-
if util.IsStrInList(config.QcloudNamespace, m.Meta.ProductName) {
192+
if repo.IsInternational && m.Meta.ProductName == "QAAP" {
193+
response, err = repo.monitorClientInSinapore.GetMonitorData(request)
194+
} else if util.IsStrInList(config.QcloudNamespace, m.Meta.ProductName) {
189195
response, err = repo.monitorClientInGuangzhou.GetMonitorData(request)
190196
} else {
191197
response, err = repo.monitorClient.GetMonitorData(request)
@@ -282,13 +288,21 @@ func NewTcmMetricRepository(cred common.CredentialIface, conf *config.TencentCon
282288
if err != nil {
283289
return
284290
}
291+
var monitorClientInSingapore *monitor.Client
292+
if conf.IsInternational {
293+
if monitorClientInSingapore, err = client.NewMonitorClient(cred, conf, "ap-singapore"); err != nil {
294+
return
295+
}
296+
}
285297

286298
repo = &TcmMetricRepositoryImpl{
287299
credential: cred,
288300
monitorClient: monitorClient,
289301
monitorClientInGuangzhou: monitorClientInGuangzhou,
302+
monitorClientInSinapore: monitorClientInSingapore,
290303
limiter: rate.NewLimiter(rate.Limit(conf.RateLimit), 1),
291304
ctx: context.Background(),
305+
IsInternational: conf.IsInternational,
292306
queryMetricBatchSize: conf.MetricQueryBatchSize,
293307
logger: logger,
294308
}

0 commit comments

Comments
 (0)