Update according to code review

Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
This commit is contained in:
Jeanette Tan 2023-05-05 02:29:50 +08:00
parent 19a4f314f5
commit 40240c9c1c
4 changed files with 13 additions and 12 deletions

View file

@ -491,7 +491,7 @@ type ScrapeConfig struct {
LabelValueLengthLimit uint `yaml:"label_value_length_limit,omitempty"` LabelValueLengthLimit uint `yaml:"label_value_length_limit,omitempty"`
// More than this many buckets in a native histogram will cause the scrape to // More than this many buckets in a native histogram will cause the scrape to
// fail. // fail.
NativeHistogramBucketLimit uint `yaml:"bucket_limit,omitempty"` NativeHistogramBucketLimit uint `yaml:"native_histogram_bucket_limit,omitempty"`
// We cannot do proper Go type embedding below as the parser will then parse // We cannot do proper Go type embedding below as the parser will then parse
// values arbitrarily into the overflow maps of further-down types. // values arbitrarily into the overflow maps of further-down types.

View file

@ -377,10 +377,10 @@ metric_relabel_configs:
# change in the future. # change in the future.
[ target_limit: <int> | default = 0 ] [ target_limit: <int> | default = 0 ]
# Limit on total number of positive and negative buckets allowed in a native # Limit on total number of positive and negative buckets allowed in a single
# histogram. If this is exceeded, the entire scrape will be treated as failed. # native histogram. If this is exceeded, the entire scrape will be treated as
# 0 means no limit. # failed. 0 means no limit.
[ sample_limit: <int> | default = 0 ] [ native_histogram_bucket_limit: <int> | default = 0 ]
``` ```
Where `<job_name>` must be unique across all scrape configurations. Where `<job_name>` must be unique across all scrape configurations.

View file

@ -18,6 +18,7 @@ import (
"encoding/binary" "encoding/binary"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
// Intentionally using client model to simulate client in tests. // Intentionally using client model to simulate client in tests.
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
) )

View file

@ -193,8 +193,8 @@ var (
) )
targetScrapeNativeHistogramBucketLimit = prometheus.NewCounter( targetScrapeNativeHistogramBucketLimit = prometheus.NewCounter(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "prometheus_target_scrapes_histogram_exceeded_bucket_limit_total", Name: "prometheus_target_scrapes_exceeded_native_histogram_bucket_limit_total",
Help: "Total number of scrapes that hit the native histograms bucket limit and were rejected.", Help: "Total number of scrapes that hit the native histogram bucket limit and were rejected.",
}, },
) )
) )
@ -744,17 +744,17 @@ func mutateReportSampleLabels(lset labels.Labels, target *Target) labels.Labels
} }
// appender returns an appender for ingested samples from the target. // appender returns an appender for ingested samples from the target.
func appender(app storage.Appender, limit, bucketLimit int) storage.Appender { func appender(app storage.Appender, sampleLimit, bucketLimit int) storage.Appender {
app = &timeLimitAppender{ app = &timeLimitAppender{
Appender: app, Appender: app,
maxTime: timestamp.FromTime(time.Now().Add(maxAheadTime)), maxTime: timestamp.FromTime(time.Now().Add(maxAheadTime)),
} }
// The limit is applied after metrics are potentially dropped via relabeling. // The sampleLimit is applied after metrics are potentially dropped via relabeling.
if limit > 0 { if sampleLimit > 0 {
app = &limitAppender{ app = &limitAppender{
Appender: app, Appender: app,
limit: limit, limit: sampleLimit,
} }
} }
@ -1707,7 +1707,7 @@ loop:
} }
if bucketLimitErr != nil { if bucketLimitErr != nil {
if err == nil { if err == nil {
err = bucketLimitErr // if sample limit is hit, that error takes precedence err = bucketLimitErr // If sample limit is hit, that error takes precedence.
} }
// We only want to increment this once per scrape, so this is Inc'd outside the loop. // We only want to increment this once per scrape, so this is Inc'd outside the loop.
targetScrapeNativeHistogramBucketLimit.Inc() targetScrapeNativeHistogramBucketLimit.Inc()