Skip to content

Commit

Permalink
对齐版本
Browse files Browse the repository at this point in the history
  • Loading branch information
zianazhao committed Feb 2, 2023
1 parent 7e58454 commit 029afb9
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions pkg/collector/handler_clb_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ var (
}
)

var (
LbPrivateSupportDimensions = []string{"vip", "vpcId", "loadBalancerPort", "protocol", "lanIp", "port"}
)

func init() {
registerHandler(ClbPrivateNamespace, defaultHandlerEnabled, NewClbPrivateHandler)
}
Expand Down Expand Up @@ -123,35 +119,32 @@ func (h *ClbPrivateHandler) GetSeriesByAll(m *metric.TcmMetric) ([]*metric.TcmSe
return slist, nil
}

func (h *ClbPrivateHandler) GetSeriesByCustom(m *metric.TcmMetric) (slist []*metric.TcmSeries, err error) {
func (h *ClbPrivateHandler) GetSeriesByCustom(m *metric.TcmMetric) ([]*metric.TcmSeries, error) {
var slist []*metric.TcmSeries
for _, ql := range m.Conf.CustomQueryDimensions {
if !h.checkMonitorQueryKeys(m, ql) {
v, ok := ql[h.monitorQueryKey]
if !ok {
level.Error(h.logger).Log(
"msg", fmt.Sprintf("not found %s in queryDimensions", h.monitorQueryKey),
"ql", fmt.Sprintf("%v", ql))
continue
}

s, err := metric.NewTcmSeries(m, ql, nil)
ins, err := h.collector.InstanceRepo.Get(v)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail", "metric", m.Meta.MetricName,
"ql", fmt.Sprintf("%v", ql))
level.Error(h.logger).Log("msg", "Instance not found", "err", err, "id", v)
continue
}
slist = append(slist, s)
}
return
}
func (h *ClbPrivateHandler) checkMonitorQueryKeys(m *metric.TcmMetric, ql map[string]string) bool {
for k := range ql {
if !util.IsStrInList(LbPrivateSupportDimensions, k) {
level.Error(h.logger).Log("msg", fmt.Sprintf("not found %s in supportQueryDimensions", k),
"ql", fmt.Sprintf("%v", ql),
"sd", fmt.Sprintf("%v", m.Meta.SupportDimensions),
)
return false

sl, err := h.getSeriesByMetricType(m, ins)
if err != nil {
level.Error(h.logger).Log("msg", "Create metric series fail",
"metric", m.Meta.MetricName, "instacne", ins.GetInstanceId())
continue
}
slist = append(slist, sl...)
}
return true
return slist, nil
}

func (h *ClbPrivateHandler) getSeriesByMetricType(m *metric.TcmMetric, ins instance.TcInstance) ([]*metric.TcmSeries, error) {
var dimensions []string
for _, v := range m.Meta.SupportDimensions {
Expand Down

0 comments on commit 029afb9

Please sign in to comment.