diff --git a/.golangci.yml b/.golangci.yml index d98ec746..b6463d06 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,7 @@ linters: enable: - depguard - errorlint + - godot - gofumpt - goimports - misspell @@ -51,6 +52,13 @@ linters-settings: - (github.com/go-kit/log.Logger).Log # Never check for rollback errors as Rollback() is called when a previous error was detected. - (github.com/prometheus/prometheus/storage.Appender).Rollback + godot: + scope: toplevel + exclude: + - "^ ?This file is safe to edit" + - "^ ?scheme value" + period: true + capital: true goimports: local-prefixes: github.com/prometheus/alertmanager gofumpt: diff --git a/api/v1_deprecation_router.go b/api/v1_deprecation_router.go index 3ebbbd07..46a61ebf 100644 --- a/api/v1_deprecation_router.go +++ b/api/v1_deprecation_router.go @@ -8,7 +8,6 @@ // 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 l package api diff --git a/api/v2/api.go b/api/v2/api.go index b4f57e75..6f034d25 100644 --- a/api/v2/api.go +++ b/api/v2/api.go @@ -53,7 +53,7 @@ import ( "github.com/prometheus/alertmanager/types" ) -// API represents an Alertmanager API v2 +// API represents an Alertmanager API v2. type API struct { peer cluster.ClusterPeer silences *silence.Silences @@ -82,7 +82,7 @@ type ( setAlertStatusFn func(prometheus_model.LabelSet) ) -// NewAPI returns a new Alertmanager API v2 +// NewAPI returns a new Alertmanager API v2. func NewAPI( alerts provider.Alerts, gf groupsFn, @@ -545,9 +545,9 @@ var silenceStateOrder = map[types.SilenceState]int{ // SortSilences sorts first according to the state "active, pending, expired" // then by end time or start time depending on the state. -// active silences should show the next to expire first +// Active silences should show the next to expire first // pending silences are ordered based on which one starts next -// expired are ordered based on which one expired most recently +// expired are ordered based on which one expired most recently. func SortSilences(sils open_api_models.GettableSilences) { sort.Slice(sils, func(i, j int) bool { state1 := types.SilenceState(*sils[i].Status.State) diff --git a/cli/check_config.go b/cli/check_config.go index 77214c87..c024c275 100644 --- a/cli/check_config.go +++ b/cli/check_config.go @@ -23,7 +23,7 @@ import ( "github.com/prometheus/alertmanager/template" ) -// TODO: This can just be a type that is []string, doesn't have to be a struct +// TODO: This can just be a type that is []string, doesn't have to be a struct. type checkConfigCmd struct { files []string } diff --git a/cli/cluster.go b/cli/cluster.go index 9c72373c..eefc729a 100644 --- a/cli/cluster.go +++ b/cli/cluster.go @@ -24,7 +24,7 @@ import ( const clusterHelp = `View cluster status and peers.` -// clusterCmd represents the cluster command +// configureClusterCmd represents the cluster command. func configureClusterCmd(app *kingpin.Application) { clusterCmd := app.Command("cluster", clusterHelp) clusterCmd.Command("show", clusterHelp).Default().Action(execWithTimeout(showStatus)).PreAction(requireAlertManagerURL) diff --git a/cli/config.go b/cli/config.go index 2f01e2c3..4fd93689 100644 --- a/cli/config.go +++ b/cli/config.go @@ -30,7 +30,7 @@ The amount of output is controlled by the output selection flag: - Json: Print entire config object as json ` -// configCmd represents the config command +// configureConfigCmd represents the config command. func configureConfigCmd(app *kingpin.Application) { configCmd := app.Command("config", configHelp) configCmd.Command("show", configHelp).Default().Action(execWithTimeout(queryConfig)).PreAction(requireAlertManagerURL) diff --git a/cli/config/http_config.go b/cli/config/http_config.go index 71b656b1..3704e7e6 100644 --- a/cli/config/http_config.go +++ b/cli/config/http_config.go @@ -21,7 +21,7 @@ import ( "gopkg.in/yaml.v2" ) -// LoadHTTPConfigFile returns HTTPClientConfig for the given http_config file +// LoadHTTPConfigFile returns HTTPClientConfig for the given http_config file. func LoadHTTPConfigFile(filename string) (*promconfig.HTTPClientConfig, error) { b, err := os.ReadFile(filename) if err != nil { diff --git a/cli/format/format_extended.go b/cli/format/format_extended.go index 919ef9c2..3870cc7d 100644 --- a/cli/format/format_extended.go +++ b/cli/format/format_extended.go @@ -37,7 +37,7 @@ func (formatter *ExtendedFormatter) SetOutput(writer io.Writer) { formatter.writer = writer } -// FormatSilences formats the silences into a readable string +// FormatSilences formats the silences into a readable string. func (formatter *ExtendedFormatter) FormatSilences(silences []models.GettableSilence) error { w := tabwriter.NewWriter(formatter.writer, 0, 0, 2, ' ', 0) sort.Sort(ByEndAt(silences)) @@ -58,7 +58,7 @@ func (formatter *ExtendedFormatter) FormatSilences(silences []models.GettableSil return w.Flush() } -// FormatAlerts formats the alerts into a readable string +// FormatAlerts formats the alerts into a readable string. func (formatter *ExtendedFormatter) FormatAlerts(alerts []*models.GettableAlert) error { w := tabwriter.NewWriter(formatter.writer, 0, 0, 2, ' ', 0) sort.Sort(ByStartsAt(alerts)) @@ -78,7 +78,7 @@ func (formatter *ExtendedFormatter) FormatAlerts(alerts []*models.GettableAlert) return w.Flush() } -// FormatConfig formats the alertmanager status information into a readable string +// FormatConfig formats the alertmanager status information into a readable string. func (formatter *ExtendedFormatter) FormatConfig(status *models.AlertmanagerStatus) error { fmt.Fprintln(formatter.writer, status.Config.Original) fmt.Fprintln(formatter.writer, "buildUser", status.VersionInfo.BuildUser) diff --git a/cli/root.go b/cli/root.go index 69c1022c..fe02fb82 100644 --- a/cli/root.go +++ b/cli/root.go @@ -89,7 +89,7 @@ const ( defaultAmApiv2path = "/api/v2" ) -// NewAlertmanagerClient initializes an alertmanager client with the given URL +// NewAlertmanagerClient initializes an alertmanager client with the given URL. func NewAlertmanagerClient(amURL *url.URL) *client.AlertmanagerAPI { address := defaultAmHost + ":" + defaultAmPort schemes := []string{"http"} @@ -145,7 +145,7 @@ func NewAlertmanagerClient(amURL *url.URL) *client.AlertmanagerAPI { return c } -// Execute is the main function for the amtool command +// Execute is the main function for the amtool command. func Execute() { app := kingpin.New("amtool", helpRoot).UsageWriter(os.Stdout) diff --git a/cli/silence.go b/cli/silence.go index a3373a86..d7ed2ce4 100644 --- a/cli/silence.go +++ b/cli/silence.go @@ -17,7 +17,7 @@ import ( "github.com/alecthomas/kingpin/v2" ) -// silenceCmd represents the silence command +// configureSilenceCmd represents the silence command. func configureSilenceCmd(app *kingpin.Application) { silenceCmd := app.Command("silence", "Add, expire or view silences. For more information and additional flags see query help").PreAction(requireAlertManagerURL) configureSilenceAddCmd(silenceCmd) diff --git a/cli/utils.go b/cli/utils.go index dfe39dd8..7215220a 100644 --- a/cli/utils.go +++ b/cli/utils.go @@ -29,7 +29,7 @@ import ( "github.com/prometheus/alertmanager/pkg/labels" ) -// getRemoteAlertmanagerConfigStatus returns status responsecontaining configuration from remote Alertmanager +// getRemoteAlertmanagerConfigStatus returns status responsecontaining configuration from remote Alertmanager. func getRemoteAlertmanagerConfigStatus(ctx context.Context, alertmanagerURL *url.URL) (*models.AlertmanagerStatus, error) { amclient := NewAlertmanagerClient(alertmanagerURL) params := general.NewGetStatusParams().WithContext(ctx) @@ -69,7 +69,7 @@ func loadAlertmanagerConfig(ctx context.Context, alertmanagerURL *url.URL, confi return config.Load(*configStatus.Config.Original) } -// convertClientToCommonLabelSet converts client.LabelSet to model.Labelset +// convertClientToCommonLabelSet converts client.LabelSet to model.Labelset. func convertClientToCommonLabelSet(cls models.LabelSet) model.LabelSet { mls := make(model.LabelSet, len(cls)) for ln, lv := range cls { @@ -78,7 +78,7 @@ func convertClientToCommonLabelSet(cls models.LabelSet) model.LabelSet { return mls } -// TypeMatchers only valid for when you are going to add a silence +// TypeMatchers only valid for when you are going to add a silence. func TypeMatchers(matchers []labels.Matcher) models.Matchers { typeMatchers := make(models.Matchers, len(matchers)) for i, matcher := range matchers { @@ -87,7 +87,7 @@ func TypeMatchers(matchers []labels.Matcher) models.Matchers { return typeMatchers } -// TypeMatcher only valid for when you are going to add a silence +// TypeMatcher only valid for when you are going to add a silence. func TypeMatcher(matcher labels.Matcher) *models.Matcher { name := matcher.Name value := matcher.Value diff --git a/cluster/cluster.go b/cluster/cluster.go index d85ee7f5..6e8bdaac 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -42,7 +42,7 @@ type ClusterPeer interface { Peers() []ClusterMember } -// ClusterMember interface that represents node peers in a cluster +// ClusterMember interface that represents node peers in a cluster. type ClusterMember interface { // Name returns the name of the node Name() string @@ -639,10 +639,10 @@ type Member struct { node *memberlist.Node } -// Name implements cluster.ClusterMember +// Name implements cluster.ClusterMember. func (m Member) Name() string { return m.node.Name } -// Address implements cluster.ClusterMember +// Address implements cluster.ClusterMember. func (m Member) Address() string { return m.node.Address() } // Peers returns the peers in the cluster. diff --git a/config/config.go b/config/config.go index 35cd06dd..b1760ea6 100644 --- a/config/config.go +++ b/config/config.go @@ -972,7 +972,7 @@ func (re Regexp) MarshalYAML() (interface{}, error) { return nil, nil } -// UnmarshalJSON implements the json.Unmarshaler interface for Regexp +// UnmarshalJSON implements the json.Unmarshaler interface for Regexp. func (re *Regexp) UnmarshalJSON(data []byte) error { var s string if err := json.Unmarshal(data, &s); err != nil { diff --git a/config/notifiers.go b/config/notifiers.go index d79c8b50..7d52aed1 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -312,13 +312,13 @@ type PagerdutyConfig struct { Group string `yaml:"group,omitempty" json:"group,omitempty"` } -// PagerdutyLink is a link +// PagerdutyLink is a link. type PagerdutyLink struct { Href string `yaml:"href,omitempty" json:"href,omitempty"` Text string `yaml:"text,omitempty" json:"text,omitempty"` } -// PagerdutyImage is an image +// PagerdutyImage is an image. type PagerdutyImage struct { Src string `yaml:"src,omitempty" json:"src,omitempty"` Alt string `yaml:"alt,omitempty" json:"alt,omitempty"` diff --git a/matchers/parse/lexer.go b/matchers/parse/lexer.go index d6daa6a9..52bb0392 100644 --- a/matchers/parse/lexer.go +++ b/matchers/parse/lexer.go @@ -251,7 +251,7 @@ func (l *lexer) accept(valid string) bool { } // expect consumes the next rune if its one of the valid runes. -// it returns nil if the next rune is valid, otherwise an expectedError +// It returns nil if the next rune is valid, otherwise an expectedError // error. func (l *lexer) expect(valid string) error { if strings.ContainsRune(valid, l.next()) { diff --git a/matchers/parse/parse.go b/matchers/parse/parse.go index 30a95b25..34e36203 100644 --- a/matchers/parse/parse.go +++ b/matchers/parse/parse.go @@ -196,7 +196,7 @@ func (p *parser) parseEndOfMatcher(l *lexer) (parseFunc, error) { if err != nil { if errors.Is(err, errEOF) { // If this is the end of input we still need to check if the optional - // open brace has a matching close brace + // open brace has a matching close brace. return p.parseCloseBrace, nil } return nil, fmt.Errorf("%w: %w", err, errExpectedCommaOrCloseBrace) @@ -220,7 +220,7 @@ func (p *parser) parseComma(l *lexer) (parseFunc, error) { if err != nil { if errors.Is(err, errEOF) { // If this is the end of input we still need to check if the optional - // open brace has a matching close brace + // open brace has a matching close brace. return p.parseCloseBrace, nil } return nil, fmt.Errorf("%w: %w", err, errExpectedMatcherOrCloseBrace) @@ -242,6 +242,7 @@ func (p *parser) parseEOF(l *lexer) (parseFunc, error) { return nil, nil } +// nolint:godot // accept returns true if the next token is one of the specified kinds, // otherwise false. If the token is accepted it is consumed. tokenEOF is // not an accepted kind and instead accept returns ErrEOF if there is no @@ -256,6 +257,7 @@ func (p *parser) accept(l *lexer, kinds ...tokenKind) (ok bool, err error) { return ok, err } +// nolint:godot // acceptPeek returns true if the next token is one of the specified kinds, // otherwise false. However, unlike accept, acceptPeek does not consume accepted // tokens. tokenEOF is not an accepted kind and instead accept returns ErrEOF @@ -271,6 +273,7 @@ func (p *parser) acceptPeek(l *lexer, kinds ...tokenKind) (bool, error) { return t.isOneOf(kinds...), nil } +// nolint:godot // expect returns the next token if it is one of the specified kinds, otherwise // it returns an error. If the token is expected it is consumed. tokenEOF is not // an accepted kind and instead expect returns ErrEOF if there is no more input. @@ -285,6 +288,7 @@ func (p *parser) expect(l *lexer, kind ...tokenKind) (token, error) { return t, nil } +// nolint:godot // expect returns the next token if it is one of the specified kinds, otherwise // it returns an error. However, unlike expect, expectPeek does not consume tokens. // tokenEOF is not an accepted kind and instead expect returns ErrEOF if there is no diff --git a/nflog/nflog.go b/nflog/nflog.go index 6ce12a8e..3084bf00 100644 --- a/nflog/nflog.go +++ b/nflog/nflog.go @@ -46,7 +46,7 @@ var ErrInvalidState = errors.New("invalid state") // query currently allows filtering by and/or receiver group key. // It is configured via QueryParameter functions. // -// TODO(fabxc): Future versions could allow querying a certain receiver +// TODO(fabxc): Future versions could allow querying a certain receiver, // group or a given time interval. type query struct { recv *pb.Receiver diff --git a/notify/email/email.go b/notify/email/email.go index d7e5be7b..98c98c17 100644 --- a/notify/email/email.go +++ b/notify/email/email.go @@ -347,7 +347,7 @@ func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) { return "LOGIN", []byte{}, nil } -// Used for AUTH LOGIN. (Maybe password should be encrypted) +// Used for AUTH LOGIN. (Maybe password should be encrypted). func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) { if more { switch strings.ToLower(string(fromServer)) { diff --git a/notify/notify.go b/notify/notify.go index 3752148f..bd4b4fae 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -469,7 +469,7 @@ func (ms MultiStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Al return ctx, alerts, nil } -// FanoutStage executes its stages concurrently +// FanoutStage executes its stages concurrently. type FanoutStage []Stage // Exec attempts to execute all stages concurrently and discards the results. @@ -616,7 +616,7 @@ func utcNow() time.Time { return time.Now().UTC() } -// Wrap a slice in a struct so we can store a pointer in sync.Pool +// Wrap a slice in a struct so we can store a pointer in sync.Pool. type hashBuffer struct { buf []byte } diff --git a/notify/util.go b/notify/util.go index bd54e2b4..0c440e65 100644 --- a/notify/util.go +++ b/notify/util.go @@ -34,7 +34,7 @@ import ( // truncationMarker is the character used to represent a truncation. const truncationMarker = "…" -// UserAgentHeader is the default User-Agent for notification requests +// UserAgentHeader is the default User-Agent for notification requests. var UserAgentHeader = fmt.Sprintf("Alertmanager/%s", version.Version) // RedactURL removes the URL part from an error of *url.Error type. @@ -47,7 +47,7 @@ func RedactURL(err error) error { return e } -// Get sends a GET request to the given URL +// Get sends a GET request to the given URL. func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) { return request(ctx, client, http.MethodGet, url, "", nil) } diff --git a/notify/webex/webex.go b/notify/webex/webex.go index 9e95e3ed..347dd63a 100644 --- a/notify/webex/webex.go +++ b/notify/webex/webex.go @@ -30,6 +30,7 @@ import ( ) const ( + // nolint:godot // maxMessageSize represents the maximum message length that Webex supports. maxMessageSize = 7439 ) diff --git a/pkg/labels/parse.go b/pkg/labels/parse.go index 5138716e..f84b29e8 100644 --- a/pkg/labels/parse.go +++ b/pkg/labels/parse.go @@ -136,7 +136,7 @@ func ParseMatcher(s string) (_ *Matcher, err error) { return nil, fmt.Errorf("matcher value not valid UTF-8: %s", ms[3]) } - // Unescape the rawValue: + // Unescape the rawValue. for i, r := range rawValue { if escaped { escaped = false diff --git a/provider/provider.go b/provider/provider.go index 5fcce203..4d1f76f2 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -47,7 +47,7 @@ type AlertIterator interface { Next() <-chan *types.Alert } -// NewAlertIterator returns a new AlertIterator based on the generic alertIterator type +// NewAlertIterator returns a new AlertIterator based on the generic alertIterator type. func NewAlertIterator(ch <-chan *types.Alert, done chan struct{}, err error) AlertIterator { return &alertIterator{ ch: ch, diff --git a/test/cli/acceptance.go b/test/cli/acceptance.go index d799c2e2..a2d00885 100644 --- a/test/cli/acceptance.go +++ b/test/cli/acceptance.go @@ -41,6 +41,7 @@ import ( ) const ( + // nolint:godot // amtool is the relative path to local amtool binary. amtool = "../../../amtool" ) diff --git a/test/cli/collector.go b/test/cli/collector.go index a48cd909..c3b251a3 100644 --- a/test/cli/collector.go +++ b/test/cli/collector.go @@ -191,7 +191,7 @@ func alertsToString(as []*models.GettableAlert) (string, error) { return string(b), nil } -// CompareCollectors compares two collectors based on their collected alerts +// CompareCollectors compares two collectors based on their collected alerts. func CompareCollectors(a, b *Collector, opts *AcceptanceOpts) (bool, error) { f := func(collected map[float64][]models.GettableAlerts) []*models.GettableAlert { result := []*models.GettableAlert{} diff --git a/test/with_api_v2/collector.go b/test/with_api_v2/collector.go index b0e9adc4..755d292f 100644 --- a/test/with_api_v2/collector.go +++ b/test/with_api_v2/collector.go @@ -191,7 +191,7 @@ func alertsToString(as []*models.GettableAlert) (string, error) { return string(b), nil } -// CompareCollectors compares two collectors based on their collected alerts +// CompareCollectors compares two collectors based on their collected alerts. func CompareCollectors(a, b *Collector, opts *AcceptanceOpts) (bool, error) { f := func(collected map[float64][]models.GettableAlerts) []*models.GettableAlert { result := []*models.GettableAlert{} diff --git a/test/with_api_v2/mock.go b/test/with_api_v2/mock.go index 836199e9..0ac44289 100644 --- a/test/with_api_v2/mock.go +++ b/test/with_api_v2/mock.go @@ -78,7 +78,7 @@ func (s *TestSilence) Match(v ...string) *TestSilence { return s } -// MatchRE adds a new regex matcher to the silence +// MatchRE adds a new regex matcher to the silence. func (s *TestSilence) MatchRE(v ...string) *TestSilence { if len(v)%2 == 1 { panic("bad key/values") diff --git a/timeinterval/timeinterval.go b/timeinterval/timeinterval.go index fe8c97d7..4522a22b 100644 --- a/timeinterval/timeinterval.go +++ b/timeinterval/timeinterval.go @@ -383,7 +383,7 @@ func (r WeekdayRange) MarshalYAML() (interface{}, error) { // MarshalText implements the econding.TextMarshaler interface for WeekdayRange. // It converts the range into a colon-separated string, or a single weekday if possible. -// e.g. "monday:friday" or "saturday". +// E.g. "monday:friday" or "saturday". func (r WeekdayRange) MarshalText() ([]byte, error) { beginStr, ok := daysOfWeekInv[r.Begin] if !ok { @@ -450,7 +450,7 @@ func (tz Location) MarshalJSON() (out []byte, err error) { // MarshalText implements the encoding.TextMarshaler interface for InclusiveRange. // It converts the struct into a colon-separated string, or a single element if -// appropriate. e.g. "monday:friday" or "monday" +// appropriate. E.g. "monday:friday" or "monday". func (ir InclusiveRange) MarshalText() ([]byte, error) { if ir.Begin == ir.End { return []byte(strconv.Itoa(ir.Begin)), nil diff --git a/timeinterval/timeinterval_test.go b/timeinterval/timeinterval_test.go index 8377ac11..8750ca2a 100644 --- a/timeinterval/timeinterval_test.go +++ b/timeinterval/timeinterval_test.go @@ -561,7 +561,7 @@ func TestYamlMarshal(t *testing.T) { } // Test JSON marshalling by marshalling a time interval -// and then unmarshalling to ensure they're identical +// and then unmarshalling to ensure they're identical. func TestJsonMarshal(t *testing.T) { for _, tc := range yamlUnmarshalTestCases { if tc.expectError { @@ -624,7 +624,7 @@ months: ['february'] }, } -// Tests the entire flow from unmarshalling to containing a time +// Tests the entire flow from unmarshalling to containing a time. func TestTimeIntervalComplete(t *testing.T) { for _, tc := range completeTestCases { var ti TimeInterval diff --git a/types/types.go b/types/types.go index 54a889ab..49b9f0b4 100644 --- a/types/types.go +++ b/types/types.go @@ -458,7 +458,7 @@ type Silence struct { } // Expired return if the silence is expired -// meaning that both StartsAt and EndsAt are equal +// meaning that both StartsAt and EndsAt are equal. func (s *Silence) Expired() bool { return s.StartsAt.Equal(s.EndsAt) }