protection vmselect ,avoid metrics point too much let vmselect cup load very, very high (#1478)

* protection vmselect……

* protection vmselect……

* protection vmselect……

* All checks have failed,fix

Co-authored-by: lirenzuo <lirenzuo@shein.com>
This commit is contained in:
匠心零度 2021-07-28 19:39:35 +08:00 committed by GitHub
parent 857fa4e28a
commit 626073bca8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,7 @@ var (
maxTagValuesPerSearch = flag.Int("search.maxTagValues", 100e3, "The maximum number of tag values returned per search")
maxTagValueSuffixesPerSearch = flag.Int("search.maxTagValueSuffixesPerSearch", 100e3, "The maximum number of tag value suffixes returned from /metrics/find")
maxMetricsPerSearch = flag.Int("search.maxUniqueTimeseries", 300e3, "The maximum number of unique time series each search can scan")
maxMetricsPointSearch = flag.Int("search.maxMetricsPointSearch", 300e3, "control search metrics point number")
precisionBits = flag.Int("precisionBits", 64, "The number of precision bits to store per each value. Lower precision bits improves data compression at the cost of precision loss")
disableRPCCompression = flag.Bool(`rpc.disableCompression`, false, "Disable compression of RPC traffic. This reduces CPU usage at the cost of higher network bandwidth usage")
@ -1070,13 +1071,20 @@ func (s *Server) processVMSelectSearch(ctx *vmselectRequestCtx) error {
return fmt.Errorf("cannot send empty error message: %w", err)
}
count := 0
// Send found blocks to vmselect.
for ctx.sr.NextMetricBlock() {
ctx.mb.MetricName = ctx.sr.MetricBlockRef.MetricName
ctx.sr.MetricBlockRef.BlockRef.MustReadBlock(&ctx.mb.Block, fetchData)
vmselectMetricBlocksRead.Inc()
vmselectMetricRowsRead.Add(ctx.mb.Block.RowsCount())
rowsCount := ctx.mb.Block.RowsCount()
vmselectMetricRowsRead.Add(rowsCount)
count += rowsCount
if count > *maxMetricsPointSearch {
logger.Errorf("more than -search.maxMetricsPointSearch=%d point,discard more points", *maxMetricsPointSearch)
break
}
ctx.dataBuf = ctx.mb.Marshal(ctx.dataBuf[:0])
if err := ctx.writeDataBufBytes(); err != nil {