Skip to content

Commit

Permalink
Merge pull request #83 from grafana/santihernandezc/remove_changes_in…
Browse files Browse the repository at this point in the history
…_receivers

remove changes related to capturing and exposing errors in notificati…
  • Loading branch information
santihernandezc authored Jun 4, 2024
2 parents 2798416 + 5121fbc commit c854031
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 464 deletions.
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

0 comments on commit c854031

Please sign in to comment.