Skip to content

Commit

Permalink
Merge branch 'prometheus:main' into add-route-id
Browse files Browse the repository at this point in the history
  • Loading branch information
qinxx108 authored Sep 14, 2023
2 parents 5321ca6 + 5ba9b9c commit 2221f3b
Show file tree
Hide file tree
Showing 55 changed files with 17,716 additions and 148 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
version: 2.1
orbs:
prometheus: prometheus/prometheus@0.16.0
prometheus: prometheus/prometheus@0.17.1
go: circleci/go@1.7.3
jobs:
test_frontend:
Expand Down Expand Up @@ -151,7 +151,6 @@ workflows:
- test_frontend
- test
- build_all
docker_version: "20.10.18"
filters:
branches:
only: main
Expand All @@ -161,7 +160,6 @@ workflows:
- test_frontend
- test
- build_all
docker_version: "20.10.18"
filters:
tags:
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
Expand Down
13 changes: 12 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ linters-settings:
- github.com/stretchr/testify/assert: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
- github.com/go-kit/kit/log: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
errcheck:
exclude: scripts/errcheck_excludes.txt
exclude-functions:
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
- io.Copy
# The next two are used in HTTP handlers, any error is handled by the server itself.
- io.WriteString
- (net/http.ResponseWriter).Write
# No need to check for errors on server's shutdown.
- (*net/http.Server).Shutdown
# Never check for logger errors.
- (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
goimports:
local-prefixes: github.com/prometheus/alertmanager
gofumpt:
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
## 0.26.0 / 2023-08-23

* [SECURITY] Fix stored XSS via the /api/v1/alerts endpoint in the Alertmanager UI. CVE-2023-40577
* [CHANGE] Telegram Integration: `api_url` is now optional. #2981
* [CHANGE] Telegram Integration: `ParseMode` default is now `HTML` instead of `MarkdownV2`. #2981
* [CHANGE] Webhook Integration: `url` is now marked as a secret. It will no longer show up in the logs as clear-text. #3228
* [CHANGE] Metrics: New label `reason` for `alertmanager_notifications_failed_total` metric to indicate the type of error of the alert delivery. #3094 #3307
* [FEATURE] Clustering: New flag `--cluster.label`, to help to block any traffic that is not meant for the cluster. #3354
* [FEATURE] Integrations: Add Microsoft Teams as a supported integration. #3324
* [ENHANCEMENT] Telegram Integration: Support `bot_token_file` for loading this secret from a file. #3226
* [ENHANCEMENT] Webhook Integration: Support `url_file` for loading this secret from a file. #3223
* [ENHANCEMENT] Webhook Integration: Leading and trailing white space is now removed for the contents of `url_file`. #3363
* [ENHANCEMENT] Pushover Integration: Support options `device` and `sound` (sound was previously supported but undocumented). #3318
* [ENHANCEMENT] Pushover Integration: Support `user_key_file` and `token_file` for loading this secret from a file. #3200
* [ENHANCEMENT] Slack Integration: Support errors wrapped in successful (HTTP status code 200) responses. #3121
* [ENHANCEMENT] API: Add `CORS` and `Cache-Control` HTTP headers to all version 2 API routes. #3195
* [ENHANCEMENT] UI: Receiver name is now visible as part of the alerts page. #3289
* [ENHANCEMENT] Templating: Better default text when using `{{ .Annotations }}` and `{{ .Labels }}`. #3256
* [ENHANCEMENT] Templating: Introduced a new function `trimSpace` which removes leading and trailing white spaces. #3223
* [ENHANCEMENT] CLI: `amtool silence query` now supports the `--id` flag to query an individual silence. #3241
* [ENHANCEMENT] Metrics: Introduced `alertmanager_nflog_maintenance_total` and `alertmanager_nflog_maintenance_errors_total` to monitor maintenance of the notification log. #3286
* [ENHANCEMENT] Metrics: Introduced `alertmanager_silences_maintenance_total` and `alertmanager_silences_maintenance_errors_total` to monitor maintenance of silences. #3285
* [ENHANCEMENT] Logging: Log GroupKey and alerts on alert delivery when using debug mode. #3438
* [BUGFIX] Configuration: Empty list of `receivers` and `inhibit_rules` would cause the alertmanager to crash. #3209
* [BUGFIX] Templating: Fixed a race condition when using the `title` function. It is now race-safe. #3278
* [BUGFIX] API: Fixed duplicate receiver names in the `api/v2/receivers` API endpoint. #3338
* [BUGFIX] API: Attempting to delete a silence now returns the correct status code, `404` instead of `500`. #3352
* [BUGFIX] Clustering: Fixes a panic when `tls_client_config` is empty. #3443
* [BUGFIX] Fix stored XSS via the /api/v1/alerts endpoint in the Alertmanager UI.

## 0.25.0 / 2022-12-22

* [CHANGE] Change the default `parse_mode` value from `MarkdownV2` to `HTML` for Telegram. #2981
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ STATICCHECK_IGNORE =
# Will build both the front-end as well as the back-end
build-all: assets apiv2 build

.PHONY: build
build: build-react-app assets-compress common-build

.PHONY: lint
lint: assets-compress common-lint

.PHONY: build-react-app
build-react-app:
cd ui/react-app && npm install && npm run build

.PHONY: assets-compress
assets-compress:
@echo '>> compressing assets'
scripts/compress_assets.sh

.PHONY: assets
assets: asset/assets_vfsdata.go

Expand Down
15 changes: 15 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Releases
This page describes the release process and the currently planned schedule for upcoming releases as well as the respective release shepherd. Release shepherds are chosen on a voluntary basis.

## Release Schedule

Release cadence of first pre-releases being cut is 12 weeks.

| release series | date (year-month-day) | release shepherd |
|----------------|-----------------------|-------------------------------|
| v0.26 | 2023-08-23 | Josh Abreu (Github: @gotjosh) |
| v0.27 | 2023-11-01 | Josh Abreu (Github: @gotjosh) |

If you are interested in volunteering please create a pull request against the [prometheus/alertmanager](https://github.com/prometheus/alertmanager) repository and propose yourself for the release of your choice.

If you'd like to know more about the shepherd responsibilities or the release instructions please [refer to the `RELEASE.MD`](https://github.com/prometheus/prometheus/blob/main/RELEASE.md) in [prometheus/prometheus](https://github.com/prometheus/prometheus).
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.25.0
0.26.0
4 changes: 2 additions & 2 deletions asset/assets_vfsdata.go

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions cmd/alertmanager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/prometheus/alertmanager/cluster"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/dispatch"
"github.com/prometheus/alertmanager/featurecontrol"
"github.com/prometheus/alertmanager/inhibit"
"github.com/prometheus/alertmanager/nflog"
"github.com/prometheus/alertmanager/notify"
Expand Down Expand Up @@ -142,7 +143,7 @@ func buildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logg
errs.Add(err)
return
}
integrations = append(integrations, notify.NewIntegration(n, rs, name, i))
integrations = append(integrations, notify.NewIntegration(n, rs, name, i, nc.Name))
}
)

Expand Down Expand Up @@ -231,6 +232,7 @@ func run() int {
tlsConfigFile = kingpin.Flag("cluster.tls-config", "[EXPERIMENTAL] Path to config yaml file that can enable mutual TLS within the gossip protocol.").Default("").String()
allowInsecureAdvertise = kingpin.Flag("cluster.allow-insecure-public-advertise-address-discovery", "[EXPERIMENTAL] Allow alertmanager to discover and listen on a public IP address.").Bool()
label = kingpin.Flag("cluster.label", "The cluster label is an optional string to include on each packet and stream. It uniquely identifies the cluster and prevents cross-communication issues when sending gossip messages.").Default("").String()
featureFlags = kingpin.Flag("enable-feature", fmt.Sprintf("Experimental features to enable. The flag can be repeated to enable multiple features. Valid options: %s", strings.Join(featurecontrol.AllowedFlags, ", "))).Default("").String()
)

promlogflag.AddFlags(kingpin.CommandLine, &promlogConfig)
Expand All @@ -245,7 +247,13 @@ func run() int {
level.Info(logger).Log("msg", "Starting Alertmanager", "version", version.Info())
level.Info(logger).Log("build_context", version.BuildContext())

err := os.MkdirAll(*dataDir, 0o777)
featureConfig, err := featurecontrol.NewFlags(logger, *featureFlags)
if err != nil {
level.Error(logger).Log("msg", "error parsing the feature flag list", "err", err)
return 1
}

err = os.MkdirAll(*dataDir, 0o777)
if err != nil {
level.Error(logger).Log("msg", "Unable to create data directory", "err", err)
return 1
Expand Down Expand Up @@ -421,7 +429,7 @@ func run() int {
)

dispMetrics := dispatch.NewDispatcherMetrics(false, prometheus.DefaultRegisterer)
pipelineBuilder := notify.NewPipelineBuilder(prometheus.DefaultRegisterer)
pipelineBuilder := notify.NewPipelineBuilder(prometheus.DefaultRegisterer, featureConfig)
configLogger := log.With(logger, "component", "configuration")
configCoordinator := config.NewCoordinator(
*configFile,
Expand Down Expand Up @@ -493,6 +501,7 @@ func run() int {
notificationLog,
pipelinePeer,
)

configuredReceivers.Set(float64(len(activeReceivers)))
configuredIntegrations.Set(float64(integrationsNum))

Expand Down
4 changes: 2 additions & 2 deletions cmd/alertmanager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestBuildReceiverIntegrations(t *testing.T) {
},
},
exp: []notify.Integration{
notify.NewIntegration(nil, sendResolved(false), "webhook", 0),
notify.NewIntegration(nil, sendResolved(true), "webhook", 1),
notify.NewIntegration(nil, sendResolved(false), "webhook", 0, "foo"),
notify.NewIntegration(nil, sendResolved(true), "webhook", 1, "foo"),
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ type Receiver struct {
SNSConfigs []*SNSConfig `yaml:"sns_configs,omitempty" json:"sns_configs,omitempty"`
TelegramConfigs []*TelegramConfig `yaml:"telegram_configs,omitempty" json:"telegram_configs,omitempty"`
WebexConfigs []*WebexConfig `yaml:"webex_configs,omitempty" json:"webex_configs,omitempty"`
MSTeamsConfigs []*MSTeamsConfig `yaml:"msteams_configs,omitempty" json:"teams_configs,omitempty"`
MSTeamsConfigs []*MSTeamsConfig `yaml:"msteams_configs,omitempty" json:"msteams_configs,omitempty"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface for Receiver.
Expand Down
6 changes: 1 addition & 5 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,6 @@ func (c *WebhookConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
if c.URL != nil && c.URLFile != "" {
return fmt.Errorf("at most one of url & url_file must be configured")
}
if c.URL != nil {
if c.URL.Scheme != "https" && c.URL.Scheme != "http" {
return fmt.Errorf("scheme required for webhook url")
}
}
return nil
}

Expand Down Expand Up @@ -694,6 +689,7 @@ type PushoverConfig struct {
Priority string `yaml:"priority,omitempty" json:"priority,omitempty"`
Retry duration `yaml:"retry,omitempty" json:"retry,omitempty"`
Expire duration `yaml:"expire,omitempty" json:"expire,omitempty"`
TTL duration `yaml:"ttl,omitempty" json:"ttl,omitempty"`
HTML bool `yaml:"html" json:"html,omitempty"`
}

Expand Down
12 changes: 9 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,18 @@ matchers:
# How long to initially wait to send a notification for a group
# of alerts. Allows to wait for an inhibiting alert to arrive or collect
# more initial alerts for the same group. (Usually ~0s to few minutes.)
# If omitted, child routes inherit the group_wait of the parent route.
[ group_wait: <duration> | default = 30s ]
# How long to wait before sending a notification about new alerts that
# are added to a group of alerts for which an initial notification has
# already been sent. (Usually ~5m or more.)
# already been sent. (Usually ~5m or more.) If omitted, child routes
# inherit the group_interval of the parent route.
[ group_interval: <duration> | default = 5m ]
# How long to wait before sending a notification again if it has already
# been sent successfully for an alert. (Usually ~3h or more).
# been sent successfully for an alert. (Usually ~3h or more). If omitted,
# child routes inherit the repeat_interval of the parent route.
# Note that this parameter is implicitly bound by Alertmanager's
# `--data.retention` configuration flag. Notifications will be resent after either
# repeat_interval or the data retention period have passed, whichever
Expand Down Expand Up @@ -563,7 +566,7 @@ oauth2:
# that should be excluded from proxying. IP and domain names can
# contain port numbers.
[ no_proxy: <string> ]
# Use proxy URL indicated by environment variables (HTTP_PROXY, https_proxy, HTTPs_PROXY, https_proxy, and no_proxy)
# Use proxy URL indicated by environment variables (HTTP_PROXY, http_proxy, HTTPS_PROXY, https_proxy, NO_PROXY, and no_proxy)
[ proxy_from_environment: <boolean> | default: false ]
# Specifies headers to send to proxies during CONNECT requests.
[ proxy_connect_header:
Expand Down Expand Up @@ -945,6 +948,9 @@ token_file: <filepath>
# acknowledges the notification.
[ expire: <duration> | default = 1h ]
# Optional time to live (TTL) to use for notification, see https://pushover.net/api#ttl
[ ttl: <duration> ]
# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]
```
Expand Down
78 changes: 78 additions & 0 deletions featurecontrol/featurecontrol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2023 Prometheus Team
// 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 featurecontrol

import (
"fmt"
"strings"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
)

const (
fcReceiverNameInMetrics = "receiver-name-in-metrics"
)

var AllowedFlags = []string{fcReceiverNameInMetrics}

type Flagger interface {
EnableReceiverNamesInMetrics() bool
}

type Flags struct {
logger log.Logger
enableReceiverNamesInMetrics bool
}

func (f *Flags) EnableReceiverNamesInMetrics() bool {
return f.enableReceiverNamesInMetrics
}

type flagOption func(flags *Flags)

func enableReceiverNameInMetrics() flagOption {
return func(configs *Flags) {
configs.enableReceiverNamesInMetrics = true
}
}

func NewFlags(logger log.Logger, features string) (Flagger, error) {
fc := &Flags{logger: logger}
opts := []flagOption{}

if len(features) == 0 {
return NoopFlags{}, nil
}

for _, feature := range strings.Split(features, ",") {
switch feature {
case fcReceiverNameInMetrics:
opts = append(opts, enableReceiverNameInMetrics())
level.Warn(logger).Log("msg", "Experimental receiver name in metrics enabled")
default:
return nil, fmt.Errorf("Unknown option '%s' for --enable-feature", feature)
}
}

for _, opt := range opts {
opt(fc)
}

return fc, nil
}

type NoopFlags struct{}

func (n NoopFlags) EnableReceiverNamesInMetrics() bool { return false }
58 changes: 58 additions & 0 deletions featurecontrol/featurecontrol_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2023 Prometheus Team
// 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 featurecontrol

import (
"errors"
"strings"
"testing"

"github.com/go-kit/log"
"github.com/stretchr/testify/require"
)

func TestFlags(t *testing.T) {
tc := []struct {
name string
featureFlags string
err error
}{
{
name: "with only valid feature flags",
featureFlags: fcReceiverNameInMetrics,
},
{
name: "with only invalid feature flags",
featureFlags: "somethingsomething",
err: errors.New("Unknown option 'somethingsomething' for --enable-feature"),
},
{
name: "with both, valid and invalid feature flags",
featureFlags: strings.Join([]string{fcReceiverNameInMetrics, "somethingbad"}, ","),
err: errors.New("Unknown option 'somethingbad' for --enable-feature"),
},
}

for _, tt := range tc {
t.Run(tt.name, func(t *testing.T) {
fc, err := NewFlags(log.NewNopLogger(), tt.featureFlags)
if tt.err != nil {
require.EqualError(t, err, tt.err.Error())
} else {
require.NoError(t, err)
require.NotNil(t, fc)
}
})
}
}
Loading

0 comments on commit 2221f3b

Please sign in to comment.