Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate and remove api/v1/ #2970

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading