-
Notifications
You must be signed in to change notification settings - Fork 820
Dispatcher groups limits #4254
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
pstibrany
merged 6 commits into
cortexproject:master
from
pstibrany:dispatcher-groups-limits
Jun 9, 2021
Merged
Dispatcher groups limits #4254
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f2d7f55
Expose dispatcher aggregation groups limit.
pstibrany 6b74cf1
Expose dispatcher aggregation groups limit reached metric.
pstibrany 2238aca
CHANGELOG.md
pstibrany 58dd26a
Send two alerts per alert group.
pstibrany 4618a92
Simplify option name, add alertmanager limits to list of experimental…
pstibrany 80137b0
Fix metric name.
pstibrany 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
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
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,112 @@ | ||
package alertmanager | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/prometheus/alertmanager/config" | ||
"github.com/prometheus/alertmanager/types" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/prometheus/common/model" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cortexproject/cortex/pkg/util/test" | ||
) | ||
|
||
func TestDispatcherGroupLimits(t *testing.T) { | ||
for name, tc := range map[string]struct { | ||
groups int | ||
groupsLimit int | ||
expectedFailures int | ||
}{ | ||
"no limit": {groups: 5, groupsLimit: 0, expectedFailures: 0}, | ||
"high limit": {groups: 5, groupsLimit: 10, expectedFailures: 0}, | ||
"low limit": {groups: 5, groupsLimit: 3, expectedFailures: 4}, // 2 groups that fail, 2 alerts per group = 4 failures | ||
} { | ||
t.Run(name, func(t *testing.T) { | ||
createAlertmanagerAndSendAlerts(t, tc.groups, tc.groupsLimit, tc.expectedFailures) | ||
}) | ||
} | ||
} | ||
|
||
func createAlertmanagerAndSendAlerts(t *testing.T, alertGroups, groupsLimit, expectedFailures int) { | ||
user := "test" | ||
|
||
reg := prometheus.NewPedanticRegistry() | ||
am, err := New(&Config{ | ||
UserID: user, | ||
Logger: log.NewNopLogger(), | ||
Limits: &mockAlertManagerLimits{maxDispatcherAggregationGroups: groupsLimit}, | ||
TenantDataDir: t.TempDir(), | ||
ExternalURL: &url.URL{Path: "/am"}, | ||
ShardingEnabled: false, | ||
}, reg) | ||
require.NoError(t, err) | ||
defer am.StopAndWait() | ||
|
||
cfgRaw := `receivers: | ||
- name: 'prod' | ||
|
||
route: | ||
group_by: ['alertname'] | ||
group_wait: 10ms | ||
group_interval: 10ms | ||
receiver: 'prod'` | ||
|
||
cfg, err := config.Load(cfgRaw) | ||
require.NoError(t, err) | ||
require.NoError(t, am.ApplyConfig(user, cfg, cfgRaw)) | ||
|
||
now := time.Now() | ||
|
||
for i := 0; i < alertGroups; i++ { | ||
alertName := model.LabelValue(fmt.Sprintf("Alert-%d", i)) | ||
|
||
inputAlerts := []*types.Alert{ | ||
{ | ||
Alert: model.Alert{ | ||
Labels: model.LabelSet{ | ||
"alertname": alertName, | ||
"a": "b", | ||
}, | ||
Annotations: model.LabelSet{"foo": "bar"}, | ||
StartsAt: now, | ||
EndsAt: now.Add(5 * time.Minute), | ||
GeneratorURL: "http://example.com/prometheus", | ||
}, | ||
UpdatedAt: now, | ||
Timeout: false, | ||
}, | ||
|
||
{ | ||
Alert: model.Alert{ | ||
Labels: model.LabelSet{ | ||
"alertname": alertName, | ||
"z": "y", | ||
}, | ||
Annotations: model.LabelSet{"foo": "bar"}, | ||
StartsAt: now, | ||
EndsAt: now.Add(5 * time.Minute), | ||
GeneratorURL: "http://example.com/prometheus", | ||
}, | ||
UpdatedAt: now, | ||
Timeout: false, | ||
}, | ||
} | ||
require.NoError(t, am.alerts.Put(inputAlerts...)) | ||
} | ||
|
||
// Give it some time, as alerts are sent to dispatcher asynchronously. | ||
test.Poll(t, 3*time.Second, nil, func() interface{} { | ||
return testutil.GatherAndCompare(reg, strings.NewReader(fmt.Sprintf(` | ||
# HELP alertmanager_dispatcher_aggregation_group_limit_reached_total Number of times when dispatcher failed to create new aggregation group due to limit. | ||
# TYPE alertmanager_dispatcher_aggregation_group_limit_reached_total counter | ||
alertmanager_dispatcher_aggregation_group_limit_reached_total %d | ||
`, expectedFailures)), "alertmanager_dispatcher_aggregation_group_limit_reached_total") | ||
}) | ||
} |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.