mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 03:38:43 +00:00
rfac: removed raw prometheusRuleSize check
This commit is contained in:
parent
15d0a11ca1
commit
2e679711c8
5 changed files with 14 additions and 28 deletions
pkg
|
@ -233,14 +233,6 @@ func (a *Admission) validatePrometheusRules(ar v1.AdmissionReview) *v1.Admission
|
|||
return toAdmissionResponseFailure(errUnmarshalRules, prometheusRuleResource, []error{err})
|
||||
}
|
||||
|
||||
// Check if the size of prometheusRule exceeds 512KB (1048576 Bytes).
|
||||
maxSize := 524288
|
||||
promRuleSize := len(ar.Request.Object.Raw)
|
||||
if promRuleSize > maxSize {
|
||||
a.logger.Warn("PrometheusRule size exceeded", "err", fmt.Errorf("%s size exceeds 512KB", prometheusRuleResource))
|
||||
return toAdmissionResponseFailure("Size exceeds 512KB", prometheusRuleResource, []error{fmt.Errorf("prometheusRules exceeded by %d bytes, maximum limit is 512KB", promRuleSize-maxSize)})
|
||||
}
|
||||
|
||||
errors := promoperator.ValidateRule(promRule.Spec)
|
||||
if len(errors) != 0 {
|
||||
const m = "Invalid rule"
|
||||
|
|
|
@ -42,6 +42,12 @@ const (
|
|||
ThanosFormat
|
||||
)
|
||||
|
||||
// The maximum `Data` size of a ConfigMap seems to differ between
|
||||
// environments. This is probably due to different meta data sizes which count
|
||||
// into the overall maximum size of a ConfigMap. Thereby lets leave a
|
||||
// large buffer.
|
||||
var MaxConfigMapDataSize = int(float64(v1.MaxSecretSize) * 0.5)
|
||||
|
||||
type PrometheusRuleSelector struct {
|
||||
ruleFormat RuleConfigurationFormat
|
||||
version semver.Version
|
||||
|
@ -160,10 +166,9 @@ func ValidateRule(promRuleSpec monitoringv1.PrometheusRuleSpec) []error {
|
|||
}
|
||||
|
||||
// Check if the size of prometheusRule exceeds 512KB (1048576 Bytes).
|
||||
maxSize := 524288
|
||||
promRuleSize := len(content)
|
||||
if promRuleSize > maxSize {
|
||||
return []error{fmt.Errorf("prometheusRules exceeded by %d bytes, maximum limit is 512KB", promRuleSize-maxSize)}
|
||||
if promRuleSize > MaxConfigMapDataSize {
|
||||
return []error{fmt.Errorf("the length of rendered Prometheus Rule is %d bytes which is above the maximum limit of %d bytes", promRuleSize, MaxConfigMapDataSize)}
|
||||
}
|
||||
|
||||
_, errs := rulefmt.Parse(content)
|
||||
|
|
|
@ -33,12 +33,6 @@ import (
|
|||
prompkg "github.com/prometheus-operator/prometheus-operator/pkg/prometheus"
|
||||
)
|
||||
|
||||
// The maximum `Data` size of a ConfigMap seems to differ between
|
||||
// environments. This is probably due to different meta data sizes which count
|
||||
// into the overall maximum size of a ConfigMap. Thereby lets leave a
|
||||
// large buffer.
|
||||
var maxConfigMapDataSize = int(float64(v1.MaxSecretSize) * 0.5)
|
||||
|
||||
func (c *Operator) createOrUpdateRuleConfigMaps(ctx context.Context, p *monitoringv1.Prometheus) ([]string, error) {
|
||||
cClient := c.kclient.CoreV1().ConfigMaps(p.Namespace)
|
||||
|
||||
|
@ -206,7 +200,7 @@ func (c *Operator) selectRuleNamespaces(p *monitoringv1.Prometheus) ([]string, e
|
|||
func makeRulesConfigMaps(p *monitoringv1.Prometheus, ruleFiles map[string]string, opts ...operator.ObjectOption) ([]v1.ConfigMap, error) {
|
||||
//check if none of the rule files is too large for a single ConfigMap
|
||||
for filename, file := range ruleFiles {
|
||||
if len(file) > maxConfigMapDataSize {
|
||||
if len(file) > operator.MaxConfigMapDataSize {
|
||||
return nil, fmt.Errorf(
|
||||
"rule file '%v' is too large for a single Kubernetes ConfigMap",
|
||||
filename,
|
||||
|
@ -229,7 +223,7 @@ func makeRulesConfigMaps(p *monitoringv1.Prometheus, ruleFiles map[string]string
|
|||
|
||||
for _, filename := range fileNames {
|
||||
// If rule file doesn't fit into current bucket, create new bucket.
|
||||
if bucketSize(buckets[currBucketIndex])+len(ruleFiles[filename]) > maxConfigMapDataSize {
|
||||
if bucketSize(buckets[currBucketIndex])+len(ruleFiles[filename]) > operator.MaxConfigMapDataSize {
|
||||
buckets = append(buckets, map[string]string{})
|
||||
currBucketIndex++
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/operator"
|
||||
)
|
||||
|
||||
func TestMakeRulesConfigMaps(t *testing.T) {
|
||||
|
@ -57,7 +58,7 @@ func shouldErrorOnTooLargeRuleFile(t *testing.T) {
|
|||
func shouldSplitUpLargeSmallIntoTwo(t *testing.T) {
|
||||
ruleFiles := map[string]string{}
|
||||
|
||||
ruleFiles["first"] = strings.Repeat("a", maxConfigMapDataSize)
|
||||
ruleFiles["first"] = strings.Repeat("a", operator.MaxConfigMapDataSize)
|
||||
ruleFiles["second"] = "a"
|
||||
|
||||
configMaps, err := makeRulesConfigMaps(&monitoringv1.Prometheus{ObjectMeta: metav1.ObjectMeta{Name: "test"}}, ruleFiles)
|
||||
|
|
|
@ -34,12 +34,6 @@ import (
|
|||
|
||||
const labelThanosRulerName = "thanos-ruler-name"
|
||||
|
||||
// The maximum `Data` size of a ConfigMap seems to differ between
|
||||
// environments. This is probably due to different meta data sizes which count
|
||||
// into the overall maximum size of a ConfigMap. Thereby lets leave a
|
||||
// large buffer.
|
||||
var maxConfigMapDataSize = int(float64(v1.MaxSecretSize) * 0.5)
|
||||
|
||||
func (o *Operator) createOrUpdateRuleConfigMaps(ctx context.Context, t *monitoringv1.ThanosRuler) ([]string, error) {
|
||||
cClient := o.kclient.CoreV1().ConfigMaps(t.Namespace)
|
||||
|
||||
|
@ -207,7 +201,7 @@ func (o *Operator) selectRuleNamespaces(p *monitoringv1.ThanosRuler) ([]string,
|
|||
func makeRulesConfigMaps(t *monitoringv1.ThanosRuler, ruleFiles map[string]string, opts ...operator.ObjectOption) ([]v1.ConfigMap, error) {
|
||||
//check if none of the rule files is too large for a single ConfigMap
|
||||
for filename, file := range ruleFiles {
|
||||
if len(file) > maxConfigMapDataSize {
|
||||
if len(file) > operator.MaxConfigMapDataSize {
|
||||
return nil, fmt.Errorf(
|
||||
"rule file '%v' is too large for a single Kubernetes ConfigMap",
|
||||
filename,
|
||||
|
@ -230,7 +224,7 @@ func makeRulesConfigMaps(t *monitoringv1.ThanosRuler, ruleFiles map[string]strin
|
|||
|
||||
for _, filename := range fileNames {
|
||||
// If rule file doesn't fit into current bucket, create new bucket.
|
||||
if bucketSize(buckets[currBucketIndex])+len(ruleFiles[filename]) > maxConfigMapDataSize {
|
||||
if bucketSize(buckets[currBucketIndex])+len(ruleFiles[filename]) > operator.MaxConfigMapDataSize {
|
||||
buckets = append(buckets, map[string]string{})
|
||||
currBucketIndex++
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue