diff --git a/pkg/client/client.go b/pkg/client/client.go index 0c653d5..857f457 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1,6 +1,7 @@ package client import ( + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions" "net/http" "net/url" @@ -10,6 +11,7 @@ import ( kafka "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka/v20190819" clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317" cmq "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cmq/v20190304" + apiCommon "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" cynosdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb/v20190107" @@ -305,3 +307,14 @@ func NewGAAPClient(cred common.CredentialIface, conf *config.TencentConfig) (*ga } return gaap.NewClient(cred, conf.Credential.Region, cpf) } + +func NewGAAPCommonClient(cred common.CredentialIface, conf *config.TencentConfig) *apiCommon.Client { + cpf := profile.NewClientProfile() + if conf.Credential.IsInternal == true { + cpf.HttpProfile.Endpoint = "gaap.internal.tencentcloudapi.com" + } else { + cpf.HttpProfile.Endpoint = "gaap.tencentcloudapi.com" + } + cpf.HttpProfile.ReqMethod = "POST" + return apiCommon.NewCommonClient(cred, regions.Guangzhou, cpf) +} diff --git a/pkg/collector/handler_qaap.go b/pkg/collector/handler_qaap.go index be6230e..68e5c05 100644 --- a/pkg/collector/handler_qaap.go +++ b/pkg/collector/handler_qaap.go @@ -8,6 +8,7 @@ import ( "github.com/tencentyun/tencentcloud-exporter/pkg/instance" "github.com/tencentyun/tencentcloud-exporter/pkg/metric" "github.com/tencentyun/tencentcloud-exporter/pkg/util" + "strings" "time" ) @@ -16,14 +17,32 @@ const ( QaapInstanceidKey = "channelId" ) +var ( + QaapDetail2GroupidMetricNames = []string{ + "GroupInFlow", "GroupOutFlow", "GroupInbandwidth", "GroupOutbandwidth", + } + QaapIpDetailMetricNames = []string{ + "IpConnum", "IpInbandwidth", "IpInpacket", "IpLatency", "IpOutbandwidth", "IpOutpacket", "IpPacketLoss", + } + QaapListenerStatMetricNames = []string{ + "ListenerConnum", "ListenerOutbandwidth", "ListenerInpacket", "ListenerOutpacket", "ListenerInbandwidth", + } + QaapListenerRsMetricNames = []string{ + "ListenerRsStatus", + } + QaapRuleRsMetricNames = []string{ + "RuleRsStatus", + } +) + func init() { registerHandler(QaapNamespace, defaultHandlerEnabled, NewQaapHandler) } type QaapHandler struct { baseProductHandler - tcpListenersRepo instance.QaapTcInstanceTCPListenersRepository - udpListenersRepo instance.QaapTcInstanceUDPListenersRepository + commonQaapInstanceInfoRepo instance.CommonQaapTcInstanceRepository + qaapInstanceInfoRepo instance.QaapTcInstanceInfoRepository } func (h *QaapHandler) IsMetricMetaVaild(meta *metric.TcmMeta) bool { @@ -137,9 +156,16 @@ func (h *QaapHandler) getSeriesByMetricType(m *metric.TcmMetric, ins instance.Tc for _, v := range m.Meta.SupportDimensions { dimensions = append(dimensions, v) } - - if util.IsStrInList(dimensions, "listenerId") { - return h.getListenerIdSeries(m, ins) + if util.IsStrInList(QaapDetail2GroupidMetricNames, m.Meta.MetricName) { + return h.getQaapDetail2GroupidSeries(m, ins) + } else if util.IsStrInList(QaapIpDetailMetricNames, m.Meta.MetricName) { + return h.getQaapIpDetailSeries(m, ins) + } else if util.IsStrInList(QaapListenerStatMetricNames, m.Meta.MetricName) { + return h.getQaapListenerStatSeries(m, ins) + } else if util.IsStrInList(QaapListenerRsMetricNames, m.Meta.MetricName) { + return h.getQaapListenerRsSeries(m, ins) + } else if util.IsStrInList(QaapRuleRsMetricNames, m.Meta.MetricName) { + return h.getRuleRsSeries(m, ins) } else { return h.getInstanceSeries(m, ins) } @@ -147,7 +173,6 @@ func (h *QaapHandler) getSeriesByMetricType(m *metric.TcmMetric, ins instance.Tc func (h *QaapHandler) getInstanceSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) { var series []*metric.TcmSeries - ql := map[string]string{ h.monitorQueryKey: ins.GetMonitorQueryKey(), } @@ -160,9 +185,10 @@ func (h *QaapHandler) getInstanceSeries(m *metric.TcmMetric, ins instance.TcInst return series, nil } -func (h *QaapHandler) getListenerIdSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) { +func (h *QaapHandler) getQaapListenerRsSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) { var series []*metric.TcmSeries - tcpListenersInfos, err := h.tcpListenersRepo.GetTCPListenersInfo(ins.GetInstanceId()) + + tcpListenersInfos, err := h.qaapInstanceInfoRepo.GetTCPListenersInfo(ins.GetInstanceId()) if err != nil { return nil, err } @@ -182,7 +208,7 @@ func (h *QaapHandler) getListenerIdSeries(m *metric.TcmMetric, ins instance.TcIn series = append(series, s) } } - udpListenersInfos, err := h.udpListenersRepo.GetUDPListenersInfo(ins.GetInstanceId()) + udpListenersInfos, err := h.qaapInstanceInfoRepo.GetUDPListenersInfo(ins.GetInstanceId()) if err != nil { return nil, err } @@ -205,19 +231,126 @@ func (h *QaapHandler) getListenerIdSeries(m *metric.TcmMetric, ins instance.TcIn return series, nil } +func (h *QaapHandler) getQaapDetail2GroupidSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) { + var series []*metric.TcmSeries + proxyGroupLists, err := h.qaapInstanceInfoRepo.GetProxyGroupList(ins.GetInstanceId()) + if err != nil { + return nil, err + } + for _, proxyGroupList := range proxyGroupLists.Response.ProxyGroupList { + ql := map[string]string{ + "GroupId": *proxyGroupList.GroupId, + } + s, err := metric.NewTcmSeries(m, ql, ins) + if err != nil { + return nil, err + } + series = append(series, s) + } + return series, nil +} + +func (h *QaapHandler) getQaapIpDetailSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) { + var series []*metric.TcmSeries + noneBgpIpLists, err := h.commonQaapInstanceInfoRepo.GetCommonQaapNoneBgpIpList(ins.GetInstanceId()) + if err != nil { + return nil, err + } + for _, instanceSet := range noneBgpIpLists.Response.InstanceSet { + ql := map[string]string{ + "ip": instanceSet.IP, + "proxyid": instanceSet.ProxyId, + "groupid": instanceSet.GroupId, + "isp": strings.ToLower(instanceSet.Isp), + } + s, err := metric.NewTcmSeries(m, ql, ins) + if err != nil { + return nil, err + } + series = append(series, s) + } + return series, nil +} + +func (h *QaapHandler) getQaapListenerStatSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) { + var series []*metric.TcmSeries + ProxyInstances, err := h.commonQaapInstanceInfoRepo.GetCommonQaapProxyInstances(ins.GetInstanceId()) + if err != nil { + return nil, err + } + for _, proxySet := range ProxyInstances.Response.ProxySet { + for _, l4Listener := range proxySet.L4ListenerSet { + ql := map[string]string{ + "instanceid": proxySet.ProxyId, + "listenerid": l4Listener.ListenerId, + "protocol": l4Listener.Protocol, + } + s, err := metric.NewTcmSeries(m, ql, ins) + if err != nil { + return nil, err + } + series = append(series, s) + } + for _, l7Listener := range proxySet.L7ListenerSet { + ql := map[string]string{ + "instanceid": proxySet.ProxyId, + "listenerid": l7Listener.ListenerId, + "protocol": l7Listener.ForwardProtocol, + } + s, err := metric.NewTcmSeries(m, ql, ins) + if err != nil { + return nil, err + } + series = append(series, s) + } + + } + return series, nil +} +func (h *QaapHandler) getRuleRsSeries(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) { + var series []*metric.TcmSeries + ProxyInstances, err := h.commonQaapInstanceInfoRepo.GetCommonQaapProxyInstances(ins.GetInstanceId()) + if err != nil { + return nil, err + } + for _, proxySet := range ProxyInstances.Response.ProxySet { + for _, l7Listener := range proxySet.L7ListenerSet { + for _, rule := range l7Listener.RuleSet { + for _, rs := range rule.RsSet { + ql := map[string]string{ + "instanceid": proxySet.ProxyId, + "listenerid": l7Listener.ListenerId, + "ruleid": rule.RuleId, + "rs_ip": rs.RsInfo, + } + s, err := metric.NewTcmSeries(m, ql, ins) + if err != nil { + return nil, err + } + series = append(series, s) + } + + } + + } + + } + return series, nil +} + func NewQaapHandler(cred common.CredentialIface, c *TcProductCollector, logger log.Logger) (handler ProductHandler, err error) { - tcpListenersRepo, err := instance.NewQaapTcInstanceTCPListenersRepository(cred, c.Conf, logger) + qaapInstanceInfo, err := instance.NewQaapTcInstanceInfoRepository(cred, c.Conf, logger) if err != nil { return nil, err } - relodInterval := time.Duration(c.ProductConf.RelodIntervalMinutes * int64(time.Minute)) - tcpListenersRepoCache := instance.NewTcGaapInstanceeTCPListenersCache(tcpListenersRepo, relodInterval, logger) + reloadInterval := time.Duration(c.ProductConf.RelodIntervalMinutes * int64(time.Minute)) + qaapInstanceInfoCache := instance.NewTcGaapInstanceeInfosCache(qaapInstanceInfo, reloadInterval, logger) - udpListenersRepo, err := instance.NewQaapTcInstanceUDPListenersRepository(cred, c.Conf, logger) + commonQaapInstanceInfoRepo, err := instance.NewCommonQaapTcInstanceRepository(cred, c.Conf, logger) if err != nil { return nil, err } - udpListenersRepoCache := instance.NewTcGaapInstanceeUDPListenersCache(udpListenersRepo, relodInterval, logger) + commonQaapInstanceInfoCache := instance.NewTcCommonGaapInstanceeInfosCache(commonQaapInstanceInfoRepo, reloadInterval, logger) handler = &QaapHandler{ baseProductHandler: baseProductHandler{ @@ -225,8 +358,8 @@ func NewQaapHandler(cred common.CredentialIface, c *TcProductCollector, logger l collector: c, logger: logger, }, - tcpListenersRepo: tcpListenersRepoCache, - udpListenersRepo: udpListenersRepoCache, + commonQaapInstanceInfoRepo: commonQaapInstanceInfoCache, + qaapInstanceInfoRepo: qaapInstanceInfoCache, } return diff --git a/pkg/config/config.go b/pkg/config/config.go index e7e55cc..f00fa68 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -144,7 +144,7 @@ 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 表示是国际站 } diff --git a/pkg/instance/cache.go b/pkg/instance/cache.go index fc36ed4..0e5f772 100644 --- a/pkg/instance/cache.go +++ b/pkg/instance/cache.go @@ -528,9 +528,11 @@ func NewVbcTcInstanceDRegionRepositoryCache(repo VbcTcInstanceDRegionRepository, } // gaap -type TcGaapInstanceeTCPListenersCache struct { - Raw QaapTcInstanceTCPListenersRepository - cache map[string]*gaap.DescribeTCPListenersResponse +type TcGaapInstanceeInfosCache struct { + Raw QaapTcInstanceInfoRepository + tcpCache map[string]*gaap.DescribeTCPListenersResponse + udpCache map[string]*gaap.DescribeUDPListenersResponse + groupCache map[string]*gaap.DescribeProxyGroupListResponse lastReloadTime map[string]time.Time reloadInterval time.Duration mu sync.Mutex @@ -538,10 +540,10 @@ type TcGaapInstanceeTCPListenersCache struct { logger log.Logger } -func (c *TcGaapInstanceeTCPListenersCache) GetTCPListenersInfo(instanceId string) (*gaap.DescribeTCPListenersResponse, error) { +func (c *TcGaapInstanceeInfosCache) GetTCPListenersInfo(instanceId string) (*gaap.DescribeTCPListenersResponse, error) { lrtime, exists := c.lastReloadTime[instanceId] if exists && time.Now().Sub(lrtime) < c.reloadInterval { - namespace, ok := c.cache[instanceId] + namespace, ok := c.tcpCache[instanceId] if ok { return namespace, nil } @@ -551,16 +553,54 @@ func (c *TcGaapInstanceeTCPListenersCache) GetTCPListenersInfo(instanceId string if err != nil { return nil, err } - c.cache[instanceId] = tcpListeners + c.tcpCache[instanceId] = tcpListeners c.lastReloadTime[instanceId] = time.Now() level.Debug(c.logger).Log("msg", "Get gaap Namespaces info from api", "instanceId", instanceId) return tcpListeners, nil } +func (c *TcGaapInstanceeInfosCache) GetUDPListenersInfo(instanceId string) (*gaap.DescribeUDPListenersResponse, error) { + lrtime, exists := c.lastReloadTime[instanceId] + if exists && time.Now().Sub(lrtime) < c.reloadInterval { + namespace, ok := c.udpCache[instanceId] + if ok { + return namespace, nil + } + } -func NewTcGaapInstanceeTCPListenersCache(repo QaapTcInstanceTCPListenersRepository, reloadInterval time.Duration, logger log.Logger) QaapTcInstanceTCPListenersRepository { - cache := &TcGaapInstanceeTCPListenersCache{ + udpListeners, err := c.Raw.GetUDPListenersInfo(instanceId) + if err != nil { + return nil, err + } + c.udpCache[instanceId] = udpListeners + c.lastReloadTime[instanceId] = time.Now() + level.Debug(c.logger).Log("msg", "Get gaap Namespaces info from api", "instanceId", instanceId) + return udpListeners, nil +} +func (c *TcGaapInstanceeInfosCache) GetProxyGroupList(instanceId string) (*gaap.DescribeProxyGroupListResponse, error) { + lrtime, exists := c.lastReloadTime[instanceId] + if exists && time.Now().Sub(lrtime) < c.reloadInterval { + namespace, ok := c.groupCache[instanceId] + if ok { + return namespace, nil + } + } + + proxyGroupList, err := c.Raw.GetProxyGroupList(instanceId) + if err != nil { + return nil, err + } + c.groupCache[instanceId] = proxyGroupList + c.lastReloadTime[instanceId] = time.Now() + level.Debug(c.logger).Log("msg", "Get gaap Namespaces info from api", "instanceId", instanceId) + return proxyGroupList, nil +} + +func NewTcGaapInstanceeInfosCache(repo QaapTcInstanceInfoRepository, reloadInterval time.Duration, logger log.Logger) QaapTcInstanceInfoRepository { + cache := &TcGaapInstanceeInfosCache{ Raw: repo, - cache: map[string]*gaap.DescribeTCPListenersResponse{}, + tcpCache: map[string]*gaap.DescribeTCPListenersResponse{}, + udpCache: map[string]*gaap.DescribeUDPListenersResponse{}, + groupCache: map[string]*gaap.DescribeProxyGroupListResponse{}, lastReloadTime: map[string]time.Time{}, reloadInterval: reloadInterval, logger: logger, @@ -568,42 +608,62 @@ func NewTcGaapInstanceeTCPListenersCache(repo QaapTcInstanceTCPListenersReposito return cache } -type TcGaapInstanceeUDPListenersCache struct { - Raw QaapTcInstanceUDPListenersRepository - cache map[string]*gaap.DescribeUDPListenersResponse - lastReloadTime map[string]time.Time - reloadInterval time.Duration - mu sync.Mutex +type TcCommonGaapInstanceeInfosCache struct { + Raw CommonQaapTcInstanceRepository + proxyInstancesCache map[string]ProxyInstancesRsp + noneBgpIpListCache map[string]NoneBgpIpListRsp + lastReloadTime map[string]time.Time + reloadInterval time.Duration + mu sync.Mutex logger log.Logger } -func (c *TcGaapInstanceeUDPListenersCache) GetUDPListenersInfo(instanceId string) (*gaap.DescribeUDPListenersResponse, error) { +func (c *TcCommonGaapInstanceeInfosCache) GetCommonQaapProxyInstances(instanceId string) (ProxyInstancesRsp, error) { lrtime, exists := c.lastReloadTime[instanceId] if exists && time.Now().Sub(lrtime) < c.reloadInterval { - namespace, ok := c.cache[instanceId] + namespace, ok := c.proxyInstancesCache[instanceId] if ok { return namespace, nil } } - tcpListeners, err := c.Raw.GetUDPListenersInfo(instanceId) + proxyGroupList, err := c.Raw.GetCommonQaapProxyInstances(instanceId) if err != nil { - return nil, err + return ProxyInstancesRsp{}, err } - c.cache[instanceId] = tcpListeners + c.proxyInstancesCache[instanceId] = proxyGroupList c.lastReloadTime[instanceId] = time.Now() level.Debug(c.logger).Log("msg", "Get gaap Namespaces info from api", "instanceId", instanceId) - return tcpListeners, nil + return proxyGroupList, nil +} +func (c *TcCommonGaapInstanceeInfosCache) GetCommonQaapNoneBgpIpList(instanceId string) (NoneBgpIpListRsp, error) { + lrtime, exists := c.lastReloadTime[instanceId] + if exists && time.Now().Sub(lrtime) < c.reloadInterval { + namespace, ok := c.noneBgpIpListCache[instanceId] + if ok { + return namespace, nil + } + } + + proxyGroupList, err := c.Raw.GetCommonQaapNoneBgpIpList(instanceId) + if err != nil { + return NoneBgpIpListRsp{}, err + } + c.noneBgpIpListCache[instanceId] = proxyGroupList + c.lastReloadTime[instanceId] = time.Now() + level.Debug(c.logger).Log("msg", "Get gaap Namespaces info from api", "instanceId", instanceId) + return proxyGroupList, nil } -func NewTcGaapInstanceeUDPListenersCache(repo QaapTcInstanceUDPListenersRepository, reloadInterval time.Duration, logger log.Logger) QaapTcInstanceUDPListenersRepository { - cache := &TcGaapInstanceeUDPListenersCache{ - Raw: repo, - cache: map[string]*gaap.DescribeUDPListenersResponse{}, - lastReloadTime: map[string]time.Time{}, - reloadInterval: reloadInterval, - logger: logger, +func NewTcCommonGaapInstanceeInfosCache(repo CommonQaapTcInstanceRepository, reloadInterval time.Duration, logger log.Logger) CommonQaapTcInstanceRepository { + cache := &TcCommonGaapInstanceeInfosCache{ + Raw: repo, + proxyInstancesCache: map[string]ProxyInstancesRsp{}, + noneBgpIpListCache: map[string]NoneBgpIpListRsp{}, + lastReloadTime: map[string]time.Time{}, + reloadInterval: reloadInterval, + logger: logger, } return cache } diff --git a/pkg/instance/repository_qaap.go b/pkg/instance/repository_qaap.go index 7de54b9..e2d651b 100644 --- a/pkg/instance/repository_qaap.go +++ b/pkg/instance/repository_qaap.go @@ -1,9 +1,11 @@ package instance import ( + "encoding/json" "fmt" "github.com/go-kit/log" "github.com/go-kit/log/level" + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" sdk "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529" selfcommon "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" @@ -93,17 +95,38 @@ func NewQaapTcInstanceRepository(cred common.CredentialIface, c *config.TencentC return } -// TCPListeners -type QaapTcInstanceTCPListenersRepository interface { +// DescribeProxyGroupList +type QaapTcInstanceInfoRepository interface { + GetProxyGroupList(instanceId string) (*sdk.DescribeProxyGroupListResponse, error) + GetUDPListenersInfo(instanceId string) (*sdk.DescribeUDPListenersResponse, error) GetTCPListenersInfo(instanceId string) (*sdk.DescribeTCPListenersResponse, error) } -type QaapTcInstanceTCPListenersRepositoryImpl struct { +type QaapTcInstanceInfoRepositoryImpl struct { client *sdk.Client logger log.Logger } -func (repo *QaapTcInstanceTCPListenersRepositoryImpl) GetTCPListenersInfo(instanceId string) (*sdk.DescribeTCPListenersResponse, error) { +func (repo *QaapTcInstanceInfoRepositoryImpl) GetProxyGroupList(instanceId string) (*sdk.DescribeProxyGroupListResponse, error) { + req := sdk.NewDescribeProxyGroupListRequest() + var offset int64 = 0 + var limit int64 = 100 + var projectId int64 = -1 + req.Limit = &limit + req.Offset = &offset + req.ProjectId = &projectId + return repo.client.DescribeProxyGroupList(req) +} +func (repo *QaapTcInstanceInfoRepositoryImpl) GetUDPListenersInfo(instanceId string) (*sdk.DescribeUDPListenersResponse, error) { + req := sdk.NewDescribeUDPListenersRequest() + var offset uint64 = 0 + var limit uint64 = 100 + req.Limit = &limit + req.Offset = &offset + req.ProxyId = selfcommon.StringPtr(instanceId) + return repo.client.DescribeUDPListeners(req) +} +func (repo *QaapTcInstanceInfoRepositoryImpl) GetTCPListenersInfo(instanceId string) (*sdk.DescribeTCPListenersResponse, error) { req := sdk.NewDescribeTCPListenersRequest() var offset uint64 = 0 var limit uint64 = 100 @@ -113,44 +136,128 @@ func (repo *QaapTcInstanceTCPListenersRepositoryImpl) GetTCPListenersInfo(instan return repo.client.DescribeTCPListeners(req) } -func NewQaapTcInstanceTCPListenersRepository(cred common.CredentialIface, c *config.TencentConfig, logger log.Logger) (QaapTcInstanceTCPListenersRepository, error) { +func NewQaapTcInstanceInfoRepository(cred common.CredentialIface, c *config.TencentConfig, logger log.Logger) (QaapTcInstanceInfoRepository, error) { cli, err := client.NewGAAPClient(cred, c) if err != nil { return nil, err } - repo := &QaapTcInstanceTCPListenersRepositoryImpl{ + repo := &QaapTcInstanceInfoRepositoryImpl{ client: cli, logger: logger, } return repo, nil } -// UDPListeners -type QaapTcInstanceUDPListenersRepository interface { - GetUDPListenersInfo(instanceId string) (*sdk.DescribeUDPListenersResponse, error) +// 内部接口 +type ProxyInstancesResponse struct { + TotalCount int64 + ProxySet []ProxyDetail +} +type ProxyInstancesRsp struct { + Response ProxyInstancesResponse +} +type ProxyDetail struct { + ProxyId string + ProxyName string + L4ListenerSet []L4ListenerDetail + L7ListenerSet []L7ListenerDetail +} +type L4ListenerDetail struct { + ListenerId string + ListenerName string + Protocol string + RsSet []BoundRsDetail +} +type BoundRsDetail struct { + RsId string + RsInfo string +} +type L7ListenerDetail struct { + ListenerId string + ListenerName string + ForwardProtocol string + RuleSet []RuleDetail +} +type RuleDetail struct { + RsSet []BoundRsDetail + RuleId string } -type QaapTcInstanceUDPListenersRepositoryImpl struct { - client *sdk.Client +type NoneBgpIpListRsp struct { + Response NoneBgpIpListResponse +} +type NoneBgpIpListResponse struct { + TotalCount int64 + InstanceSet []InstanceDetail +} +type InstanceDetail struct { + IP string + Isp string + ProxyId string + GroupId string +} +type CommonQaapTcInstanceRepository interface { + GetCommonQaapProxyInstances(instanceId string) (ProxyInstancesRsp, error) + GetCommonQaapNoneBgpIpList(instanceId string) (NoneBgpIpListRsp, error) +} + +type CommonQaapTcInstanceRepositoryImpl struct { + client *selfcommon.Client logger log.Logger } -func (repo *QaapTcInstanceUDPListenersRepositoryImpl) GetUDPListenersInfo(instanceId string) (*sdk.DescribeUDPListenersResponse, error) { - req := sdk.NewDescribeUDPListenersRequest() - var offset uint64 = 0 - var limit uint64 = 100 - req.Limit = &limit - req.Offset = &offset - req.ProxyId = selfcommon.StringPtr(instanceId) - return repo.client.DescribeUDPListeners(req) +func (repo *CommonQaapTcInstanceRepositoryImpl) GetCommonQaapProxyInstances(instanceId string) (ProxyInstancesRsp, error) { + var proxyInstancesRsp ProxyInstancesRsp + request := tchttp.NewCommonRequest("gaap", "2018-05-29", "DescribeProxyInstances") + body := map[string]interface{}{ + "Limit": 100, + "Offset": 0, + "ProxyIds": []string{instanceId}, + } + // 设置action所需的请求数据 + err := request.SetActionParameters(body) + if err != nil { + return proxyInstancesRsp, err + } + // 创建common response + response := tchttp.NewCommonResponse() + // 发送请求 + err = repo.client.Send(request, response) + if err != nil { + fmt.Printf("fail to invoke api: %v \n", err) + } + // 获取响应结果 + json.Unmarshal(response.GetBody(), &proxyInstancesRsp) + return proxyInstancesRsp, nil } -func NewQaapTcInstanceUDPListenersRepository(cred common.CredentialIface, c *config.TencentConfig, logger log.Logger) (QaapTcInstanceUDPListenersRepository, error) { - cli, err := client.NewGAAPClient(cred, c) +func (repo *CommonQaapTcInstanceRepositoryImpl) GetCommonQaapNoneBgpIpList(instanceId string) (NoneBgpIpListRsp, error) { + var noneBgpIpListRsp NoneBgpIpListRsp + request := tchttp.NewCommonRequest("gaap", "2018-05-29", "DescribeNoneBgpIpList") + body := map[string]interface{}{ + "Limit": 100, + "Offset": 0, + } + // 设置action所需的请求数据 + err := request.SetActionParameters(body) if err != nil { - return nil, err + return noneBgpIpListRsp, err + } + // 创建common response + response := tchttp.NewCommonResponse() + // 发送请求 + err = repo.client.Send(request, response) + if err != nil { + fmt.Printf("fail to invoke api: %v \n", err) } - repo := &QaapTcInstanceUDPListenersRepositoryImpl{ + // 获取响应结果 + json.Unmarshal(response.GetBody(), &noneBgpIpListRsp) + return noneBgpIpListRsp, nil +} + +func NewCommonQaapTcInstanceRepository(cred common.CredentialIface, c *config.TencentConfig, logger log.Logger) (CommonQaapTcInstanceRepository, error) { + cli := client.NewGAAPCommonClient(cred, c) + repo := &CommonQaapTcInstanceRepositoryImpl{ client: cli, logger: logger, } diff --git a/pkg/metric/repository.go b/pkg/metric/repository.go index 43c10be..e274e05 100644 --- a/pkg/metric/repository.go +++ b/pkg/metric/repository.go @@ -199,7 +199,6 @@ func (repo *TcmMetricRepositoryImpl) listSampleByBatch( if err != nil { return nil, err } - for _, points := range response.Response.DataPoints { samples, ql, e := repo.buildSamples(m, points) if e != nil {