mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
Allow passing query args to HTTP requests send to the Alertmanager API
Alertmanager 0.4.x silences endpoint uses pagination, code for this was incorrectly dropped in #216, re-add it. Requires a way for mapper packages to signal the need for passing query args to HTTP requests
This commit is contained in:
@@ -115,6 +115,11 @@ func (am *Alertmanager) pullSilences(version string) error {
|
||||
log.Errorf("[%s] Failed to generate silences endpoint URL: %s", am.Name, err)
|
||||
return err
|
||||
}
|
||||
// append query args if mapper needs those
|
||||
queryArgs := mapper.QueryArgs()
|
||||
if queryArgs != "" {
|
||||
url = fmt.Sprintf("%s?%s", url, queryArgs)
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
// read raw body from the source
|
||||
@@ -175,6 +180,12 @@ func (am *Alertmanager) pullAlerts(version string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// append query args if mapper needs those
|
||||
queryArgs := mapper.QueryArgs()
|
||||
if queryArgs != "" {
|
||||
url = fmt.Sprintf("%s?%s", url, queryArgs)
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
// read raw body from the source
|
||||
source, err := am.reader.Read(url)
|
||||
|
||||
@@ -16,6 +16,7 @@ var (
|
||||
type Mapper interface {
|
||||
IsSupported(version string) bool
|
||||
AbsoluteURL(baseURI string) (string, error)
|
||||
QueryArgs() string
|
||||
}
|
||||
|
||||
// AlertMapper handles mapping of Alertmanager alert information to unsee AlertGroup models
|
||||
|
||||
@@ -59,6 +59,11 @@ func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) {
|
||||
return uri.JoinURL(baseURI, "api/v1/alerts/groups")
|
||||
}
|
||||
|
||||
// QueryArgs for HTTP requests send to the Alertmanager API endpoint
|
||||
func (m AlertMapper) QueryArgs() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsSupported returns true if given version string is supported
|
||||
func (m AlertMapper) IsSupported(version string) bool {
|
||||
versionRange := semver.MustParseRange(">=0.4.0 <0.5.0")
|
||||
|
||||
@@ -7,7 +7,9 @@ package v04
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -52,6 +54,13 @@ func (m SilenceMapper) AbsoluteURL(baseURI string) (string, error) {
|
||||
return uri.JoinURL(baseURI, "api/v1/silences")
|
||||
}
|
||||
|
||||
// QueryArgs for HTTP requests send to the Alertmanager API endpoint
|
||||
func (m SilenceMapper) QueryArgs() string {
|
||||
// Alertmanager 0.4 uses pagination for silences, pass a huge value so that
|
||||
// we get all possible silences
|
||||
return fmt.Sprintf("api/v1/silences?limit=%d", math.MaxInt32)
|
||||
}
|
||||
|
||||
// IsSupported returns true if given version string is supported
|
||||
func (m SilenceMapper) IsSupported(version string) bool {
|
||||
versionRange := semver.MustParseRange(">=0.4.0 <0.5.0")
|
||||
|
||||
@@ -58,6 +58,11 @@ func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) {
|
||||
return uri.JoinURL(baseURI, "api/v1/alerts/groups")
|
||||
}
|
||||
|
||||
// QueryArgs for HTTP requests send to the Alertmanager API endpoint
|
||||
func (m AlertMapper) QueryArgs() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsSupported returns true if given version string is supported
|
||||
func (m AlertMapper) IsSupported(version string) bool {
|
||||
versionRange := semver.MustParseRange(">=0.5.0 <=0.6.0")
|
||||
|
||||
@@ -46,6 +46,11 @@ func (m SilenceMapper) AbsoluteURL(baseURI string) (string, error) {
|
||||
return uri.JoinURL(baseURI, "api/v1/silences")
|
||||
}
|
||||
|
||||
// QueryArgs for HTTP requests send to the Alertmanager API endpoint
|
||||
func (m SilenceMapper) QueryArgs() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsSupported returns true if given version string is supported
|
||||
func (m SilenceMapper) IsSupported(version string) bool {
|
||||
versionRange := semver.MustParseRange(">=0.5.0")
|
||||
|
||||
@@ -60,6 +60,11 @@ func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) {
|
||||
return uri.JoinURL(baseURI, "api/v1/alerts/groups")
|
||||
}
|
||||
|
||||
// QueryArgs for HTTP requests send to the Alertmanager API endpoint
|
||||
func (m AlertMapper) QueryArgs() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsSupported returns true if given version string is supported
|
||||
func (m AlertMapper) IsSupported(version string) bool {
|
||||
versionRange := semver.MustParseRange("=0.6.1")
|
||||
|
||||
@@ -64,6 +64,11 @@ func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) {
|
||||
return uri.JoinURL(baseURI, "api/v1/alerts/groups")
|
||||
}
|
||||
|
||||
// QueryArgs for HTTP requests send to the Alertmanager API endpoint
|
||||
func (m AlertMapper) QueryArgs() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// IsSupported returns true if given version string is supported
|
||||
func (m AlertMapper) IsSupported(version string) bool {
|
||||
versionRange := semver.MustParseRange(">=0.6.2")
|
||||
|
||||
Reference in New Issue
Block a user