Skip to content

vmalert: compress each vmrule independently - #2617

Open
AndrewChubatiuk wants to merge 1 commit into
masterfrom
fix-config-items-destribution
Open

AndrewChubatiuk wants to merge 1 commit into
masterfrom
fix-config-items-destribution

Conversation

@AndrewChubatiuk

@AndrewChubatiuk AndrewChubatiuk commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

fixes #2610

store compressed vmrule content in bucket as . key, which prevents from groups recreation in vmalert

@AndrewChubatiuk
AndrewChubatiuk marked this pull request as draft September 14, 2026 07:16

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

Fix all with cubic | Re-trigger cubic

Comment thread internal/controller/operator/factory/vmalert/rules.go Outdated
Comment thread internal/controller/operator/factory/vmagent/vmagent.go Outdated
Comment thread internal/controller/operator/factory/vmalert/rules.go Outdated
Comment thread internal/controller/operator/factory/vmalert/rules_test.go Outdated
@AndrewChubatiuk
AndrewChubatiuk force-pushed the fix-config-items-destribution branch 3 times, most recently from 7f8d004 to d7a2cad Compare September 18, 2026 07:47
@AndrewChubatiuk AndrewChubatiuk changed the title vmalert/vmsingle/vmagent: distribute child objects across configmaps consistently vmalert: compress each vmrule independently Sep 18, 2026
@AndrewChubatiuk
AndrewChubatiuk force-pushed the fix-config-items-destribution branch from d7a2cad to b57acc5 Compare September 18, 2026 07:57
@AndrewChubatiuk

Copy link
Copy Markdown
Contributor Author

@cubic-ai-dev

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@cubic-ai-dev

@AndrewChubatiuk I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread internal/controller/operator/factory/vmsingle/vmsingle.go Outdated
Comment thread internal/controller/operator/factory/vmalert/vmalert.go Outdated
Comment thread docs/CHANGELOG.md Outdated
Comment thread internal/config/config.go
Comment thread internal/controller/operator/factory/vmalert/rules.go
@AndrewChubatiuk
AndrewChubatiuk force-pushed the fix-config-items-destribution branch 2 times, most recently from 9d2ca42 to 3b70ce1 Compare September 18, 2026 10:24
@AndrewChubatiuk

Copy link
Copy Markdown
Contributor Author

@cubic-ai-dev

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@cubic-ai-dev

@AndrewChubatiuk I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 11 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread internal/controller/operator/factory/vmagent/vmagent.go Outdated
@AndrewChubatiuk
AndrewChubatiuk force-pushed the fix-config-items-destribution branch from 3b70ce1 to f4bc834 Compare September 18, 2026 11:10
@AndrewChubatiuk

Copy link
Copy Markdown
Contributor Author

@cubic-ai-dev

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@cubic-ai-dev

@AndrewChubatiuk I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 11 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread internal/controller/operator/factory/vmagent/vmagent.go Outdated
Comment thread internal/controller/operator/factory/vmagent/vmagent.go Outdated
@AndrewChubatiuk
AndrewChubatiuk force-pushed the fix-config-items-destribution branch from f4bc834 to 65720f9 Compare September 18, 2026 12:01
@AndrewChubatiuk
AndrewChubatiuk marked this pull request as ready for review September 18, 2026 13:41

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 11 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/controller/operator/factory/vmagent/vmagent.go">

<violation number="1" location="internal/controller/operator/factory/vmagent/vmagent.go:1419">
P2: When a VMAgent has no scrape jobs, this call skips the marshal-size check entirely, so a large `cfgBase` can produce a main Secret larger than `ConfigDataBudgetBytes` without an error. Measure the base-only configuration on the empty-job path before reconciling the Secret.</violation>
</file>

<file name="internal/controller/operator/factory/vmagent/vmagent_test.go">

<violation number="1" location="internal/controller/operator/factory/vmagent/vmagent_test.go:3480">
P2: When the main Secret is missing, this non-fatal assertion leaves `secret` empty and the following size check passes with length zero. Return after a failed `Get` (or use a fatal assertion) before validating the compressed data.</violation>

<violation number="2" location="internal/controller/operator/factory/vmagent/vmagent_test.go:3488">
P2: TestCreateOrUpdateScrapeConfig_CompressibleBaseConfigDoesNotHardFail never exercises the budget/measurement path: with no scrape objects, jobs is empty, and PackItemsFunc short-circuits (`len(items) == 0`) before calling the measuring closure, so the assertion passes trivially and cannot catch a regression in compressible-base handling. Add at least one VMServiceScrape so the packing/measurement logic actually runs.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

// Split jobs into gzip-compressed buckets, each fitting within the Kubernetes Secret limit.
buckets, err := build.PackItems(jobs, cfg.ConfigDataBudgetBytes, 150)
// measures the real stored bytes (cfgBase+glob+wrapper), glob assumed present as a safe overestimate
mainBuckets, err := build.PackItemsFunc(jobs, cfg.ConfigDataBudgetBytes, func(candidate []yaml.MapSlice) ([]byte, error) {

@cubic-dev-ai cubic-dev-ai Bot Sep 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When a VMAgent has no scrape jobs, this call skips the marshal-size check entirely, so a large cfgBase can produce a main Secret larger than ConfigDataBudgetBytes without an error. Measure the base-only configuration on the empty-job path before reconciling the Secret.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/controller/operator/factory/vmagent/vmagent.go, line 1419:

<comment>When a VMAgent has no scrape jobs, this call skips the marshal-size check entirely, so a large `cfgBase` can produce a main Secret larger than `ConfigDataBudgetBytes` without an error. Measure the base-only configuration on the empty-job path before reconciling the Secret.</comment>

<file context>
@@ -1415,12 +1415,28 @@ func createOrUpdateScrapeConfig(ctx context.Context, rclient client.Client, cr,
-	// Split jobs into gzip-compressed buckets, each fitting within the Kubernetes Secret limit.
-	buckets, err := build.PackItems(jobs, cfg.ConfigDataBudgetBytes, 150)
+	// measures the real stored bytes (cfgBase+glob+wrapper), glob assumed present as a safe overestimate
+	mainBuckets, err := build.PackItemsFunc(jobs, cfg.ConfigDataBudgetBytes, func(candidate []yaml.MapSlice) ([]byte, error) {
+		mainCfg := append(append(yaml.MapSlice{}, cfgBase...), yaml.MapItem{
+			Key:   "scrape_config_files",
</file context>
Fix with cubic

Comment on lines +3480 to +3483
assert.NoError(t, fclient.Get(ctx, types.NamespacedName{
Name: build.ResourceName(build.SecretConfigResourceKind, cr),
Namespace: cr.Namespace,
}, &secret))

@cubic-dev-ai cubic-dev-ai Bot Sep 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When the main Secret is missing, this non-fatal assertion leaves secret empty and the following size check passes with length zero. Return after a failed Get (or use a fatal assertion) before validating the compressed data.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/controller/operator/factory/vmagent/vmagent_test.go, line 3480:

<comment>When the main Secret is missing, this non-fatal assertion leaves `secret` empty and the following size check passes with length zero. Return after a failed `Get` (or use a fatal assertion) before validating the compressed data.</comment>

<file context>
@@ -3421,3 +3423,93 @@ func TestMakeSpecForAgentOk_WatchTargetDirPairing(t *testing.T) {
+	}
+
+	var secret corev1.Secret
+	assert.NoError(t, fclient.Get(ctx, types.NamespacedName{
+		Name:      build.ResourceName(build.SecretConfigResourceKind, cr),
+		Namespace: cr.Namespace,
</file context>
Suggested change
assert.NoError(t, fclient.Get(ctx, types.NamespacedName{
Name: build.ResourceName(build.SecretConfigResourceKind, cr),
Namespace: cr.Namespace,
}, &secret))
if !assert.NoError(t, fclient.Get(ctx, types.NamespacedName{
Name: build.ResourceName(build.SecretConfigResourceKind, cr),
Namespace: cr.Namespace,
}, &secret)) {
return
}
Fix with cubic

"main config secret must not exceed ConfigDataBudgetBytes once cfgBase is included")
}

func TestCreateOrUpdateScrapeConfig_CompressibleBaseConfigDoesNotHardFail(t *testing.T) {

@cubic-dev-ai cubic-dev-ai Bot Sep 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: TestCreateOrUpdateScrapeConfig_CompressibleBaseConfigDoesNotHardFail never exercises the budget/measurement path: with no scrape objects, jobs is empty, and PackItemsFunc short-circuits (len(items) == 0) before calling the measuring closure, so the assertion passes trivially and cannot catch a regression in compressible-base handling. Add at least one VMServiceScrape so the packing/measurement logic actually runs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/controller/operator/factory/vmagent/vmagent_test.go, line 3488:

<comment>TestCreateOrUpdateScrapeConfig_CompressibleBaseConfigDoesNotHardFail never exercises the budget/measurement path: with no scrape objects, jobs is empty, and PackItemsFunc short-circuits (`len(items) == 0`) before calling the measuring closure, so the assertion passes trivially and cannot catch a regression in compressible-base handling. Add at least one VMServiceScrape so the packing/measurement logic actually runs.</comment>

<file context>
@@ -3421,3 +3423,93 @@ func TestMakeSpecForAgentOk_WatchTargetDirPairing(t *testing.T) {
+		"main config secret must not exceed ConfigDataBudgetBytes once cfgBase is included")
+}
+
+func TestCreateOrUpdateScrapeConfig_CompressibleBaseConfigDoesNotHardFail(t *testing.T) {
+	ctx := context.Background()
+	cr := &vmv1beta1.VMAgent{
</file context>
Fix with cubic

@AndrewChubatiuk
AndrewChubatiuk force-pushed the fix-config-items-destribution branch from 65720f9 to e3fb427 Compare September 18, 2026 14:07
@AndrewChubatiuk
AndrewChubatiuk force-pushed the fix-config-items-destribution branch from e3fb427 to bddb5bf Compare September 18, 2026 14:25
@Haleygo Haleygo self-assigned this Sep 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vmalert: vmrule changes could trigger unrelated group restarts during reload in large environments

2 participants