Skip to content

Commit

Permalink
more changes to the API v1 removal
Browse files Browse the repository at this point in the history
Signed-off-by: gotjosh <[email protected]>
  • Loading branch information
gotjosh committed Nov 21, 2023
1 parent a0d920f commit 119e1c4
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1,025 deletions.
10 changes: 8 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import (

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

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

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

// Register all APIs. 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 {
// 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 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 119e1c4

Please sign in to comment.