Add roundtrip marshal tests and fix JSON/YAML tag compatibility for v0mimir1 configs#504
Add roundtrip marshal tests and fix JSON/YAML tag compatibility for v0mimir1 configs#504yuri-tceretian wants to merge 10 commits intomainfrom
Conversation
…with custom marshaling where secrets are unmasked
There was a problem hiding this comment.
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
withFallbackmissingtoken_fileYAML fallback- Added
token_filefallback handling in TelegramUnmarshalYAMLand covered it with a test that unmarshals JSON-styletoken_filevia YAML.
- Added
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"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
file fields are not supported in Grafana\Mimir. We can ignore them



Summary
GetFullConfigtest helpers for each v0mimir1 integration to enable roundtrip testingreceivers/package, supporting both upstream and local secret types (Secret,SecretURL)SigV4Configstruct from upstream intoreceivers/sns/v0mimir1to control JSON/YAML tagscustom_fields, Telegramtoken/chatfallback, SigV4 field tagsHeaderstype to remove custom JSON marshaler that interfered with secret unmaskingv0mimir1testpackageHTTPClientConfigroundtrip tests documenting known JSON round-trip limitationsTest plan
PlainSecretsJSON)definition.Receiver→ upstreamconfig.Receiver→definition.ReceiverHTTPClientConfigroundtrip tests documenting edge casesmake testandmake lintpass🤖 Generated with Claude Code