Skip to content

Add roundtrip marshal tests and fix JSON/YAML tag compatibility for v0mimir1 configs#504

Open
yuri-tceretian wants to merge 10 commits intomainfrom
yuri-tceretian/v0-roundtrip-marshal
Open

Add roundtrip marshal tests and fix JSON/YAML tag compatibility for v0mimir1 configs#504
yuri-tceretian wants to merge 10 commits intomainfrom
yuri-tceretian/v0-roundtrip-marshal

Conversation

@yuri-tceretian
Copy link
Collaborator

@yuri-tceretian yuri-tceretian commented Feb 27, 2026

Summary

  • Add GetFullConfig test helpers for each v0mimir1 integration to enable roundtrip testing
  • Add roundtrip marshal/unmarshal tests for integration configs (YAML and JSON)
  • Move custom secrets JSON marshaler to receivers/ package, supporting both upstream and local secret types (Secret, SecretURL)
  • Copy SigV4Config struct from upstream into receivers/sns/v0mimir1 to control JSON/YAML tags
  • Fix JSON tag compatibility: Jira custom_fields, Telegram token/chat fallback, SigV4 field tags
  • Flatten Headers type to remove custom JSON marshaler that interfered with secret unmasking
  • Move HTTP client test data to a separate v0mimir1test package
  • Add HTTPClientConfig roundtrip tests documenting known JSON round-trip limitations

Test plan

  • Per-integration config roundtrip tests (YAML and JSON marshal → unmarshal)
  • Secret type marshaling tests (masking in standard JSON, plain text in PlainSecretsJSON)
  • Receiver conversion roundtrip: definition.Receiver → upstream config.Receiverdefinition.Receiver
  • HTTPClientConfig roundtrip tests documenting edge cases
  • CI: make test and make lint pass

🤖 Generated with Claude Code

@yuri-tceretian yuri-tceretian requested a review from a team as a code owner February 27, 2026 20:12
@github-project-automation github-project-automation bot moved this to In review in Alerting Feb 27, 2026
@yuri-tceretian yuri-tceretian changed the title Copy upstream receiver configs and notifiers into v0mimir1 with roundtrip tests Add roundtrip marshal tests and fix JSON/YAML tag compatibility for v0mimir1 configs Feb 27, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Telegram withFallback missing token_file YAML fallback
    • Added token_file fallback handling in Telegram UnmarshalYAML and covered it with a test that unmarshals JSON-style token_file via YAML.

Create PR

Or push these changes by commenting:

@cursor push 9a19b6cb31
Preview (9a19b6cb31)
diff --git a/receivers/telegram/v0mimir1/config.go b/receivers/telegram/v0mimir1/config.go
--- a/receivers/telegram/v0mimir1/config.go
+++ b/receivers/telegram/v0mimir1/config.go
@@ -54,9 +54,10 @@
 func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
 	type plain Config
 	type withFallback struct {
-		plain        `yaml:",inline" json:",inline"`
-		BotTokenJson receivers.Secret `yaml:"token"`
-		ChatIDJson   int64            `yaml:"chat"`
+		plain            `yaml:",inline" json:",inline"`
+		BotTokenJson     receivers.Secret `yaml:"token"`
+		BotTokenFileJson string           `yaml:"token_file"`
+		ChatIDJson       int64            `yaml:"chat"`
 	}
 	pl := withFallback{plain: plain(DefaultConfig)}
 	if err := unmarshal(&pl); err != nil {
@@ -66,6 +67,9 @@
 	if c.BotToken == "" && pl.BotTokenJson != "" {
 		c.BotToken = pl.BotTokenJson
 	}
+	if c.BotTokenFile == "" && pl.BotTokenFileJson != "" {
+		c.BotTokenFile = pl.BotTokenFileJson
+	}
 	if c.ChatID == 0 && pl.ChatIDJson != 0 {
 		c.ChatID = pl.ChatIDJson
 	}

diff --git a/receivers/telegram/v0mimir1/config_test.go b/receivers/telegram/v0mimir1/config_test.go
--- a/receivers/telegram/v0mimir1/config_test.go
+++ b/receivers/telegram/v0mimir1/config_test.go
@@ -82,6 +82,13 @@
 parse_mode: Markdown
 `,
 		},
+		{
+			name: "json token_file tag is supported",
+			in: `
+token_file: /file
+chat: 123
+`,
+		},
 	}
 
 	for _, tt := range tc {

type withFallback struct {
plain `yaml:",inline" json:",inline"`
BotTokenJson receivers.Secret `yaml:"token"`
ChatIDJson int64 `yaml:"chat"`
Copy link

Choose a reason for hiding this comment

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

Telegram withFallback missing token_file YAML fallback

Medium Severity

The withFallback struct in UnmarshalYAML adds YAML tag fallbacks for "token" (JSON tag of BotToken) and "chat" (JSON tag of ChatID), but omits a fallback for "token_file" (the JSON tag of BotTokenFile, whose YAML tag is "bot_token_file"). When JSON data containing "token_file" is unmarshaled via a YAML parser, this key won't match any YAML tag and the value is silently lost, resulting in a "missing bot_token or bot_token_file" validation error. The Jira withFallback consistently covers all mismatched json/yaml tags for that config, but Telegram does not.

Fix in Cursor Fix in Web

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

file fields are not supported in Grafana\Mimir. We can ignore them

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

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

1 participant