Skip to content

Commit 9459d0c

Browse files
authored
fix: metrics上报支持按业务基本黑名单设置 (#171)
1 parent 754c78f commit 9459d0c

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

cmd/feed-server/service/metric.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
// nolint:funlen
23-
func initMetric(name string) *metric {
23+
func initMetric(name string, blacklistBizIds []uint32) *metric {
2424
m := new(metric)
2525
labels := prm.Labels{"name": name}
2626
m.watchTotal = prometheus.NewGaugeVec(prometheus.GaugeOpts{
@@ -141,6 +141,12 @@ func initMetric(name string) *metric {
141141
}, versionChange)
142142
metrics.Register().MustRegister(m.changeTotalSeconds)
143143

144+
black := make(map[uint32]struct{}, len(blacklistBizIds))
145+
for _, id := range blacklistBizIds {
146+
black[id] = struct{}{}
147+
}
148+
m.blacklist = black
149+
144150
return m
145151
}
146152

@@ -170,6 +176,7 @@ type metric struct {
170176
changeTotalFileSize *prometheus.HistogramVec
171177
// 变更总耗时
172178
changeTotalSeconds *prometheus.HistogramVec
179+
blacklist map[uint32]struct{}
173180
}
174181

175182
// collectDownload collects metrics for download
@@ -178,3 +185,8 @@ func (m *metric) collectDownload(biz string, totalSize, delayRequests, delayMill
178185
m.downloadDelayRequests.With(prm.Labels{"bizID": biz}).Set(float64(delayRequests))
179186
m.downloadDelayMilliseconds.With(prm.Labels{"bizID": biz}).Set(float64(delayMilliseconds))
180187
}
188+
189+
func (m *metric) shouldReport(bizID uint32) bool {
190+
_, exists := m.blacklist[bizID]
191+
return !exists
192+
}

cmd/feed-server/service/rpc_sidecar.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,9 @@ func (s *Service) GetSingleFileContent(req *pbfs.GetSingleFileContentReq,
10691069
}
10701070

10711071
func (s *Service) handleResourceUsageMetrics(bizID uint32, appName string, resource sfs.ResourceUsage) {
1072+
if !s.mc.shouldReport(bizID) {
1073+
return
1074+
}
10721075
s.mc.clientMaxCPUUsage.WithLabelValues(strconv.Itoa(int(bizID)), appName).Set(resource.CpuMaxUsage)
10731076
s.mc.clientCurrentCPUUsage.WithLabelValues(strconv.Itoa(int(bizID)), appName).Set(resource.CpuUsage)
10741077
s.mc.clientMaxMemUsage.WithLabelValues(strconv.Itoa(int(bizID)), appName).Set(float64(resource.MemoryMaxUsage))
@@ -1077,6 +1080,9 @@ func (s *Service) handleResourceUsageMetrics(bizID uint32, appName string, resou
10771080

10781081
// 暴露客户端版本变更事件到metrics
10791082
func (s *Service) clientEventChangeRecord(basicData *sfs.BasicData, appMeta *sfs.SideAppMeta) {
1083+
if !s.mc.shouldReport(basicData.BizID) {
1084+
return
1085+
}
10801086
if basicData == nil && appMeta == nil {
10811087
return
10821088
}

cmd/feed-server/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func NewService(sd serviced.Discover, name string) (*Service, error) {
102102
state: state,
103103
name: name,
104104
provider: provider,
105-
mc: initMetric(name),
105+
mc: initMetric(name, cc.FeedServer().Metric.BlacklistBizIDs),
106106
gwMux: gwMux,
107107
rl: rl,
108108
}, nil

pkg/cc/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ type FeedServerSetting struct {
391391
Downstream Downstream `yaml:"downstream"`
392392
MRLimiter MatchReleaseLimiter `yaml:"matchReleaseLimiter"`
393393
RateLimiter RateLimiter `yaml:"rateLimiter"`
394+
Metric Metric `yaml:"metrics"`
394395
}
395396

396397
// trySetFlagBindIP try set flag bind ip.

pkg/cc/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,11 @@ type RateLimiter struct {
11561156
IP BasicRL `yaml:"ip"`
11571157
}
11581158

1159+
// metrics 上报时过滤的业务名单
1160+
type Metric struct {
1161+
BlacklistBizIDs []uint32 `yaml:"blacklistBizIds"`
1162+
}
1163+
11591164
// BizRLs defines the rate limiters for biz
11601165
type BizRLs struct {
11611166
Default BasicRL `yaml:"default"`

0 commit comments

Comments
 (0)