Skip to content

Commit f9a5d8e

Browse files
juexiaolinjuexiaolin
andauthored
v2.1.2 (#18)
* fix: get instance more limit * fix: supportDimensions missing key * fix(cache): get metric from cache nil * fix(dcx): skip invalid metric Co-authored-by: juexiaolin <[email protected]>
1 parent b42642a commit f9a5d8e

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

pkg/collector/handler_dcx.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ package collector
33
import (
44
"github.com/go-kit/kit/log"
55
"github.com/tencentyun/tencentcloud-exporter/pkg/metric"
6+
"github.com/tencentyun/tencentcloud-exporter/pkg/util"
7+
"strings"
68
)
79

810
const (
911
DcxNamespace = "QCE/DCX"
1012
DcxInstanceidKey = "directConnectConnId"
1113
)
1214

15+
var (
16+
DcxInvalidMetricNames = []string{"rxbytes", "txbytes"}
17+
)
18+
1319
func init() {
1420
registerHandler(DcxNamespace, defaultHandlerEnabled, NewDcxHandler)
1521
}
@@ -19,6 +25,9 @@ type dcxHandler struct {
1925
}
2026

2127
func (h *dcxHandler) CheckMetricMeta(meta *metric.TcmMeta) bool {
28+
if util.IsStrInList(DcxInvalidMetricNames, strings.ToLower(meta.MetricName)) {
29+
return false
30+
}
2231
return true
2332
}
2433

pkg/collector/product.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (c *TcProductCollector) loadMetricsByProductConf() (err error) {
124124
}
125125
// 指标元数据处理, false=跳过
126126
if !c.handler.CheckMetricMeta(meta) {
127-
level.Error(c.logger).Log("msg", " Metric meta check fail, skip", "Namespace", c.Namespace, "name", meta.MetricName)
127+
level.Warn(c.logger).Log("msg", " Metric not support, skip", "Namespace", c.Namespace, "name", meta.MetricName)
128128
continue
129129
}
130130

@@ -143,7 +143,7 @@ func (c *TcProductCollector) loadMetricsByProductConf() (err error) {
143143
}
144144
// 指标过滤
145145
if !c.handler.IsIncludeMetric(nm) {
146-
level.Error(c.logger).Log("msg", " Metric not support, skip", "Namespace", c.Namespace, "name", nm.Meta.MetricName)
146+
level.Warn(c.logger).Log("msg", " Metric not support, skip", "Namespace", c.Namespace, "name", nm.Meta.MetricName)
147147
continue
148148
}
149149
c.MetricMap[meta.MetricName] = nm

pkg/metric/cache.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package metric
22

33
import (
4+
"fmt"
45
"github.com/go-kit/kit/log"
56
"github.com/go-kit/kit/log/level"
67
"strings"
@@ -20,7 +21,15 @@ func (c *TcmMetricCache) GetMeta(namespace string, name string) (*TcmMeta, error
2021
if err != nil {
2122
return nil, err
2223
}
23-
return c.metaCache[namespace][strings.ToLower(name)], nil
24+
np, exists := c.metaCache[namespace]
25+
if !exists {
26+
return nil, fmt.Errorf("namespace cache not exists")
27+
}
28+
m, exists := np[strings.ToLower(name)]
29+
if !exists {
30+
return nil, fmt.Errorf("metric cache not exists")
31+
}
32+
return m, nil
2433
}
2534

2635
func (c *TcmMetricCache) ListMetaByNamespace(namespace string) ([]*TcmMeta, error) {

0 commit comments

Comments
 (0)