Skip to content

Commit

Permalink
change infos to infolist
Browse files Browse the repository at this point in the history
Signed-off-by: Yijie Qin <[email protected]>
  • Loading branch information
qinxx108 committed Jun 2, 2023
1 parent ec07180 commit ff168b1
Show file tree
Hide file tree
Showing 17 changed files with 584 additions and 584 deletions.
28 changes: 14 additions & 14 deletions api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"sync"
"time"

alertgroupinfos_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/alertgroupinfos"
alertgroupinfolist_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/alertgroupinfolist"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -127,7 +127,7 @@ func NewAPI(
openAPI.AlertGetAlertsHandler = alert_ops.GetAlertsHandlerFunc(api.getAlertsHandler)
openAPI.AlertPostAlertsHandler = alert_ops.PostAlertsHandlerFunc(api.postAlertsHandler)
openAPI.AlertgroupGetAlertGroupsHandler = alertgroup_ops.GetAlertGroupsHandlerFunc(api.getAlertGroupsHandler)
openAPI.AlertgroupinfosGetAlertGroupInfosHandler = alertgroupinfos_ops.GetAlertGroupInfosHandlerFunc(api.getAlertGroupInfosHandler)
openAPI.AlertgroupinfolistGetAlertGroupInfoListHandler = alertgroupinfolist_ops.GetAlertGroupInfoListHandlerFunc(api.getAlertGroupInfoListHandler)
openAPI.GeneralGetStatusHandler = general_ops.GetStatusHandlerFunc(api.getStatusHandler)
openAPI.ReceiverGetReceiversHandler = receiver_ops.GetReceiversHandlerFunc(api.getReceiversHandler)
openAPI.SilenceDeleteSilenceHandler = silence_ops.DeleteSilenceHandlerFunc(api.deleteSilenceHandler)
Expand Down Expand Up @@ -430,7 +430,7 @@ func (api *API) getAlertGroupsHandler(params alertgroup_ops.GetAlertGroupsParams
return alertgroup_ops.NewGetAlertGroupsOK().WithPayload(res)
}

func (api *API) getAlertGroupInfosHandler(params alertgroupinfos_ops.GetAlertGroupInfosParams) middleware.Responder {
func (api *API) getAlertGroupInfoListHandler(params alertgroupinfolist_ops.GetAlertGroupInfoListParams) middleware.Responder {
logger := api.requestLogger(params.HTTPRequest)

var returnPaginationToken string
Expand All @@ -440,8 +440,8 @@ func (api *API) getAlertGroupInfosHandler(params alertgroupinfos_ops.GetAlertGro
receiverFilter, err = regexp.Compile("^(?:" + *params.Receiver + ")$")
if err != nil {
level.Error(logger).Log("msg", "Failed to compile receiver regex", "err", err)
return alertgroupinfos_ops.
NewGetAlertGroupInfosBadRequest().
return alertgroupinfolist_ops.
NewGetAlertGroupInfoListBadRequest().
WithPayload(
fmt.Sprintf("failed to parse receiver param: %v", err.Error()),
)
Expand All @@ -462,17 +462,17 @@ func (api *API) getAlertGroupInfosHandler(params alertgroupinfos_ops.GetAlertGro

if err = validateNextToken(params.NextToken); err != nil {
level.Error(logger).Log("msg", "Failed to parse NextToken parameter", "err", err)
return alertgroupinfos_ops.
NewGetAlertGroupInfosBadRequest().
return alertgroupinfolist_ops.
NewGetAlertGroupInfoListBadRequest().
WithPayload(
fmt.Sprintf("failed to parse NextToken param: %v", *params.NextToken),
)
}

if err = validateMaxResult(params.MaxResults); err != nil {
level.Error(logger).Log("msg", "Failed to parse MaxResults parameter", "err", err)
return alertgroupinfos_ops.
NewGetAlertGroupInfosBadRequest().
return alertgroupinfolist_ops.
NewGetAlertGroupInfoListBadRequest().
WithPayload(
fmt.Sprintf("failed to parse MaxResults param: %v", *params.MaxResults),
)
Expand Down Expand Up @@ -508,12 +508,12 @@ func (api *API) getAlertGroupInfosHandler(params alertgroupinfos_ops.GetAlertGro
}
}

response := &open_api_models.AlertGroupInfos{
AlertGroupInfos: alertGroupInfos,
NextToken: returnPaginationToken,
response := &open_api_models.AlertGroupInfoList{
AlertGroupInfoList: alertGroupInfos,
NextToken: returnPaginationToken,
}

return alertgroupinfos_ops.NewGetAlertGroupInfosOK().WithPayload(response)
return alertgroupinfolist_ops.NewGetAlertGroupInfoListOK().WithPayload(response)
}

func (api *API) alertFilter(matchers []*labels.Matcher, silenced, inhibited, active bool) func(a *types.Alert, now time.Time) bool {
Expand Down Expand Up @@ -817,7 +817,7 @@ func getSwaggerSpec() (*loads.Document, *analysis.Spec, error) {
func validateMaxResult(maxItem *int64) error {
if maxItem != nil {
if *maxItem < 0 {
return errors.New("the maxItem need to be larger than 0")
return errors.New("the maxItem need to be larger than or equal to 0")
}
}
return nil
Expand Down
12 changes: 6 additions & 6 deletions api/v2/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"
"time"

alertgroupinfos_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/alertgroupinfos"
alertgroupinfolist_ops "github.com/prometheus/alertmanager/api/v2/restapi/operations/alertgroupinfolist"
"github.com/prometheus/alertmanager/dispatch"

"github.com/go-openapi/runtime"
Expand Down Expand Up @@ -194,28 +194,28 @@ func TestGetAlertGroupInfosHandler(t *testing.T) {
{
convertIntToPointerInt64(int64(1)),
"",
`{"alertGroupInfos":[{"labels":{"alertname":"TestingAlert","service":"api"},"receiver":{"name":"testing"}}],"nextToken":"478b4114226224a35910d449fdba8186ebfb441f"}`,
`{"alertGroupInfoList":[{"labels":{"alertname":"TestingAlert","service":"api"},"receiver":{"name":"testing"}}],"nextToken":"478b4114226224a35910d449fdba8186ebfb441f"}`,
200,
},
// One item to return, has next token.
{
convertIntToPointerInt64(int64(1)),
"478b4114226224a35910d449fdba8186ebfb441f",
`{"alertGroupInfos":[{"labels":{"alertname":"HighErrorRate","cluster":"bb","service":"api"},"receiver":{"name":"prod"}}],"nextToken":"7f4084a078a3fe29d6de82fad15af8f1411e803f"}`,
`{"alertGroupInfoList":[{"labels":{"alertname":"HighErrorRate","cluster":"bb","service":"api"},"receiver":{"name":"prod"}}],"nextToken":"7f4084a078a3fe29d6de82fad15af8f1411e803f"}`,
200,
},
// Five item to return, has next token.
{
convertIntToPointerInt64(int64(5)),
"7f4084a078a3fe29d6de82fad15af8f1411e803f",
`{"alertGroupInfos":[{"labels":{"alertname":"OtherAlert"},"receiver":{"name":"prod"}},{"labels":{"alertname":"HighErrorRate","cluster":"aa","service":"api"},"receiver":{"name":"prod"}}]}`,
`{"alertGroupInfoList":[{"labels":{"alertname":"OtherAlert"},"receiver":{"name":"prod"}},{"labels":{"alertname":"HighErrorRate","cluster":"aa","service":"api"},"receiver":{"name":"prod"}}]}`,
200,
},
// Return all results.
{
nil,
"",
`{"alertGroupInfos":[{"labels":{"alertname":"TestingAlert","service":"api"},"receiver":{"name":"testing"}},{"labels":{"alertname":"HighErrorRate","cluster":"bb","service":"api"},"receiver":{"name":"prod"}},{"labels":{"alertname":"OtherAlert"},"receiver":{"name":"prod"}},{"labels":{"alertname":"HighErrorRate","cluster":"aa","service":"api"},"receiver":{"name":"prod"}}]}`,
`{"alertGroupInfoList":[{"labels":{"alertname":"TestingAlert","service":"api"},"receiver":{"name":"testing"}},{"labels":{"alertname":"HighErrorRate","cluster":"bb","service":"api"},"receiver":{"name":"prod"}},{"labels":{"alertname":"OtherAlert"},"receiver":{"name":"prod"}},{"labels":{"alertname":"HighErrorRate","cluster":"aa","service":"api"},"receiver":{"name":"prod"}}]}`,
200,
},
} {
Expand All @@ -231,7 +231,7 @@ func TestGetAlertGroupInfosHandler(t *testing.T) {

w := httptest.NewRecorder()
p := runtime.TextProducer()
responder := api.getAlertGroupInfosHandler(alertgroupinfos_ops.GetAlertGroupInfosParams{
responder := api.getAlertGroupInfoListHandler(alertgroupinfolist_ops.GetAlertGroupInfoListParams{
MaxResults: tc.maxResult,
NextToken: &tc.nextToken,
HTTPRequest: r,
Expand Down

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

Loading

0 comments on commit ff168b1

Please sign in to comment.