Skip to content
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

remove changes related to capturing and exposing errors in notificati… #83

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/prometheus/alertmanager/cluster"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/dispatch"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/provider"
"github.com/prometheus/alertmanager/silence"
"github.com/prometheus/alertmanager/types"
Expand Down Expand Up @@ -187,8 +186,8 @@ func (api *API) Register(r *route.Router, routePrefix string) *http.ServeMux {

// Update config and resolve timeout of each API. APIv2 also needs
// setAlertStatus to be updated.
func (api *API) Update(cfg *config.Config, receivers []*notify.Receiver, setAlertStatus func(model.LabelSet)) {
api.v2.Update(cfg, setAlertStatus, receivers)
func (api *API) Update(cfg *config.Config, setAlertStatus func(model.LabelSet)) {
api.v2.Update(cfg, setAlertStatus)
}

func (api *API) limitHandler(h http.Handler) http.Handler {
Expand Down
45 changes: 7 additions & 38 deletions api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/dispatch"
"github.com/prometheus/alertmanager/matchers/compat"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/pkg/labels"
"github.com/prometheus/alertmanager/provider"
"github.com/prometheus/alertmanager/silence"
Expand Down Expand Up @@ -75,8 +74,7 @@ type API struct {
logger log.Logger
m *metrics.Alerts

Handler http.Handler
receivers []*notify.Receiver
Handler http.Handler
}

type (
Expand Down Expand Up @@ -158,14 +156,13 @@ func (api *API) requestLogger(req *http.Request) log.Logger {
}

// Update sets the API struct members that may change between reloads of alertmanager.
func (api *API) Update(cfg *config.Config, setAlertStatus setAlertStatusFn, receivers []*notify.Receiver) {
func (api *API) Update(cfg *config.Config, setAlertStatus setAlertStatusFn) {
api.mtx.Lock()
defer api.mtx.Unlock()

api.alertmanagerConfig = cfg
api.route = dispatch.NewRoute(cfg.Route, nil)
api.setAlertStatus = setAlertStatus
api.receivers = receivers
}

func (api *API) getStatusHandler(params general_ops.GetStatusParams) middleware.Responder {
Expand Down Expand Up @@ -226,40 +223,12 @@ func (api *API) getStatusHandler(params general_ops.GetStatusParams) middleware.

func (api *API) getReceiversHandler(params receiver_ops.GetReceiversParams) middleware.Responder {
api.mtx.RLock()
configReceivers := api.receivers
api.mtx.RUnlock()

receivers := make([]*open_api_models.Receiver, 0, len(configReceivers))
for _, r := range configReceivers {
integrations := make([]*open_api_models.Integration, 0, len(r.Integrations()))

for _, integration := range r.Integrations() {
notify, duration, err := integration.GetReport()
iname := integration.String()
sendResolved := integration.SendResolved()
integrations = append(integrations, &open_api_models.Integration{
Name: &iname,
SendResolved: &sendResolved,
LastNotifyAttempt: strfmt.DateTime(notify.UTC()),
LastNotifyAttemptDuration: duration.String(),
LastNotifyAttemptError: func() string {
if err != nil {
return err.Error()
}
return ""
}(),
})
}

rName := r.Name()
active := r.Active()
model := &open_api_models.Receiver{
Name: &rName,
Active: &active,
Integrations: integrations,
}
defer api.mtx.RUnlock()

receivers = append(receivers, model)
receivers := make([]*open_api_models.Receiver, 0, len(api.alertmanagerConfig.Receivers))
for _, r := range api.alertmanagerConfig.Receivers {
name := r.Name
receivers = append(receivers, &open_api_models.Receiver{Name: &name})
}

return receiver_ops.NewGetReceiversOK().WithPayload(receivers)
Expand Down
7 changes: 1 addition & 6 deletions api/v2/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
receiver_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/receiver"
silence_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/silence"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/pkg/labels"
"github.com/prometheus/alertmanager/silence"
"github.com/prometheus/alertmanager/silence/silencepb"
Expand Down Expand Up @@ -485,18 +484,14 @@ receivers:
uptime: time.Now(),
logger: log.NewNopLogger(),
alertmanagerConfig: cfg,
receivers: []*notify.Receiver{
notify.NewReceiver("team-X", true, nil),
notify.NewReceiver("team-Y", true, nil),
},
}

for _, tc := range []struct {
body string
expectedCode int
}{
{
`[{"active":true,"integrations":[],"name":"team-X"},{"active":true,"integrations":[],"name":"team-Y"}]`,
`[{"name":"team-X"},{"name":"team-Y"}]`,
200,
},
} {
Expand Down
128 changes: 0 additions & 128 deletions api/v2/models/integration.go

This file was deleted.

89 changes: 1 addition & 88 deletions api/v2/models/receiver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading