Skip to content

Commit

Permalink
Deprecate and remove api/v1/ (#2970)
Browse files Browse the repository at this point in the history
* Deprecate and remove api/v1/

Signed-off-by: gotjosh <josue.abreu@gmail.com>
---------

Signed-off-by: gotjosh <josue.abreu@gmail.com>
  • Loading branch information
gotjosh committed Nov 24, 2023
1 parent 4f0bdf4 commit b4f7027
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 3,908 deletions.
24 changes: 7 additions & 17 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"

apiv1 "github.com/prometheus/alertmanager/api/v1"
apiv2 "github.com/prometheus/alertmanager/api/v2"
"github.com/prometheus/alertmanager/cluster"
"github.com/prometheus/alertmanager/config"
Expand All @@ -37,8 +36,9 @@ import (

// API represents all APIs of Alertmanager.
type API struct {
v1 *apiv1.API
v2 *apiv2.API
v2 *apiv2.API
deprecationRouter *V1DeprecationRouter

requestsInFlight prometheus.Gauge
concurrencyLimitExceeded prometheus.Counter
timeout time.Duration
Expand Down Expand Up @@ -110,15 +110,6 @@ func New(opts Options) (*API, error) {
}
}

v1 := apiv1.New(
opts.Alerts,
opts.Silences,
opts.StatusFunc,
opts.Peer,
log.With(l, "version", "v1"),
opts.Registry,
)

v2, err := apiv2.NewAPI(
opts.Alerts,
opts.GroupFunc,
Expand Down Expand Up @@ -154,7 +145,7 @@ func New(opts Options) (*API, error) {
}

return &API{
v1: v1,
deprecationRouter: NewV1DeprecationRouter(log.With(l, "version", "v1")),
v2: v2,
requestsInFlight: requestsInFlight,
concurrencyLimitExceeded: concurrencyLimitExceeded,
Expand All @@ -163,16 +154,16 @@ func New(opts Options) (*API, error) {
}, nil
}

// Register all APIs. It registers APIv1 with the provided router directly. As
// APIv2 works on the http.Handler level, this method also creates a new
// Register API. As APIv2 works on the http.Handler level, this method also creates a new
// http.ServeMux and then uses it to register both the provided router (to
// handle "/") and APIv2 (to handle "<routePrefix>/api/v2"). The method returns
// the newly created http.ServeMux. If a timeout has been set on construction of
// API, it is enforced for all HTTP request going through this mux. The same is
// true for the concurrency limit, with the exception that it is only applied to
// GET requests.
func (api *API) Register(r *route.Router, routePrefix string) *http.ServeMux {
api.v1.Register(r.WithPrefix("/api/v1"))
// TODO(gotjosh) API V1 was removed as of version 0.28, when we reach 1.0.0 we should removed these deprecation warnings.
api.deprecationRouter.Register(r.WithPrefix("/api/v1"))

mux := http.NewServeMux()
mux.Handle("/", api.limitHandler(r))
Expand All @@ -196,7 +187,6 @@ 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, setAlertStatus func(model.LabelSet)) {
api.v1.Update(cfg)
api.v2.Update(cfg, setAlertStatus)
}

Expand Down
9 changes: 5 additions & 4 deletions api/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ package metrics

import "github.com/prometheus/client_golang/prometheus"

// Alerts stores metrics for alerts which are common across all API versions.
// Alerts stores metrics for alerts.
type Alerts struct {
firing prometheus.Counter
resolved prometheus.Counter
invalid prometheus.Counter
}

// NewAlerts returns an *Alerts struct for the given API version.
func NewAlerts(version string, r prometheus.Registerer) *Alerts {
// Since v1 was deprecated in 0.28, v2 is now hardcoded.
func NewAlerts(r prometheus.Registerer) *Alerts {
numReceivedAlerts := prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "alertmanager_alerts_received_total",
Help: "The total number of received alerts.",
ConstLabels: prometheus.Labels{"version": version},
ConstLabels: prometheus.Labels{"version": "v2"},
}, []string{"status"})
numInvalidAlerts := prometheus.NewCounter(prometheus.CounterOpts{
Name: "alertmanager_alerts_invalid_total",
Help: "The total number of received alerts that were invalid.",
ConstLabels: prometheus.Labels{"version": version},
ConstLabels: prometheus.Labels{"version": "v2"},
})
if r != nil {
r.MustRegister(numReceivedAlerts, numInvalidAlerts)
Expand Down
Loading

0 comments on commit b4f7027

Please sign in to comment.