-
Notifications
You must be signed in to change notification settings - Fork 2.5k
refactor(email): move configuration types into email package #5576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SoloJacobs
merged 1 commit into
prometheus:main
from
TheMeier:chmaser-notifier-config-refactor-fe141404
Sep 21, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package common | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "net" | ||
| ) | ||
|
|
||
| // HostPort represents a "host:port" network address. | ||
| type HostPort struct { | ||
| Host string | ||
| Port string | ||
| } | ||
|
|
||
| // UnmarshalYAML implements the yaml.Unmarshaler interface for HostPort. | ||
| func (hp *HostPort) UnmarshalYAML(unmarshal func(any) error) error { | ||
| var ( | ||
| s string | ||
| err error | ||
| ) | ||
| if err = unmarshal(&s); err != nil { | ||
| return err | ||
| } | ||
| if s == "" { | ||
| return nil | ||
| } | ||
| hp.Host, hp.Port, err = net.SplitHostPort(s) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if hp.Port == "" { | ||
| return fmt.Errorf("address %q: port cannot be empty", s) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // UnmarshalJSON implements the json.Unmarshaler interface for HostPort. | ||
| func (hp *HostPort) UnmarshalJSON(data []byte) error { | ||
| var ( | ||
| s string | ||
| err error | ||
| ) | ||
| if err = json.Unmarshal(data, &s); err != nil { | ||
| return err | ||
| } | ||
| if s == "" { | ||
| return nil | ||
| } | ||
| hp.Host, hp.Port, err = net.SplitHostPort(s) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if hp.Port == "" { | ||
| return fmt.Errorf("address %q: port cannot be empty", s) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // MarshalYAML implements the yaml.Marshaler interface for HostPort. | ||
| func (hp HostPort) MarshalYAML() (any, error) { | ||
| return hp.String(), nil | ||
| } | ||
|
|
||
| // MarshalJSON implements the json.Marshaler interface for HostPort. | ||
| func (hp HostPort) MarshalJSON() ([]byte, error) { | ||
| return json.Marshal(hp.String()) | ||
| } | ||
|
|
||
| func (hp HostPort) String() string { | ||
| if hp.Host == "" && hp.Port == "" { | ||
| return "" | ||
| } | ||
| return net.JoinHostPort(hp.Host, hp.Port) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package common | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "gopkg.in/yaml.v2" | ||
| ) | ||
|
|
||
| func TestUnmarshalHostPort(t *testing.T) { | ||
| for _, tc := range []struct { | ||
| in string | ||
|
|
||
| exp HostPort | ||
| jsonOut string | ||
| yamlOut string | ||
| err bool | ||
| }{ | ||
| { | ||
| in: `""`, | ||
| exp: HostPort{}, | ||
| yamlOut: `"" | ||
| `, | ||
| jsonOut: `""`, | ||
| }, | ||
| { | ||
| in: `"localhost:25"`, | ||
| exp: HostPort{Host: "localhost", Port: "25"}, | ||
| yamlOut: `localhost:25 | ||
| `, | ||
| jsonOut: `"localhost:25"`, | ||
| }, | ||
| { | ||
| in: `":25"`, | ||
| exp: HostPort{Host: "", Port: "25"}, | ||
| yamlOut: `:25 | ||
| `, | ||
| jsonOut: `":25"`, | ||
| }, | ||
| { | ||
| in: `"localhost"`, | ||
| err: true, | ||
| }, | ||
| { | ||
| in: `"localhost:"`, | ||
| err: true, | ||
| }, | ||
| { | ||
| in: `"[fd12:3456:789a::1]:25"`, | ||
| exp: HostPort{Host: "fd12:3456:789a::1", Port: "25"}, | ||
| yamlOut: `'[fd12:3456:789a::1]:25' | ||
| `, | ||
| jsonOut: `"[fd12:3456:789a::1]:25"`, | ||
| }, | ||
| } { | ||
| t.Run(tc.in, func(t *testing.T) { | ||
| hp := HostPort{} | ||
| err := yaml.Unmarshal([]byte(tc.in), &hp) | ||
| if tc.err { | ||
| require.Error(t, err) | ||
| return | ||
| } | ||
| require.NoError(t, err) | ||
| require.Equal(t, tc.exp, hp) | ||
|
|
||
| b, err := yaml.Marshal(&hp) | ||
| require.NoError(t, err) | ||
| require.Equal(t, tc.yamlOut, string(b)) | ||
|
|
||
| b, err = json.Marshal(&hp) | ||
| require.NoError(t, err) | ||
| require.Equal(t, tc.jsonOut, string(b)) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve aliases for the relocated exported types.
Removing
config.HostPortandconfig.EmailConfigbreaks downstream Go code that constructs these types or assigns[]*config.EmailConfigtoReceiver.EmailConfigs. Retaintype HostPort = amcommoncfg.HostPortandtype EmailConfig = email.EmailConfiginconfig. Otherwise, document this breaking migration and include it in release notes.Also applies to: 928-928
🤖 Prompt for AI Agents
Source: Learnings