mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-24 23:13:18 +00:00
f1b920bcc9
The current Alertmanager API v1 is undocumented and written by hand. This patch introduces a new Alertmanager API - v2. The API is fully generated via an OpenAPI 2.0 [1] specification (see `api/v2/openapi.yaml`) with the exception of the http handlers itself. Pros: - Generated server code - Ability to generate clients in all major languages (Go, Java, JS, Python, Ruby, Haskell, *elm* [3] ...) - Strict contract (OpenAPI spec) between server and clients. - Instant feedback on frontend-breaking changes, due to strictly typed frontend language elm. - Generated documentation (See Alertmanager online Swagger UI [4]) Cons: - Dependency on open api ecosystem including go-swagger [2] In addition this patch includes the following changes. - README.md: Add API section - test: Duplicate acceptance test to API v1 & API v2 version The Alertmanager acceptance test framework has a decent test coverage on the Alertmanager API. Introducing the Alertmanager API v2 does not go hand in hand with deprecating API v1. They should live alongside each other for a couple of minor Alertmanager versions. Instead of porting the acceptance test framework to use the new API v2, this patch duplicates the acceptance tests, one using the API v1, the other API v2. Once API v1 is removed we can simply remove `test/with_api_v1` and bring `test/with_api_v2` to `test/`. [1] https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md [2] https://github.com/go-swagger/go-swagger/ [3] https://github.com/ahultgren/swagger-elm [4] http://petstore.swagger.io/?url=https://raw.githubusercontent.com/mxinden/alertmanager/apiv2/api/v2/openapi.yaml Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
100 lines
2.4 KiB
Go
100 lines
2.4 KiB
Go
// Code generated by go-swagger; DO NOT EDIT.
|
|
|
|
package silence
|
|
|
|
// This file was generated by the swagger tool.
|
|
// Editing this file might prove futile when you re-run the swagger generate command
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-openapi/runtime"
|
|
)
|
|
|
|
// PostSilencesOKCode is the HTTP code returned for type PostSilencesOK
|
|
const PostSilencesOKCode int = 200
|
|
|
|
/*PostSilencesOK Create / update silence response
|
|
|
|
swagger:response postSilencesOK
|
|
*/
|
|
type PostSilencesOK struct {
|
|
|
|
/*
|
|
In: Body
|
|
*/
|
|
Payload *PostSilencesOKBody `json:"body,omitempty"`
|
|
}
|
|
|
|
// NewPostSilencesOK creates PostSilencesOK with default headers values
|
|
func NewPostSilencesOK() *PostSilencesOK {
|
|
|
|
return &PostSilencesOK{}
|
|
}
|
|
|
|
// WithPayload adds the payload to the post silences o k response
|
|
func (o *PostSilencesOK) WithPayload(payload *PostSilencesOKBody) *PostSilencesOK {
|
|
o.Payload = payload
|
|
return o
|
|
}
|
|
|
|
// SetPayload sets the payload to the post silences o k response
|
|
func (o *PostSilencesOK) SetPayload(payload *PostSilencesOKBody) {
|
|
o.Payload = payload
|
|
}
|
|
|
|
// WriteResponse to the client
|
|
func (o *PostSilencesOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
|
|
|
rw.WriteHeader(200)
|
|
if o.Payload != nil {
|
|
payload := o.Payload
|
|
if err := producer.Produce(rw, payload); err != nil {
|
|
panic(err) // let the recovery middleware deal with this
|
|
}
|
|
}
|
|
}
|
|
|
|
// PostSilencesBadRequestCode is the HTTP code returned for type PostSilencesBadRequest
|
|
const PostSilencesBadRequestCode int = 400
|
|
|
|
/*PostSilencesBadRequest Bad request
|
|
|
|
swagger:response postSilencesBadRequest
|
|
*/
|
|
type PostSilencesBadRequest struct {
|
|
|
|
/*
|
|
In: Body
|
|
*/
|
|
Payload string `json:"body,omitempty"`
|
|
}
|
|
|
|
// NewPostSilencesBadRequest creates PostSilencesBadRequest with default headers values
|
|
func NewPostSilencesBadRequest() *PostSilencesBadRequest {
|
|
|
|
return &PostSilencesBadRequest{}
|
|
}
|
|
|
|
// WithPayload adds the payload to the post silences bad request response
|
|
func (o *PostSilencesBadRequest) WithPayload(payload string) *PostSilencesBadRequest {
|
|
o.Payload = payload
|
|
return o
|
|
}
|
|
|
|
// SetPayload sets the payload to the post silences bad request response
|
|
func (o *PostSilencesBadRequest) SetPayload(payload string) {
|
|
o.Payload = payload
|
|
}
|
|
|
|
// WriteResponse to the client
|
|
func (o *PostSilencesBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
|
|
|
rw.WriteHeader(400)
|
|
payload := o.Payload
|
|
if err := producer.Produce(rw, payload); err != nil {
|
|
panic(err) // let the recovery middleware deal with this
|
|
}
|
|
|
|
}
|