Skip to content

Commit

Permalink
Merge pull request #1632 from mxinden/alerts-api-v2
Browse files Browse the repository at this point in the history
ui: Move alerts to api v2
  • Loading branch information
mxinden committed Nov 26, 2018
2 parents 2962039 + f504f95 commit 091a8a8
Show file tree
Hide file tree
Showing 46 changed files with 1,060 additions and 508 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ test/with_api_v2/api_v2_client/models test/with_api_v2/api_v2_client/client: api

.PHONY: clean
clean:
rm -f asset/assets_vfsdata.go
rm -r api/v2/models api/v2/restapi test/with_api_v2/api_v2_client/models test/with_api_v2/api_v2_client/client
cd $(FRONTEND_DIR) && $(MAKE) clean
- rm -f asset/assets_vfsdata.go
- rm -r api/v2/models api/v2/restapi test/with_api_v2/api_v2_client/models test/with_api_v2/api_v2_client/client
- cd $(FRONTEND_DIR) && $(MAKE) clean

.PHONY: test
test: common-test $(ERRCHECK_BINARY)
Expand Down
28 changes: 20 additions & 8 deletions api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (api *API) getAlertsHandler(params alert_ops.GetAlertsParams) middleware.Re
receiverFilter *regexp.Regexp
// Initialize result slice to prevent api returning `null` when there
// are no alerts present
res = []*open_api_models.Alert{}
res = open_api_models.GettableAlerts{}
matchers = []*labels.Matcher{}
)

Expand Down Expand Up @@ -251,22 +251,35 @@ func (api *API) getAlertsHandler(params alert_ops.GetAlertsParams) middleware.Re
}

state := string(status.State)
startsAt := strfmt.DateTime(a.StartsAt)
updatedAt := strfmt.DateTime(a.UpdatedAt)
endsAt := strfmt.DateTime(a.EndsAt)
fingerprint := a.Fingerprint().String()

alert := open_api_models.Alert{
alert := open_api_models.GettableAlert{
Annotations: modelLabelSetToAPILabelSet(a.Annotations),
EndsAt: strfmt.DateTime(a.EndsAt),
Fingerprint: a.Fingerprint().String(),
StartsAt: &startsAt,
UpdatedAt: &updatedAt,
EndsAt: &endsAt,
Fingerprint: &fingerprint,
GeneratorURL: strfmt.URI(a.GeneratorURL),
Labels: modelLabelSetToAPILabelSet(a.Labels),
Receivers: receivers,
StartsAt: strfmt.DateTime(a.StartsAt),
Status: &open_api_models.AlertStatus{
State: &state,
SilencedBy: status.SilencedBy,
InhibitedBy: status.InhibitedBy,
},
}

if alert.Status.SilencedBy == nil {
alert.Status.SilencedBy = []string{}
}

if alert.Status.InhibitedBy == nil {
alert.Status.InhibitedBy = []string{}
}

res = append(res, &alert)
}
api.mtx.RUnlock()
Expand All @@ -276,7 +289,7 @@ func (api *API) getAlertsHandler(params alert_ops.GetAlertsParams) middleware.Re
return alert_ops.NewGetAlertsInternalServerError().WithPayload(err.Error())
}
sort.Slice(res, func(i, j int) bool {
return res[i].Fingerprint < res[j].Fingerprint
return *res[i].Fingerprint < *res[j].Fingerprint
})

return alert_ops.NewGetAlertsOK().WithPayload(res)
Expand Down Expand Up @@ -343,11 +356,10 @@ func (api *API) postAlertsHandler(params alert_ops.PostAlertsParams) middleware.
return alert_ops.NewPostAlertsOK()
}

func openAPIAlertsToAlerts(apiAlerts open_api_models.Alerts) []*types.Alert {
func openAPIAlertsToAlerts(apiAlerts open_api_models.PostableAlerts) []*types.Alert {
alerts := []*types.Alert{}
for _, apiAlert := range apiAlerts {
alert := types.Alert{
UpdatedAt: time.Time(apiAlert.UpdatedAt),
Alert: prometheus_model.Alert{
Labels: apiLabelSetToModelLabelSet(apiAlert.Labels),
Annotations: apiLabelSetToModelLabelSet(apiAlert.Annotations),
Expand Down
88 changes: 52 additions & 36 deletions api/v2/models/alert.go → api/v2/models/gettable_alert.go

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

10 changes: 5 additions & 5 deletions api/v2/models/alerts.go → api/v2/models/gettable_alerts.go

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

Loading

0 comments on commit 091a8a8

Please sign in to comment.